Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
vsch committed Jan 3, 2016
1 parent 52de8d3 commit 6e5d118
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions src/main/java/org/pegdown/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,15 @@ public Rule Block() {
}

public Rule Para() {
return NodeSequence(
// The Para Rule only tests for the presence of a following blank line, but does not consume it.
// this means that phantom \n's will not be part of the node's source range, except when
// the input had no EOL's at the end at all, even then only one of these will be included
NonindentSpace(), Inlines(), push(new ParaNode(popAsNode())), Test(BlankLine())
return Sequence(
NonindentSpace(),
NodeSequence(
// The Para Rule only tests for the presence of a following blank line, but does not consume it.
// this means that phantom \n's will not be part of the node's source range, except when
// the input had no EOL's at the end at all, even then only one of these will be included
Inlines(), push(new ParaNode(popAsNode())), Test(BlankLine())

)
);
}

Expand All @@ -144,8 +147,8 @@ public Rule Para() {
public Rule Footnote() {
Var<FootnoteNode> node = new Var<FootnoteNode>();
return Sequence(
NonindentSpace(),
NodeSequence(
NonindentSpace(),
Sequence(
FootnoteLabel(), Sp(), ':', Sp()
),
Expand Down Expand Up @@ -243,12 +246,14 @@ public Rule CodeFence(Var<Integer> markerLength) {
}

public Rule HorizontalRule() {
return NodeSequence(
return Sequence(
NonindentSpace(),
FirstOf(HorizontalRule('*'), HorizontalRule('-'), HorizontalRule('_')),
Sp(), Newline(),
(ext(RELAXEDHRULES) ? EMPTY : Test(BlankLine())),
push(new SimpleNode(Type.HRule))
NodeSequence(
FirstOf(HorizontalRule('*'), HorizontalRule('-'), HorizontalRule('_')),
Sp(), Newline(),
(ext(RELAXEDHRULES) ? EMPTY : Test(BlankLine())),
push(new SimpleNode(Type.HRule))
)
);
}

Expand Down Expand Up @@ -1355,15 +1360,16 @@ public Rule Label() {
// here we exclude the EOL at the end from the node's text range
public Rule Reference() {
return Sequence(
ReferenceNoEOL(),
// vsch: moved NonindentSpace() outside of the ReferenceNode range, otherwise the leading spaces were included as part of the node range.
NonindentSpace(), ReferenceNoEOL(),
Newline()
);
}

public Rule ReferenceNoEOL() {
Var<ReferenceNode> ref = new Var<ReferenceNode>();
return NodeSequence(
NonindentSpace(), Label(), push(ref.setAndGet(new ReferenceNode(popAsNode()))),
Label(), push(ref.setAndGet(new ReferenceNode(popAsNode()))),
':', Spn1(), RefSrc(ref),
Sp(), Optional(RefTitle(ref)),
Sp(),
Expand Down Expand Up @@ -1648,10 +1654,13 @@ public Rule Digit() {

public Rule Abbreviation() {
Var<AbbreviationNode> node = new Var<AbbreviationNode>();
return NodeSequence(
NonindentSpace(), '*', Label(), push(node.setAndGet(new AbbreviationNode(popAsNode()))),
Sp(), ':', Sp(), AbbreviationText(node),
abbreviations.add(node.get())
return Sequence(
NonindentSpace(),
NodeSequence(
'*', Label(), push(node.setAndGet(new AbbreviationNode(popAsNode()))),
Sp(), ':', Sp(), AbbreviationText(node),
abbreviations.add(node.get())
)
);
}

Expand All @@ -1668,10 +1677,13 @@ public Rule AbbreviationText(Var<AbbreviationNode> node) {
//*************** TOC *****************

public Rule Toc() {
return NodeSequence("[TOC",
Optional(Sp(), "level=", Digit(), push(match())),
"]",
push(new TocNode(headers, peek() instanceof String ? Integer.parseInt(popAsString()) : 6))
return Sequence(
NonindentSpace(),
NodeSequence("[TOC",
Optional(Sp(), "level=", Digit(), push(match())),
"]",
push(new TocNode(headers, peek() instanceof String ? Integer.parseInt(popAsString()) : 6))
)
);
}

Expand Down

0 comments on commit 6e5d118

Please sign in to comment.