-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Markdown: Added support for nested bold and italic tokens #1897
Markdown: Added support for nested bold and italic tokens #1897
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- bold and italic share nearly identical regular expressions
- bold, italic, and strike share nearly the same content
- pandoc's markdown defines ::: as well, for classes
- pandoc's markdown supports { } after various elements, also for classes
- not immediately obvious why token.content[2] isn't used/defined (line 196)
- don't see any tests for ** bold with _ italic inside
- don't see any tests for __ bold with * italic inside
- is bold/italic/strike a possibility?
@DaveJarvis Thank you for taking the time to review this PR!
The new
I don't think we need to support a parser specific feature. If it's a commonly used feature, then sure we'll add it.
I added a comment explaining the structure of
Added.
Yes, you can nest bold, italic, and strike, or is there any issue with it? |
Available since Oct 2017 (jgm/pandoc#168), so it's gaining in usage and popularity.
I didn't see any specific unit tests that go through all the combinations, but maybe they aren't necessary. |
Because strike uses different delimiters than bold and italic, so it's generally less problematic. So I think that this should be sufficent testing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The unit test blocks are comprehensive, though a little unwieldy. Not sure if it would be worthwhile to write a recursive function to iterate over an array of inline elements. Something like:
generate_inline_test( [ '**', '__' ] )
generate_inline_test( [ '__', '**' ] )
generate_inline_test( [ '*', '__', '~~' ] )
If so, once the generate_inline_test
function is created, it would be possible to call it programmatically to generate all possible combinations and permutations based on a single array of inline elements (e.g., ['**', '__', '~~', '*', '_', ...]
).
Regarding the combinations: Yes we could write such a function but I don't think we have to. Looking at the regular expression, it's enough to test the nested tokens one level deep (It doesn't make sense the nest e.g. bold inside bold which makes things simpler) which gives us 6 * 4 combinations which are all covered by the bold, italic and strike tests in this PR. |
@DaveJarvis Again, thank you for reviewing! |
This PR adds support for nested bold and italic tokens.
This also resolves #1849.
Example
Before:

After:
