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
18 changes: 15 additions & 3 deletions src/parser/inlines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub struct Subject<'a: 'd, 'r, 'o, 'd, 'i, 'c: 'subj, 'subj> {
delimiter_arena: &'d Arena<Delimiter<'a, 'd>>,
last_delimiter: Option<&'d Delimiter<'a, 'd>>,
brackets: Vec<Bracket<'a, 'd>>,
within_brackets: bool,
pub backticks: [usize; MAXBACKTICKS + 1],
pub scanned_for_backticks: bool,
special_chars: [bool; 256],
Expand Down Expand Up @@ -74,6 +75,7 @@ impl<'a, 'r, 'o, 'd, 'i, 'c, 'subj> Subject<'a, 'r, 'o, 'd, 'i, 'c, 'subj> {
delimiter_arena,
last_delimiter: None,
brackets: vec![],
within_brackets: false,
backticks: [0; MAXBACKTICKS + 1],
scanned_for_backticks: false,
special_chars: [false; 256],
Expand Down Expand Up @@ -128,9 +130,13 @@ impl<'a, 'r, 'o, 'd, 'i, 'c, 'subj> Subject<'a, 'r, 'o, 'd, 'i, 'c, 'subj> {
self.pos += 1;
let inl = make_inline(self.arena, NodeValue::Text(b"[".to_vec()));
self.push_bracket(false, inl);
self.within_brackets = true;
Some(inl)
}
']' => self.handle_close_bracket(),
']' => {
self.within_brackets = false;
self.handle_close_bracket()
}
'!' => {
self.pos += 1;
if self.peek_char() == Some(&(b'[')) && self.peek_char_n(1) != Some(&(b'^')) {
Expand All @@ -143,7 +149,9 @@ impl<'a, 'r, 'o, 'd, 'i, 'c, 'subj> Subject<'a, 'r, 'o, 'd, 'i, 'c, 'subj> {
}
}
'~' if self.options.extension.strikethrough => Some(self.handle_delim(b'~')),
'^' if self.options.extension.superscript => Some(self.handle_delim(b'^')),
'^' if self.options.extension.superscript && !self.within_brackets => {
Some(self.handle_delim(b'^'))
}
_ => {
let endpos = self.find_special_char();
let mut contents = self.input[self.pos..endpos].to_vec();
Expand Down Expand Up @@ -452,7 +460,11 @@ impl<'a, 'r, 'o, 'd, 'i, 'c, 'subj> Subject<'a, 'r, 'o, 'd, 'i, 'c, 'subj> {
pub fn find_special_char(&self) -> usize {
for n in self.pos..self.input.len() {
if self.special_chars[self.input[n] as usize] {
return n;
if self.input[n] == b'^' && self.within_brackets {
// NO OP
} else {
return n;
}
}
if self.options.parse.smart && self.smart_chars[self.input[n] as usize] {
return n;
Expand Down
36 changes: 36 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,42 @@ fn footnote_in_table() {
));
}

#[test]
fn footnote_with_superscript() {
html_opts!(
[extension.superscript, extension.footnotes],
concat!(
"Here is a footnote reference.[^1]\n",
"\n",
"Here is a longer footnote reference.[^ref]\n",
"\n",
"e = mc^2^.\n",
"\n",
"[^1]: Here is the footnote.\n",
"[^ref]: Here is another footnote.\n",
),
concat!(
"<p>Here is a footnote reference.<sup class=\"footnote-ref\"><a href=\"#fn1\" \
id=\"fnref1\">1</a></sup></p>\n",
"<p>Here is a longer footnote reference.<sup class=\"footnote-ref\"><a href=\"#fn2\" \
id=\"fnref2\">2</a></sup></p>\n",
"<p>e = mc<sup>2</sup>.</p>\n",
"<section class=\"footnotes\">\n",
"<ol>\n",
"<li id=\"fn1\">\n",
"<p>Here is the footnote. <a href=\"#fnref1\" \
class=\"footnote-backref\">↩</a></p>\n",
"</li>\n",
"<li id=\"fn2\">\n",
"<p>Here is another footnote. <a href=\"#fnref2\" \
class=\"footnote-backref\">↩</a></p>\n",
"</li>\n",
"</ol>\n",
"</section>\n"
),
);
}

#[test]
fn regression_back_to_back_ranges() {
html(
Expand Down