Markdown: Don't emit paragraph tags when a paragraph is "tight". (#5848)

* markdown: Don't emit paragraph tags when a paragraph is "tight".

Motivation: Since the upgrade to remarkable.js (#3876), lists are rendered as
HTML like this:

```
<ul>
  <li><p>One</p></li>
  <li><p>Two</p></li>
  <li><p>Three</p></li>
</ul>
```

The paragraph nodes insert blocks that break the visual flow of the list and are
unexpected e.g. compared to WikiText markup's rendering of a bulleted list.

Solution: remarkable.js annotates certain paragraph nodes as "tight", and in the
bulleted list case, the paragraph nodes wrapping the text of each list item are
marked tight.

remarkable uses the tight property to [elide paragraph tags in its
renderer](58b6945f20/lib/rules.js (L136-L142)).

This change implements the equivalent logic in TiddlyWiki's markdown rendering:
If a paragraph is marked tight, then we elide the `<p>` tag wrapping its children.

* Use ES5 Array.concat instead of ES6 spread operator.
This commit is contained in:
RJ Skerry-Ryan 2021-07-06 03:33:12 -07:00 committed by GitHub
parent a1d9464011
commit 8d9dc0cd29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -100,7 +100,14 @@ function convertNodes(remarkableTree, isStartOfInline) {
var currentNode = remarkableTree[i];
switch (currentNode.type) {
case "paragraph_open":
i = wrappedElement("p", i, currentNode.level, "paragraph_close", remarkableTree);
// If the paragraph is a "tight" layout paragraph, don't wrap children in a <p> tag.
if (currentNode.tight) {
i = withChildren(i, currentNode.level, "paragraph_close", remarkableTree, function(children) {
Array.prototype.push.apply(out, children);
});
} else {
i = wrappedElement("p", i, currentNode.level, "paragraph_close", remarkableTree);
}
break;
case "heading_open":