-
Notifications
You must be signed in to change notification settings - Fork 31
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
Do not end paragraph before :::
in fenced divs
#428
Conversation
As discussed in <#403 (comment)>.
I pressed on using the original approach of @Omikhleia, which relied on buffering the contents of a fenced div before parsing them. However, I realized that buffering the body of a fenced div would have so many different corner cases just to properly handle nested fenced divs and fenced code blocks that this approach is not worth the effort. I stashed my changes here. Instead, I mapped out the viable approach that we should implement. Our issue is with the handling of trailing div fences when the Lines 30960 to 30981 in 415379f
Namely, the pattern ::: {#some-identifier}
This is the beginning of a div
> This is a blockquote that contains three colons:
> :::
This is the end of a div
::: Here, the line In #427, @lostenderman followed my suggestion and tried to fix the issue by tracking whether we are on the top level of a fenced div or nested in a block-level element using a named capture group However, this approach does not work well with nested fenced divs, which would require that the named capture group is a stack rather than a scalar, so that we can know whether we are still at the top level of a parent fenced div when we have emerged from a nested fenced div. More crucially, this approach does not fix the issue for trailing lines of blockquotes and other elements such as list items, which should be able to close a div but are technically still nested in a block-level element: ::: {#some-identifier}
> This is a blockquote followed by the end of a div:
::: Therefore, we need a different approach. A more relaxed condition for the closing div fence is that it has the same indent level as the opening div fence. Currently, we use the function |
if fenced_div_indent_table.indents ~= nil then | ||
num_opening_indents = #fenced_div_indent_table.indents | ||
end | ||
return num_current_indents == num_opening_indents |
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.
@lostenderman This feels like the conceptually correct approach. However, num_current_indents
is currently still wrong for e.g. lazy continuation lines:
::: {#an-identifier}
> a
::: <!-- Here, `num_current_indents` is still 1 but `num_opening_indents` is 0. -->
This is also corroborated by the CI, which fails on the single test case in fenced-divs.test
that involves what-would-be lazy continuation lines if the fenced div syntax extension were disabled:
markdown/tests/testfiles/lunamark-markdown/fenced-divs.test
Lines 89 to 92 in 415379f
::: {#another-identifier} | |
> This is a blockquote immediately in a | |
> div | |
::: |
I will appreciate your advice on refining the current approach. In the Endline
pattern, we call the parsers.check_minimal_indent
and parsers.check_optional_indent
patterns before the EnclineExceptions
pattern and these update indent_table.trail
with information about the current line. Perhaps we could use indent_table.trail
to better determine num_current_indents
? I am still not comfortable around the indent-info / trail-info objects and how to interpret their properties and will appreciate a nudge in the right direction (or a commit).
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.
@lostenderman If you are busy, I will likely figure it out eventually at this point. However, you would likely be much more efficient at this, since the indent-info / trail-info objects are your code. I will appreciate your insight.
% \end{markdown} | ||
% \begin{macrocode} | ||
self.initialize_named_group("div_level", "0") | ||
% Initialize a named group named `fenced_div_level` for tracking how deep |
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.
% Initialize a named group named `fenced_div_level` for tracking how deep | |
% Initialize a named group `fenced_div_level` for tracking how deep |
4cf1e86
to
bd7ac0a
Compare
Closes #407.
Tasks
:::
in fenced divs #427 and the fenced div parser using the approach of @Omikhleia:CHANGES.md
.