Skip to content

Commit ca01215

Browse files
committed
cont'd.
1 parent 7ff9cc9 commit ca01215

File tree

1 file changed

+64
-47
lines changed

1 file changed

+64
-47
lines changed

src/parser/mod.rs

Lines changed: 64 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,8 @@ pub mod alert;
88
pub mod math;
99
pub mod multiline_block_quote;
1010

11-
use crate::adapters::SyntaxHighlighterAdapter;
12-
use crate::arena_tree::Node;
13-
use crate::ctype::{isdigit, isspace};
14-
use crate::entity;
15-
use crate::nodes::{self, NodeFootnoteDefinition, Sourcepos};
16-
use crate::nodes::{
17-
Ast, AstNode, ListDelimType, ListType, NodeCodeBlock, NodeDescriptionItem, NodeHeading,
18-
NodeHtmlBlock, NodeList, NodeValue,
19-
};
20-
use crate::scanners::{self, SetextChar};
21-
use crate::strings::{self, split_off_front_matter, Case};
11+
#[cfg(feature = "bon")]
12+
use bon::Builder;
2213
use std::cell::RefCell;
2314
use std::cmp::{min, Ordering};
2415
use std::collections::{HashMap, VecDeque};
@@ -29,14 +20,19 @@ use std::str;
2920
use std::sync::Arc;
3021
use typed_arena::Arena;
3122

32-
use crate::adapters::HeadingAdapter;
23+
use crate::adapters::{HeadingAdapter, SyntaxHighlighterAdapter};
24+
use crate::arena_tree::Node;
25+
use crate::ctype::{isdigit, isspace};
26+
use crate::entity;
27+
use crate::nodes::{
28+
self, Ast, AstNode, ListDelimType, ListType, NodeCodeBlock, NodeDescriptionItem,
29+
NodeFootnoteDefinition, NodeHeading, NodeHtmlBlock, NodeList, NodeValue, Sourcepos,
30+
};
3331
use crate::parser::alert::{AlertType, NodeAlert};
32+
use crate::parser::inlines::RefMap;
3433
use crate::parser::multiline_block_quote::NodeMultilineBlockQuote;
35-
36-
#[cfg(feature = "bon")]
37-
use bon::Builder;
38-
39-
use self::inlines::RefMap;
34+
use crate::scanners::{self, SetextChar};
35+
use crate::strings::{self, split_off_front_matter, Case};
4036

4137
const TAB_STOP: usize = 4;
4238
const CODE_INDENT: usize = 4;
@@ -2972,36 +2968,18 @@ where
29722968
let mut child_in_bracket_context = in_bracket_context;
29732969
let mut emptied = false;
29742970
let n_ast = &mut n.data.borrow_mut();
2975-
let mut sourcepos = n_ast.sourcepos;
29762971

2972+
let sourcepos = n_ast.sourcepos;
29772973
match n_ast.value {
29782974
NodeValue::Text(ref mut root) => {
2979-
// Join adjacent text nodes together, then post-process.
2980-
// Record the original list of sourcepos and bytecounts
2981-
// for the post-processing step.
2982-
let mut spxv = VecDeque::new();
2983-
spxv.push_back((sourcepos, root.len()));
2984-
while let Some(ns) = n.next_sibling() {
2985-
match ns.data.borrow().value {
2986-
NodeValue::Text(ref adj) => {
2987-
root.push_str(adj);
2988-
let sp = ns.data.borrow().sourcepos;
2989-
spxv.push_back((sp, adj.len()));
2990-
sourcepos.end.column = sp.end.column;
2991-
ns.detach();
2992-
}
2993-
_ => break,
2994-
}
2995-
}
2996-
2997-
self.postprocess_text_node_with_context(
2975+
let sourcepos = self.postprocess_text_node_with_context(
29982976
n,
2977+
sourcepos,
29992978
root,
3000-
&mut sourcepos,
3001-
spxv,
30022979
in_bracket_context,
30032980
);
30042981
emptied = root.is_empty();
2982+
n_ast.sourcepos = sourcepos;
30052983
}
30062984
NodeValue::Link(..) | NodeValue::Image(..) | NodeValue::WikiLink(..) => {
30072985
// Recurse into links, images, and wikilinks to join adjacent text nodes,
@@ -3011,8 +2989,6 @@ where
30112989
_ => {}
30122990
}
30132991

3014-
n_ast.sourcepos = sourcepos;
3015-
30162992
if !emptied {
30172993
children.push((n, child_in_bracket_context));
30182994
}
@@ -3031,6 +3007,43 @@ where
30313007
}
30323008

30333009
fn postprocess_text_node_with_context(
3010+
&mut self,
3011+
node: &'a AstNode<'a>,
3012+
mut sourcepos: Sourcepos,
3013+
root: &mut String,
3014+
in_bracket_context: bool,
3015+
) -> Sourcepos {
3016+
// Join adjacent text nodes together, then post-process.
3017+
// Record the original list of sourcepos and bytecounts
3018+
// for the post-processing step.
3019+
3020+
let mut spxv = VecDeque::new();
3021+
spxv.push_back((sourcepos, root.len()));
3022+
while let Some(ns) = node.next_sibling() {
3023+
match ns.data.borrow().value {
3024+
NodeValue::Text(ref adj) => {
3025+
root.push_str(adj);
3026+
let sp = ns.data.borrow().sourcepos;
3027+
spxv.push_back((sp, adj.len()));
3028+
sourcepos.end.column = sp.end.column;
3029+
ns.detach();
3030+
}
3031+
_ => break,
3032+
}
3033+
}
3034+
3035+
self.postprocess_text_node_with_context_inner(
3036+
node,
3037+
root,
3038+
&mut sourcepos,
3039+
spxv,
3040+
in_bracket_context,
3041+
);
3042+
3043+
sourcepos
3044+
}
3045+
3046+
fn postprocess_text_node_with_context_inner(
30343047
&mut self,
30353048
node: &'a AstNode<'a>,
30363049
text: &mut String,
@@ -3154,15 +3167,19 @@ where
31543167
fn parse_reference_inline(&mut self, content: &[u8]) -> Option<usize> {
31553168
// In this case reference inlines rarely have delimiters
31563169
// so we often just need the minimal case
3157-
let delimiter_arena = Arena::with_capacity(0);
3170+
let unused_node_arena = Arena::new();
3171+
let unused_footnote_defs = inlines::FootnoteDefs::new();
3172+
let unused_delimiter_arena = Arena::with_capacity(0);
3173+
let mut unused_refmap = inlines::RefMap::new();
3174+
31583175
let mut subj = inlines::Subject::new(
3159-
self.arena,
3176+
&unused_node_arena,
31603177
self.options,
31613178
content,
31623179
0, // XXX -1 in upstream; never used?
3163-
&mut self.refmap,
3164-
&self.footnote_defs,
3165-
&delimiter_arena,
3180+
&mut unused_refmap,
3181+
&unused_footnote_defs,
3182+
&unused_delimiter_arena,
31663183
);
31673184

31683185
let mut lab: String = match subj.link_label() {
@@ -3216,7 +3233,7 @@ where
32163233

32173234
lab = strings::normalize_label(&lab, Case::Fold);
32183235
if !lab.is_empty() {
3219-
subj.refmap.map.entry(lab).or_insert(ResolvedReference {
3236+
self.refmap.map.entry(lab).or_insert(ResolvedReference {
32203237
url: String::from_utf8(strings::clean_url(url)).unwrap(),
32213238
title: String::from_utf8(strings::clean_title(&title)).unwrap(),
32223239
});

0 commit comments

Comments
 (0)