Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions fuzz/fuzz_targets/all_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ struct FuzzExtensionOptions {
subscript: bool,
subtext: bool,
cjk_friendly_emphasis: bool,
highlight: bool,
// non-bool below
header_ids: bool,
front_matter_delimiter: bool,
image_url_rewriter: bool,
Expand Down Expand Up @@ -88,6 +90,8 @@ impl FuzzExtensionOptions {
subscript: self.subscript,
subtext: self.subtext,
cjk_friendly_emphasis: self.cjk_friendly_emphasis,
highlight: self.highlight,
// non-bool below
header_ids: if self.header_ids {
Some("user-content-".into())
} else {
Expand Down
7 changes: 7 additions & 0 deletions src/arena_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ impl<'a, T> Node<'a, T> {
self.last_child.set(Some(new_child));
}

/// Append multiple new children to this node, after existing children.
pub fn extend(&'a self, new_children: impl IntoIterator<Item = &'a Node<'a, T>>) {
for child in new_children.into_iter() {
self.append(child);
}
}

/// Prepend a new child to this node, before existing children.
pub fn prepend(&'a self, new_child: &'a Node<'a, T>) {
new_child.detach();
Expand Down
7 changes: 4 additions & 3 deletions src/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1622,9 +1622,10 @@ fn tagfilter(literal: &str) -> bool {
for t in TAGFILTER_BLACKLIST.iter() {
if lc.starts_with(t) {
let j = i + t.len();
return isspace(bytes[j])
|| bytes[j] == b'>'
|| (bytes[j] == b'/' && bytes.len() >= j + 2 && bytes[j + 1] == b'>');
let Some(&b) = bytes.get(j) else {
return false;
};
return isspace(b) || b == b'>' || (b == b'/' && bytes.get(j + 1) == Some(&b'>'));
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ pub enum NodeValue {
Image(Box<NodeLink>),

/// **Inline**. A footnote reference.
FootnoteReference(NodeFootnoteReference),
FootnoteReference(Box<NodeFootnoteReference>),

#[cfg(feature = "shortcodes")]
/// **Inline**. An Emoji character generated from a shortcode. Enable with feature "shortcodes".
Expand Down Expand Up @@ -459,6 +459,9 @@ pub struct NodeFootnoteReference {
/// The name of the footnote.
pub name: String,

/// The original text elements of the footnote, including their source position spans.
pub texts: Vec<(String, usize)>,

/// The index of reference to the same footnote
pub ref_num: u32,

Expand Down
34 changes: 28 additions & 6 deletions src/parser/inlines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,11 +994,12 @@ impl<'a, 'r, 'o, 'd, 'c, 'p> Subject<'a, 'r, 'o, 'd, 'c, 'p> {

// Create the footnote reference node
let ref_node = self.make_inline(
NodeValue::FootnoteReference(NodeFootnoteReference {
NodeValue::FootnoteReference(Box::new(NodeFootnoteReference {
name: name.clone(),
texts: vec![], // Unused.
ref_num: 0,
ix: 0,
}),
})),
startpos,
endpos,
);
Expand Down Expand Up @@ -1734,13 +1735,33 @@ impl<'a, 'r, 'o, 'd, 'c, 'p> Subject<'a, 'r, 'o, 'd, 'c, 'p> {
// do anything fancy here at all.
let mut sussy = false;

let mut texts = vec![];

for sibling in sibling_iterator {
match sibling.data().value {
let sibling_ast = sibling.data();
if sibling_ast.sourcepos.start.line != sibling_ast.sourcepos.end.line
|| sibling_ast.sourcepos.end.column < sibling_ast.sourcepos.start.column
{
sussy = true;
break;
}

match sibling_ast.value {
NodeValue::Text(ref literal) => {
text.push_str(literal);
texts.push((
literal.to_string(),
sibling_ast.sourcepos.end.column - sibling_ast.sourcepos.start.column
+ 1,
));
}
NodeValue::HtmlInline(ref literal) => {
text.push_str(literal);
texts.push((
literal.to_string(),
sibling_ast.sourcepos.end.column - sibling_ast.sourcepos.start.column
+ 1,
));
}
_ => {
sussy = true;
Expand All @@ -1751,11 +1772,12 @@ impl<'a, 'r, 'o, 'd, 'c, 'p> Subject<'a, 'r, 'o, 'd, 'c, 'p> {

if !sussy && text.len() > 1 {
let inl = self.make_inline(
NodeValue::FootnoteReference(NodeFootnoteReference {
NodeValue::FootnoteReference(Box::new(NodeFootnoteReference {
name: text[1..].to_string(),
texts,
ref_num: 0,
ix: 0,
}),
})),
// Overridden immediately below.
self.scanner.pos,
self.scanner.pos,
Expand Down Expand Up @@ -2341,7 +2363,7 @@ pub(crate) fn manual_scan_link_url_2(input: &str) -> Option<(&str, usize)> {
}
}

if i >= len || nb_p != 0 {
if len == 0 || nb_p != 0 {
None
} else {
Some((&input[..i], i))
Expand Down
Loading