Skip to content

Commit

Permalink
Fix sourcepos for ___ and ***
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalmoksha committed Aug 15, 2024
1 parent 32ccfca commit ba69381
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 8 deletions.
11 changes: 9 additions & 2 deletions src/parser/inlines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1123,11 +1123,18 @@ impl<'a, 'r, 'o, 'c, 'd, 'i> Subject<'a, 'r, 'o, 'c, 'd, 'i> {
self.pos,
);
{
// if we have `___` or `***` then we need to adjust the sourcepos colums by 1
let triple_adjustment = if opener_num_chars > 0 && use_delims == 2 {
1
} else {
0
};

emph.data.borrow_mut().sourcepos = (
opener.inl.data.borrow().sourcepos.start.line,
opener.inl.data.borrow().sourcepos.start.column,
opener.inl.data.borrow().sourcepos.start.column + triple_adjustment,
closer.inl.data.borrow().sourcepos.end.line,
closer.inl.data.borrow().sourcepos.end.column,
closer.inl.data.borrow().sourcepos.end.column - triple_adjustment,
)
.into();
}
Expand Down
45 changes: 39 additions & 6 deletions src/tests/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ fn link_sourcepos_truffle_bergamot() {
}

#[test]
fn link_sourcepos_inline_paragraph_multiline() {
fn paragraph_sourcepos_multiline() {
assert_ast_match!(
[],
" A\n"
Expand All @@ -615,7 +615,7 @@ fn link_sourcepos_inline_paragraph_multiline() {
}

#[test]
fn link_sourcepos_inline_listitem_multiline() {
fn listitem_sourcepos_multiline() {
assert_ast_match!(
[],
"- A\n"
Expand All @@ -635,7 +635,7 @@ fn link_sourcepos_inline_listitem_multiline() {
}

#[test]
fn link_sourcepos_inline_listitem_multiline_2() {
fn listitem_sourcepos_multiline_2() {
assert_ast_match!(
[],
"- A\n"
Expand Down Expand Up @@ -664,7 +664,7 @@ fn link_sourcepos_inline_listitem_multiline_2() {
}

#[test]
fn link_sourcepos_inline_double_emphasis_1() {
fn emphasis_sourcepos_double_1() {
assert_ast_match!(
[],
"_**this**_\n",
Expand All @@ -680,9 +680,25 @@ fn link_sourcepos_inline_double_emphasis_1() {
);
}

#[ignore]
#[test]
fn link_sourcepos_inline_double_emphasis_2() {
fn emphasis_sourcepos_double_2() {
assert_ast_match!(
[],
"**_this_**\n",
(document (1:1-1:10) [
(paragraph (1:1-1:10) [
(strong (1:1-1:10) [
(emph (1:3-1:8) [
(text (1:4-1:7) "this")
])
])
])
])
);
}

#[test]
fn emphasis_sourcepos_double_3() {
assert_ast_match!(
[],
"___this___\n",
Expand All @@ -697,3 +713,20 @@ fn link_sourcepos_inline_double_emphasis_2() {
])
);
}

#[test]
fn emphasis_sourcepos_double_4() {
assert_ast_match!(
[],
"***this***\n",
(document (1:1-1:10) [
(paragraph (1:1-1:10) [
(emph (1:1-1:10) [
(strong (1:2-1:9) [
(text (1:4-1:7) "this")
])
])
])
])
);
}
31 changes: 31 additions & 0 deletions src/tests/underline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,34 @@ fn underline() {
concat!("<p><u>underlined text</u></p>\n"),
);
}

#[test]
fn underline_sourcepos() {
assert_ast_match!(
[extension.underline],
"__this__\n",
(document (1:1-1:8) [
(paragraph (1:1-1:8) [
(underline (1:1-1:8) [
(text (1:3-1:6) "this")
])
])
])
);
}
#[test]
fn underline_sourcepos_emphasis() {
assert_ast_match!(
[extension.underline],
"___this___\n",
(document (1:1-1:10) [
(paragraph (1:1-1:10) [
(emph (1:1-1:10) [
(underline (1:2-1:9) [
(text (1:4-1:7) "this")
])
])
])
])
);
}

0 comments on commit ba69381

Please sign in to comment.