Handle bold/strong nested inside italics/em
While trying out this library, my initial input ran up against some edge cases. (It handled everything else perfectly though, which is awesome.). I decided to take a stab at fixing the bugs, which is this PR. I've broken down every test case addition + related fix into its own commit for easy review.
Here's the summary of changes in input/output:
| Input | Output in production | Output after this PR |
|---|---|---|
*italics **and bold** end* |
<p>*italics <strong>and bold</strong> end*</p> |
<p><em>italics <strong>and bold</strong> end</em></p> |
*italics **and bold*** |
<p>*italics <strong>and bold</strong>*</p> |
<p><em>italics <strong>and bold</strong></em></p> |
***bold** and italics* |
<p>*<strong>bold</strong> and italics*</p> |
<p><em><strong>bold</strong> and italics</em></p> |
*start **bold** and italics* |
<p>*start <strong>bold</strong> and italics*</p> |
<p><em>start <strong>bold</strong> and italics</em></p> |
*improper **nesting* is** bad |
<p>*improper <strong>nesting* is</strong> bad</p> |
<p><em>improper **nesting</em> is** bad</p> |
I don't see how the testcase makes the case for this PR?
Don't understand the random i +=2. Comments also didn't change even though the code around it changed very much
@miekg It does seem to fix the following:
In current code:
*italics **and bold** end*
=>
<p>*italics <strong>and bold</strong> end*</p>
See https://tools.arslexis.io/goplayground/#iPKnCL5art6
Per babelmark, most other return:
<p><em>italics <strong>and bold </strong> end</em></p>
see: https://babelmark.github.io/?text=italics+and+bold+end
The case *improper **nesting* is** bad gets closer to what majority does but not fully (see https://babelmark.github.io/?text=improper+nesting+is+bad)
I don't see how the testcase makes the case for this PR?
Don't understand the random
i +=2. Comments also didn't change even though the code around it changed very much
Apologies - I got lazy at the end of the work day and should have provided more context. I've updated the PR description and split the main commit into two (to better highlight what each change does) in hopes it better communicates the goals.
I also realized another edge case and added a test for that + fixed it. This reverted the optimization case I was talking about as the bug was there instead.
Lemme know if you need more information!
@miekg Just following up on this, as I think I addressed all your concerns. Let me know your thoughts and if you need me to do anything else!
Thanks, I pushed it in https://github.com/gomarkdown/markdown/commit/77f4768f716dcbd724917f1bade5f8c07e8a8cc1
Had to resolve a conflict and add a fix for infinite loop from #311 so couldn't just merge it