From ba69381cd61df2ab089c6b87b7656d237133b58b Mon Sep 17 00:00:00 2001 From: digitalMoksha Date: Thu, 15 Aug 2024 17:25:11 -0500 Subject: [PATCH] Fix sourcepos for ___ and *** --- src/parser/inlines.rs | 11 +++++++++-- src/tests/core.rs | 45 ++++++++++++++++++++++++++++++++++++------ src/tests/underline.rs | 31 +++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 8 deletions(-) diff --git a/src/parser/inlines.rs b/src/parser/inlines.rs index 4e59baa0..067af763 100644 --- a/src/parser/inlines.rs +++ b/src/parser/inlines.rs @@ -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(); } diff --git a/src/tests/core.rs b/src/tests/core.rs index f6a3eb51..848426c0 100644 --- a/src/tests/core.rs +++ b/src/tests/core.rs @@ -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" @@ -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" @@ -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" @@ -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", @@ -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", @@ -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") + ]) + ]) + ]) + ]) + ); +} diff --git a/src/tests/underline.rs b/src/tests/underline.rs index 8efa9a9f..444cb36c 100644 --- a/src/tests/underline.rs +++ b/src/tests/underline.rs @@ -8,3 +8,34 @@ fn underline() { concat!("

underlined text

\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") + ]) + ]) + ]) + ]) + ); +}