Skip to content
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

Fix ToMarkdown missing newlines for label-lists #1094

Merged
merged 1 commit into from
Mar 8, 2024

Conversation

skipkayhil
Copy link
Contributor

Ref rails/rails#50759

Previously, using ToMarkdown on a label-list would generate output that could not be reparsed by the RDoc::Markdown parser:

md = <<~MD
apple
: a red fruit

banana
: a yellow fruit
MD

doc = RDoc::Markdown.parse(md)
doc # => [doc: [list: NOTE [item: ["apple"]; [para: "a red fruit"]], [item: ["banana"]; [para: "a yellow fruit"]]]]

new_md = doc.accept(RDoc::Markup::ToMarkdown.new)
new_md # => "apple\n:   a red fruit\nbanana\n:   a yellow fruit\n\n"

new_doc = RDoc::Markdown.parse(new_md)
new_doc # => [doc: [list: NOTE [item: ["apple"]; [para: "a red fruit\nbanana\n: a yellow fruit"]]]]

The issue is that the PHP Markdown Extra spec requires a newline after each definition list item, but ToMarkdown was not putting newlines between label-list items.

This commit fixes the issue by properly appending a newline after each label-list item so that the output of ToMarkdown can be reparsed by RDoc::Markdown:

md = <<~MD
apple
: a red fruit

banana
: a yellow fruit
MD

doc = RDoc::Markdown.parse(mdoc)
doc # => [doc: [list: NOTE [item: ["apple"]; [para: "a red fruit"]], [item: ["banana"]; [para: "a yellow fruit"]]]]

new_md = doc.accept(RDoc::Markup::ToMarkdown.new)
new_md # => "apple\n:   a red fruit\n\nbanana\n:   a yellow fruit\n\n"

new_doc = RDoc::Markdown.parse(new_md)
new_doc # => [doc: [list: NOTE [item: ["apple"]; [para: "a red fruit"]], [item: ["banana"]; [para: "a yellow fruit"]]]]

Previously, using ToMarkdown on a label-list would generate output that
could not be reparsed by the RDoc::Markdown parser:

```
md = <<~MD
apple
: a red fruit

banana
: a yellow fruit
MD

doc = RDoc::Markdown.parse(md)
doc # => [doc: [list: NOTE [item: ["apple"]; [para: "a red fruit"]], [item: ["banana"]; [para: "a yellow fruit"]]]]

new_md = doc.accept(RDoc::Markup::ToMarkdown.new)
new_md # => "apple\n:   a red fruit\nbanana\n:   a yellow fruit\n\n"

new_doc = RDoc::Markdown.parse(new_md)
new_doc # => [doc: [list: NOTE [item: ["apple"]; [para: "a red fruit\nbanana\n: a yellow fruit"]]]]
```

The issue is that the [PHP Markdown Extra spec][1] requires a newline
after each definition list item, but ToMarkdown was not putting newlines
between label-list items.

This commit fixes the issue by properly appending a newline after each
label-list item so that the output of ToMarkdown can be reparsed by
RDoc::Markdown:

```
md = <<~MD
apple
: a red fruit

banana
: a yellow fruit
MD

doc = RDoc::Markdown.parse(mdoc)
doc # => [doc: [list: NOTE [item: ["apple"]; [para: "a red fruit"]], [item: ["banana"]; [para: "a yellow fruit"]]]]

new_md = doc.accept(RDoc::Markup::ToMarkdown.new)
new_md # => "apple\n:   a red fruit\n\nbanana\n:   a yellow fruit\n\n"

new_doc = RDoc::Markdown.parse(new_md)
new_doc # => [doc: [list: NOTE [item: ["apple"]; [para: "a red fruit"]], [item: ["banana"]; [para: "a yellow fruit"]]]]
```

[1]: https://michelf.ca/projects/php-markdown/extra/#def-list
@nobu nobu merged commit 5b8dca6 into ruby:master Mar 8, 2024
24 checks passed
@skipkayhil skipkayhil deleted the hm-fix-md-label-list-newlines branch March 8, 2024 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants