Skip to content

Commit

Permalink
Do not prefix standalone linebreaks (as often emitted from HTML parsers
Browse files Browse the repository at this point in the history
without any semantical meaning)
  • Loading branch information
kwin committed Oct 19, 2024
1 parent 6631e16 commit 6a78acb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -873,9 +873,6 @@ public void nonBreakingSpace() {

@Override
public void text(String text, SinkEventAttributes attributes) {
if (text.equals("\n")) {
return;
}
if (attributes != null) {
inline(attributes);
}
Expand All @@ -885,10 +882,12 @@ public void text(String text, SinkEventAttributes attributes) {
LOGGER.warn("{}Ignoring unsupported table caption in Markdown", getLocationLogPrefix());
} else {
String unifiedText = currentContext.escape(unifyEOLs(text));
// each line must potentially be prefixed
String prefix = getLinePrefix();
if (prefix.length() > 0) {
unifiedText = unifiedText.replaceAll(EOL, EOL + prefix);
// ignore newlines only, because those are emitted often coming from linebreaks in HTML with no semantical meaning
if (!unifiedText.equals(EOL)) {
String prefix = getLinePrefix();
if (prefix.length() > 0) {
unifiedText = unifiedText.replaceAll(EOL, EOL + prefix);
}
}
writeUnescaped(unifiedText);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ public void testRoundtrip() throws IOException, ParseException {

final SinkEventTestingSink originalSink = new SinkEventTestingSink();
parseFile(parser, "test", originalSink);
// strip empty lines from sink content

// compare sink events from parsing original markdown with sink events from re-generated markdown
try {
Expand Down Expand Up @@ -518,7 +519,7 @@ public void testMultilineVerbatimSourceAfterListItem() {
sink.listItem();
sink.text("Before");
sink.verbatim(SinkEventAttributeSet.SOURCE);
sink.text("codeline1\ncodeline2");
sink.text("codeline1" + EOL + "codeline2");
sink.verbatim_();
sink.text("After");
sink.listItem_();
Expand Down

0 comments on commit 6a78acb

Please sign in to comment.