-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes GH-83.
- Loading branch information
Showing
7 changed files
with
48 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* @import {Nodes} from 'mdast' | ||
*/ | ||
|
||
/** | ||
* Drop trailing initial and final `br`s. | ||
* | ||
* @template {Nodes} Node | ||
* Node type. | ||
* @param {Array<Node>} nodes | ||
* List of nodes. | ||
* @returns {Array<Node>} | ||
* List of nodes w/o `break`s. | ||
*/ | ||
export function dropSurroundingBreaks(nodes) { | ||
let start = 0 | ||
let end = nodes.length | ||
|
||
while (start < end && nodes[start].type === 'break') start++ | ||
while (end > start && nodes[end - 1].type === 'break') end-- | ||
|
||
return start === 0 && end === nodes.length ? nodes : nodes.slice(start, end) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,10 @@ juliett | |
mike | ||
|
||
november | ||
|
||
oscar\ | ||
papa | ||
|
||
quebec | ||
|
||
romeo |
d6cab31
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.
@wooorm this breaks our roundtrip tests that convert html->hast->mdast->md->mdast->hast->html.
it removes the
<br>
at the beginning of a paragraph.d6cab31
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.
Hi Tobias! That is intentional, see the test fixture in this commit (
<h1><br>kilo</h1>
), it wasn’t caught before due to thep
starting with acode
. See also GH-83.If you have lots of fixtures, then every patch will be a breaking change: I’d recommend a package lock if you worry about that.
d6cab31
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.
hmm, but why is
<p><br>kilo</p>
not transformed into\ kilo
?
there is no way for us to preserve the
break
node.d6cab31
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.
There are many things that are not preserved — the question behind this example is: why would someone write that? It is not semantic: “br elements must be used only for line breaks that are actually part of the content, as in poems or addresses.”
d6cab31
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.
this is a good question :-) authors tend to misuse space/enter for formatting, like for indentation and enforcing page breaks.
d6cab31
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.
Right ;) And, why should that misuse be persisted? I see it exactly otherwise: the goal here is to make readable and clean markdown, to drop that abuse!