Skip to content

Commit a239307

Browse files
committed
fix for sirthias#222
1 parent b18095e commit a239307

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

CHANGELOG

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ This function is also called for VerbatimNode from the DefaultVerbatimSerializer
7575
preceded by alphanumeric for _ and as long as not surrounded by spaces for * instead
7676
of only when preceded by spaces.
7777

78+
- Added allowing code fenced blocks with all blank lines
79+
7880
Version 1.6.0 (2015-09-18)
7981
--------------------------
8082
- Fixed collision between ANCHORLINKS and STRIKETHROUGH, WIKILINKS extensions (#161)

src/main/java/org/pegdown/DefaultVerbatimSerializer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void serialize(final VerbatimNode node, final Printer printer) {
1717
printer.println().print("<pre><code").print(printer.preview(node, "code", attributes, false)).print('>');
1818
String text = node.getText();
1919
// print HTML breaks for all initial newlines
20-
while (text.charAt(0) == '\n') {
20+
while (!text.isEmpty() && text.charAt(0) == '\n') {
2121
printer.print("<br/>");
2222
text = text.substring(1);
2323
}

src/main/java/org/pegdown/Parser.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,14 @@ public Rule FencedCodeBlock() {
222222
Var<Integer> markerLength = new Var<Integer>();
223223
return NodeSequence(
224224
// vsch: test to see if what appears to be a code fence is just inline code
225+
// vsch: change to accept code fence with all blank lines
225226
CodeFence(markerLength),
226-
TestNot(CodeFence(markerLength)), // prevent empty matches
227-
ZeroOrMore(BlankLine(), text.append('\n')),
228-
OneOrMore(TestNot(Newline(), CodeFence(markerLength)), ANY, text.append(matchedChar())),
229-
Newline(),
230-
push(new VerbatimNode(text.appended('\n').getString(), popAsString())),
227+
OneOrMore(
228+
TestNot(CodeFence(markerLength)),
229+
ZeroOrMore(TestNot(Newline()), ANY, text.append(matchedChar())),
230+
Sequence(Newline(), text.append(matchedChar()))
231+
),
232+
push(new VerbatimNode(text.getString(), popAsString())),
231233
CodeFence(markerLength), drop()
232234
);
233235
}
@@ -1461,8 +1463,7 @@ ticks, Sp(),
14611463
FirstOf(
14621464
Sequence(TestNot('`'), Nonspacechar()),
14631465
Sequence(TestNot(ticks), OneOrMore('`')),
1464-
Sequence(TestNot(Sp(), ticks),
1465-
FirstOf(Spacechar(), Sequence(Newline(), TestNot(BlankLine()))))
1466+
Sequence(TestNot(Sp(), ticks), FirstOf(Spacechar(), Sequence(Newline(), TestNot(BlankLine()))))
14661467
)
14671468
),
14681469
push(new CodeNode(match())),

0 commit comments

Comments
 (0)