-
-
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_to_html different/incorrect behavior with leading line-break #3685
Comments
The filter has a behavior to remove the indentation: Twig/extra/markdown-extra/MarkdownRuntime.php Lines 25 to 28 in b4d6723
This seems to be what breaks when the markdown start with an empty line, because it will then remove the empty line between |
Well that doesn't seem like a good way of doing it. Not only for my issue of no indentation, but markdown can legitimately start with an indented code block, followed by non-indented paragraphs, etc. A workaround for now would be to do |
Maybe Twig could borrow the approach I implemented in my colinodell/indentation library? It basically:
Here are some test cases showing the results. I don't know if this approach is the most efficient but it seems fairly reliable. |
Maybe. I'm not sure such an intricate solution is required though.
There's a couple of differences here. I ignore empty lines, since many IDEs tend to remove whitespace on empty lines. I also treat tabs as 4 spaces, since this is how Markdown sees them.
Thanks, I added the early return.
Thanks. We could add some tests for the indentation detection, but I think the Markdown tests cover it. I added a comparison between the Twig output (after the indentation has been removed and the Markdown converted to HTML) and the direct Markdown output from the Markdown library in use. |
I thought I was going mad at one point. I've simplified the issue to the following code:
Output
I originally noticed it when I was getting the second (incorrect) results with this, which seems harmless enough.
Similar effects with other markdown libraries. Note that passing a leading line-break to the markdown library directly (without Twig) works as expected.
The text was updated successfully, but these errors were encountered: