#9, #8, #7 fix
diff --git a/.gitignore b/.gitignore
index f14e302..5388b3f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,7 @@
*.ipr
*.iws
.settings/
+.idea/
target/
core/target/
cli/target/
diff --git a/core/src/main/java/org/tautua/markdownpapers/HtmlEmitter.java b/core/src/main/java/org/tautua/markdownpapers/HtmlEmitter.java
index 1b9f2a4..de98d25 100644
--- a/core/src/main/java/org/tautua/markdownpapers/HtmlEmitter.java
+++ b/core/src/main/java/org/tautua/markdownpapers/HtmlEmitter.java
@@ -148,6 +148,11 @@
node.childrenAccept(this);
}
+ @Override
+ public void visit(LineBreak node) {
+ append("<br/>");
+ }
+
public void visit(Link node) {
Resource resource = node.getResource();
if (resource == null) {
@@ -325,7 +330,7 @@
} else {
for (int i = 1; i < node.jjtGetChild(0).jjtGetNumChildren(); i++) {
Node sibling = node.jjtGetChild(0).jjtGetChild(i);
- if (!(sibling instanceof Text && ((Text)sibling).isWhitespace())) {
+ if (!(sibling instanceof Text && ((Text)sibling).isWhitespace()) ) {
return false;
}
}
diff --git a/core/src/main/java/org/tautua/markdownpapers/ast/LineBreak.java b/core/src/main/java/org/tautua/markdownpapers/ast/LineBreak.java
new file mode 100644
index 0000000..2df9e52
--- /dev/null
+++ b/core/src/main/java/org/tautua/markdownpapers/ast/LineBreak.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2011, TAUTUA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.tautua.markdownpapers.ast;
+
+/**
+ * @author Larry Ruiz
+ */
+public class LineBreak extends SimpleNode {
+
+ public LineBreak(int id) {
+ super(id);
+ }
+
+ @Override
+ public void accept(Visitor visitor) {
+ visitor.visit(this);
+ }
+}
\ No newline at end of file
diff --git a/core/src/main/java/org/tautua/markdownpapers/ast/Visitor.java b/core/src/main/java/org/tautua/markdownpapers/ast/Visitor.java
index d35d144..721f0e8 100644
--- a/core/src/main/java/org/tautua/markdownpapers/ast/Visitor.java
+++ b/core/src/main/java/org/tautua/markdownpapers/ast/Visitor.java
@@ -42,18 +42,20 @@
void visit(Image node);
- void visit(Link node);
+ void visit(Line node);
+
+ void visit(LineBreak node);
+ void visit(Link node);
+
+ void visit(List node);
+
void visit(InlineUrl node);
void visit(Item node);
- void visit(Line node);
-
void visit(ResourceDefinition node);
- void visit(List node);
-
void visit(OpeningTag node);
void visit(Paragraph node);
diff --git a/core/src/main/jjtree/Markdown.jjt b/core/src/main/jjtree/Markdown.jjt
index c6e1b70..756fe88 100644
--- a/core/src/main/jjtree/Markdown.jjt
+++ b/core/src/main/jjtree/Markdown.jjt
@@ -186,7 +186,7 @@
if (t.any(EOL)) {
newline = true;
}
- } while(t.any(SPACE, TAB, EOL));
+ } while(t.any(SPACE, TAB, GT, EOL));
Item item = (Item)stack.peek();
@@ -225,7 +225,8 @@
Item item = (Item)stack.peek();
- return t.any(PLUS, MINUS, STAR, NUMBERING) && item.getIndentation() < t.beginColumn;
+ return t.any(PLUS, MINUS, STAR, NUMBERING) && item.getIndentation() < t.beginColumn
+ && quoteLevel <= currentQuoteLevel;
}
boolean ItemLookahead() {
@@ -293,6 +294,7 @@
| < SINGLE_QUOTE : "'" >
| < SLASH : "/" >
| < STAR : "*" >
+ | < UNDERSCORE : "_" >
}
TOKEN : {
@@ -323,7 +325,7 @@
< CHAR_ENTITY_REF : "&" ( ["a"-"z", "A"-"Z"] )+ ";" >
| < NUMERIC_CHAR_REF : "&" ( ( ["0"-"9"] ){1,4} | "x" ( ["0"-"9", "a"-"f", "A"-"F"] ){1,4} ) ";" >
| < ESCAPED_CHAR : "\\" ["{", "}", "[", "]", "(", ")", "\\", "`", "_", ">", "#", ".", "!", "+", "-", "*"] >
- | < CHAR_SEQUENCE : ( ~["=", "#", "&", "*", "\"", "'", "`", ":", "<", ">", "(", ")", "[", "]", " ", "\\", "/", "\t", "\r", "\n", "!"] )+ >
+ | < CHAR_SEQUENCE : ( ~["=", "#", "&", "*", "\"", "'", "`", ":", "<", ">", "(", ")", "[", "]", " ", "\\", "/", "\t", "\r", "\n", "!", "_"] )+ >
}
void Document() #Document : {} {
@@ -343,9 +345,9 @@
}
void BlockElement() : {} {
- LOOKAHEAD( Header() ( <EOL> | <EOF> ) ) Header()
+ LOOKAHEAD( Ruler() ( <EOL> | <EOF> ) ) Ruler()
+ | LOOKAHEAD( Header() ( <EOL> | <EOF> ) ) Header()
| LOOKAHEAD( EmptyLine() ) Whitespace()
- | LOOKAHEAD( Ruler() ( <EOL> | <EOF> ) ) Ruler()
| LOOKAHEAD( CodeLine() ) Code()
| LOOKAHEAD( QuotePrefix() ) Quote()
| LOOKAHEAD( ( InsignificantWhitespace() )? ( <PLUS> | <MINUS> | <STAR> | <NUMBERING> ) ( <SPACE> | <TAB> ) ) List()
@@ -353,6 +355,11 @@
| Paragraph()
}
+/*
+void HtmlBlock() : {} {
+ Tag()
+}
+*/
void Whitespace() : {} {
( <SPACE> | <TAB> )+
}
@@ -486,6 +493,7 @@
| t = <SPACE>
| t = <STAR>
| t = <STAR_RULER>
+ | t = <UNDERSCORE>
| t = <UNDERSCORE_RULER>
) { jjtThis.append(t.image); }
| t = <TAB> { jjtThis.append(toWhitespace(prev, t)); }
@@ -536,8 +544,9 @@
Paragraph()
(
LOOKAHEAD( {ParagraphLookahead()} ) <EOL> ( LOOKAHEAD( EmptyLine() ) ( Whitespace() )? <EOL> )* Paragraph() { jjtThis.makeLoose(); }
- | LOOKAHEAD( {ListLookahead()} ) <EOL> ( LOOKAHEAD( EmptyLine() ) ( Whitespace() )? <EOL> )* List()
| LOOKAHEAD( {LooseLookahead()} ) <EOL> ( Whitespace() )? { jjtThis.makeLoose(); }
+ | LOOKAHEAD( {ListLookahead()} ) <EOL> ( LOOKAHEAD( EmptyLine() ) ( Whitespace() )? <EOL> )* List()
+
)*
{
Item item = (Item)stack.pop();
@@ -563,11 +572,16 @@
| LOOKAHEAD( Tag() ) Tag()
| LOOKAHEAD( Image() ) Image()
| LOOKAHEAD( Link() ) Link()
+ | LOOKAHEAD( LineBreak() <EOL> ) LineBreak()
| Text()
)
)+
}
+void LineBreak() #LineBreak : {} {
+ <SPACE> <SPACE>
+}
+
void Text() #Text : {
Token t;
String v;
@@ -830,6 +844,7 @@
(
t = <CHAR_SEQUENCE>
| t = "&"
+ | t = <EQ>
| t = "(" { parentheses++; }
| LOOKAHEAD({parentheses > 0}) t = ")" { parentheses--; }
| t = "["
@@ -838,7 +853,7 @@
| t = "/"
| t = "\\"
| t = "#"
- | t = "="
+ | t = <UNDERSCORE>
) { buff.append(t.image); }
) +
{ parentheses = 0; return buff.toString(); }
@@ -880,6 +895,7 @@
| t = "\\"
| t = "'"
| t = "\""
+ | t = <UNDERSCORE>
) { buff.append(t.image); }
)*
{ return buff.toString(); }
@@ -917,6 +933,7 @@
| t = <STAR>
| t = <STAR_RULER>
| t = <TAB>
+ | t = <UNDERSCORE>
| t = <UNDERSCORE_RULER>
) { return t.image; }
}
diff --git a/core/src/test/java/org/tautua/markdownpapers/MarkdownPapersTest.java b/core/src/test/java/org/tautua/markdownpapers/MarkdownPapersTest.java
index 3486b36..825d064 100644
--- a/core/src/test/java/org/tautua/markdownpapers/MarkdownPapersTest.java
+++ b/core/src/test/java/org/tautua/markdownpapers/MarkdownPapersTest.java
@@ -36,7 +36,9 @@
{"code"},
{"comments"},
{"headers"},
- {"inline"},
+ {"images"},
+ {"inline"},
+ {"linebreak"},
{"list"},
{"paragraphs"},
{"quoteAndList"},
diff --git a/core/src/test/resources/others/images.html b/core/src/test/resources/others/images.html
new file mode 100644
index 0000000..b13db79
--- /dev/null
+++ b/core/src/test/resources/others/images.html
@@ -0,0 +1,5 @@
+<p><img alt="alt" src="path/to/image1.png" title="title"/></p>
+
+<p><img alt="alt" src="path/to/image2.png" title="title"/></p>
+
+<p><img alt="alt" src="path/to/image.png"/></p>
\ No newline at end of file
diff --git a/core/src/test/resources/others/images.text b/core/src/test/resources/others/images.text
new file mode 100644
index 0000000..650ebea
--- /dev/null
+++ b/core/src/test/resources/others/images.text
@@ -0,0 +1,6 @@
+
+
+[id]: path/to/image2.png "title"
+![alt][id]
+
+
\ No newline at end of file
diff --git a/core/src/test/resources/others/linebreak.html b/core/src/test/resources/others/linebreak.html
new file mode 100644
index 0000000..16860bb
--- /dev/null
+++ b/core/src/test/resources/others/linebreak.html
@@ -0,0 +1,2 @@
+<p>there is a line break at the end <br/>
+another line.</p>
\ No newline at end of file
diff --git a/core/src/test/resources/others/linebreak.text b/core/src/test/resources/others/linebreak.text
new file mode 100644
index 0000000..59e52bb
--- /dev/null
+++ b/core/src/test/resources/others/linebreak.text
@@ -0,0 +1,2 @@
+there is a line break at the end
+another line.
\ No newline at end of file
diff --git a/core/src/test/resources/others/underscore.html b/core/src/test/resources/others/underscore.html
index 60f6020..d33d0ff 100644
--- a/core/src/test/resources/others/underscore.html
+++ b/core/src/test/resources/others/underscore.html
@@ -1,7 +1,7 @@
<h1> First header</h1>
<ul>
- <li>Invisible underscore: _, c.</li>
+ <li>Invisible underscore: _, c.<br/></li>
</ul>
<h1> Second header</h1>
diff --git a/doxia-module/src/main/java/org/tautua/markdownpapers/doxia/SinkEventEmitter.java b/doxia-module/src/main/java/org/tautua/markdownpapers/doxia/SinkEventEmitter.java
index 0c59a80..7f28d90 100644
--- a/doxia-module/src/main/java/org/tautua/markdownpapers/doxia/SinkEventEmitter.java
+++ b/doxia-module/src/main/java/org/tautua/markdownpapers/doxia/SinkEventEmitter.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2011, TAUTUA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.tautua.markdownpapers.doxia;
import org.apache.maven.doxia.sink.Sink;
@@ -106,19 +122,12 @@
Resource resource = node.getResource();
SinkEventAttributes attr = new SinkEventAttributeSet();
attr.addAttribute(SinkEventAttributeSet.ALT, node.getText());
- attr.addAttribute(SinkEventAttributeSet.TITLE, resource.getHint());
-
- if (node.jjtGetParent() instanceof Line && node.jjtGetParent().jjtGetNumChildren() == 1) {
- sink.figure();
- sink.figureGraphics(resource.getLocation(), attr);
- sink.figureCaption();
- sink.text(resource.getHint());
- sink.figureCaption_();
- sink.figure_();
- } else {
- // inline graphics
- sink.figureGraphics(resource.getLocation(), attr);
+ if(resource.getHint() != null) {
+ attr.addAttribute(SinkEventAttributeSet.TITLE, resource.getHint());
}
+
+ sink.figureGraphics(resource.getLocation(), attr);
+
}
public void visit(Link node) {
@@ -151,6 +160,10 @@
sink.text("\n");
}
+ public void visit(LineBreak node) {
+ sink.lineBreak();
+ }
+
public void visit(ResourceDefinition node) {
//do nothing
}