Enable break_on_newline extension by default for Markdown#1628
Enable break_on_newline extension by default for Markdown#1628
Conversation
|
🚀 Preview deployment available at: https://3d655dba.rdoc-6cd.pages.dev (commit: d62b032) |
Enable the existing break_on_newline extension in DEFAULT_EXTENSIONS so the Markdown parser converts soft line breaks to HardBreak objects. This produces visible <br> line breaks in HTML output, matching GFM rendering. The conversion happens in the Markdown parser's paragraph() method, which is the proper place for Markdown-specific behavior. The generic accept_paragraph in ToHtml is unchanged and has no Markdown-specific logic. Also remove the CJK-aware newline-to-space gsub from accept_paragraph that is no longer needed. The RDoc markup parser already handles newline joining at parse time in build_paragraph.
2482465 to
d62b032
Compare
| @to.start_accepting | ||
| @to.accept_paragraph para("+hello+\n", "+world+\n") | ||
| assert_equal "\n<p><code>hello</code> <code>world</code></p>\n", @to.res.join | ||
| assert_equal "\n<p><code>hello</code>\nworld\n</p>\n", @to.res.join |
There was a problem hiding this comment.
Is this intentional?
Should world be surrounded with <code>?
| assert_equal "\n<p><code>hello</code>\nworld\n</p>\n", @to.res.join | |
| assert_equal "\n<p><code>hello</code>\n<code>world</code>\n</p>\n", @to.res.join |
There was a problem hiding this comment.
Pull request overview
Enables Markdown’s existing break_on_newline extension by default so soft line breaks inside paragraphs are parsed into RDoc::Markup::HardBreak nodes (rendering as <br> in HTML), and removes newline-joining logic from RDoc::Markup::ToHtml#accept_paragraph that is no longer relied on.
Changes:
- Enable
:break_on_newlineinRDoc::Markdown::DEFAULT_EXTENSIONS(and the kpeg source) so newline handling happens at parse time. - Simplify
RDoc::Markup::ToHtml#accept_paragraphby removing the newline-to-space (CJK-aware) substitution. - Update/expand tests and update the Markdown reference documentation to reflect the new behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
lib/rdoc/markdown.rb |
Enables :break_on_newline by default in the Ruby implementation of the Markdown parser. |
lib/rdoc/markdown.kpeg |
Mirrors the default extension enablement in the kpeg source. |
lib/rdoc/markup/to_html.rb |
Removes paragraph newline-joining/substitution logic so <br>\n output is preserved and paragraph text is emitted more directly. |
test/rdoc/rdoc_markdown_test.rb |
Updates expectations to include hard_break nodes and adds an HTML assertion for blockquote continuation. |
test/rdoc/rdoc_markdown_test_test.rb |
Mass-updates expected parsed ASTs to include hard_break where newlines previously remained in paragraph text. |
test/rdoc/parser/changelog_test.rb |
Updates expectations for newline behavior in parsed changelog Markdown fragments. |
test/rdoc/markup/to_html_test.rb |
Adjusts HTML expectations for hard breaks and paragraph newlines after removing the gsub behavior. |
doc/markup_reference/markdown.md |
Updates the GFM comparison notes to reflect preserved line breaks as <br>. |
Comments suppressed due to low confidence (2)
lib/rdoc/markdown.rb:596
DEFAULT_EXTENSIONSnow includes:break_on_newline, but the file-level extension docs earlier in this file still say the extension is "disabled by default". Please update the documentation to match the new default (and clarify whether users should disable it explicitly to preserve the previous soft-break behavior).
# Extensions enabled by default
DEFAULT_EXTENSIONS = [
:break_on_newline,
:definition_lists,
:github,
:html,
:notes,
:strike,
]
lib/rdoc/markdown.kpeg:211
DEFAULT_EXTENSIONSenables:break_on_newlinehere, but the generated source/docs for the Markdown parser still describe this extension as disabled by default. Please keep the extension documentation in sync with the new default (this file andlib/rdoc/markdown.rbshould agree).
# Extensions enabled by default
DEFAULT_EXTENSIONS = [
:break_on_newline,
:definition_lists,
:github,
:html,
:notes,
:strike,
]
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def accept_paragraph(paragraph) | ||
| @res << "\n<p>" | ||
| text = paragraph.text @hard_break | ||
| text = text.gsub(/(#{SPACE_SEPARATED_LETTER_CLASS})?\K\r?\n(?=(?(1)(#{SPACE_SEPARATED_LETTER_CLASS})?))/o) { | ||
| defined?($2) && ' ' | ||
| } | ||
| @res << to_html(text) | ||
| @res << "</p>\n" |
There was a problem hiding this comment.
PR description says there are "no changes to the generic accept_paragraph in ToHtml", but this method was changed (newline-to-space gsub removed). Please update the PR description (or add rationale in-code) so reviewers/users understand this behavior change affects ToHtml output beyond Markdown parsing.
| | Link titles | ✅ | ⚠️ | Parsed but not rendered | | ||
| | Images | ✅ | ✅ | Full match | | ||
| | Autolinks `<url>` | ✅ | ✅ | Full match | | ||
| | Soft line breaks | ✅ | ⚠️ | Newlines within paragraphs produce `<br>`; GFM spec renders as a space | | ||
| | Hard line breaks | ✅ | ⚠️ | 2+ trailing spaces only; backslash `\` at EOL not supported | | ||
| | Backslash escapes | ✅ | ⚠️ | Subset of GFM's escapable characters (e.g., `~` not escapable) | |
There was a problem hiding this comment.
The PR description claims this change matches GFM rendering for soft line breaks, but this table row states the opposite (GFM renders soft breaks as a space). Please reconcile the PR description with the documented behavior here to avoid confusion about whether this is intended divergence from GFM.
Summary
break_on_newlineextension inDEFAULT_EXTENSIONSso the Markdown parser converts soft line breaks toHardBreakobjects at parse time<br>line breaks in HTML output, matching GFM rendering where> Foo\nbarshows "Foo" and "bar" on separate linesparagraph()method, which is the proper place for Markdown-specific behavior — no changes to the genericaccept_paragraphinToHtmlaccept_paragraphthat is no longer needed (the RDoc markup parser already handles newline joining at parse time inbuild_paragraph)Ref: #1550 (comment)