Permalink
Browse files

Merge branch 'master' of github.com:sirthias/pegdown into develop

  • Loading branch information...
2 parents 73d6f61 + 69b1e31 commit ec23ce51aea3ffabcf00276aa29d250732b74f11 @sirthias committed Oct 4, 2011
View
@@ -8,8 +8,8 @@ _pegdown_ is nearly 100% compatible with the original Markdown specification and
On top of the standard Markdown feature set _pegdown_ implements a number of extensions similar to what other popular Markdown processors offer.
Currently _pegdown_ supports the following extensions over standard Markdown:
-* SMARTS: Beautifys apostrophes, ellipsises ("..." and ". . .") and dashes ("--" and "---")
-* QUOTES: Beautifys single quotes, double quotes and double angle quotes (« and »)
+* SMARTS: Beautifies apostrophes, ellipses ("..." and ". . .") and dashes ("--" and "---")
+* QUOTES: Beautifies single quotes, double quotes and double angle quotes (« and »)
* SMARTYPANTS: Convenience extension enabling both, SMARTS and QUOTES, at once.
* ABBREVIATIONS: Abbreviations in the way of [PHP Markdown Extra][].
* HARDWRAPS: Alternative handling of newlines, see [Github-flavoured-Markdown][]
@@ -20,6 +20,7 @@ Currently _pegdown_ supports the following extensions over standard Markdown:
* HTML BLOCK SUPPRESSION: Suppresses the output of HTML blocks.
* INLINE HTML SUPPRESSION: Suppresses the output of inline HTML elements.
* NO_FOLLOW_LINKS: Attaches a `rel="nofollow"` attribute to all generated HTML links.
+* WIKILINKS: Support Github-style wiki links to relative HTML files.
Note: _pegdown_ differs from the original Markdown in that it ignores in-word emphasis as in
@@ -95,7 +96,7 @@ tool [peg-markdown](http://github.com/jgm/peg-markdown).
License
-------
-_pegdown_ is licensed under [APL 2.0](http://www.apache.org/licenses/LICENSE-2.0).
+_pegdown_ is licensed under [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0).
Patch Policy
@@ -26,7 +26,7 @@
static final int NONE = 0x00;
/**
- * Pretty ellipsises, dashes and apostrophes.
+ * Pretty ellipses, dashes and apostrophes.
*/
static final int SMARTS = 0x01;
@@ -57,8 +57,8 @@
static final int HARDWRAPS = 0x08;
/**
- * Enables plain autolinks the way github flavoures markdown implements them.
- * With this extension enabled pegdown will intelligently recognize URLs and email adresses
+ * Enables plain autolinks the way github flavoured markdown implements them.
+ * With this extension enabled pegdown will intelligently recognize URLs and email addresses
* without any further delimiters and mark them as the respective link type.
*
* @see <a href="http://github.github.com/github-flavored-markdown">Github-flavored-Markdown</a>
@@ -89,6 +89,13 @@
static final int FENCED_CODE_BLOCKS = 0x80;
/**
+ * Converts GitHub wiki-links to regular links.
+ *
+ * @see <a href="http://github.github.com/github-flavored-markdown">Github-flavored-Markdown</a>
+ */
+ static final int WIKILINKS = 0x100;
+
+ /**
* All available extensions excluding the HTML SUPPRESSION and NO_FOLLOW_LINKS options.
*/
static final int ALL = 0x0000FFFF;
@@ -684,6 +684,7 @@ public Rule Image() {
public Rule Link() {
return NodeSequence(
FirstOf(
+ ext(WIKILINKS) ? WikiLink() : NOTHING,
Sequence(Label(), FirstOf(ExplicitLink(), ReferenceLink())),
AutoLink()
)
@@ -762,6 +763,15 @@ public Rule AutoLink() {
);
}
+ public Rule WikiLink() {
+ return Sequence(
+ "[[",
+ OneOrMore(TestNot(']'), ANY), // Not sure ANY is appropriate here, but certainly some symbols and whitespace are
+ push(new WikiLinkNode(match(), ext(NO_FOLLOW_LINKS))),
+ "]]"
+ );
+ }
+
public Rule AutoLinkUrl() {
return Sequence(
Sequence(OneOrMore(Letter()), "://", AutoLinkEnd()),
@@ -313,6 +313,14 @@ public void visit(VerbatimNode node) {
printer.print("</code></pre>");
}
+ public void visit(WikiLinkNode node) {
+ printer.print("<a href=\"")
+ .printEncoded(node.getUrl(), this)
+ .print(node.isNofollow() ? "\" rel=\"nofollow\">" : "\">")
+ .printEncoded(node.getText(), this)
+ .print("</a>");
+ }
+
public String transformVerbatimText(String text) {
// transform all initial newlines to HTML breaks
while(text.charAt(0) == '\n') {
@@ -50,6 +50,7 @@
void visit(TableNode node);
void visit(TableRowNode node);
void visit(VerbatimNode node);
+ void visit(WikiLinkNode node);
void visit(TextNode node);
void visit(SuperNode node);
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2010-2011 Mathias Doenitz
+ *
+ * Based on peg-markdown (C) 2008-2010 John MacFarlane
+ *
+ * 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.pegdown.ast;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+
+public class WikiLinkNode
+ extends TextNode {
+ private boolean nofollow;
+ private String url;
+
+ public WikiLinkNode(String page, boolean nofollow) {
+ super(page);
+ String s;
+ try {
+ s = URLEncoder.encode(page.replace(' ', '-'), "UTF-8");
+ }
+ catch (UnsupportedEncodingException e) {
+ s = page;
+ }
+ this.url = "./" + s + ".html";
+ this.nofollow = nofollow;
+ }
+
+ public boolean isNofollow() {
+ return nofollow;
+ }
+
+ public String getUrl()
+ {
+ return url;
+ }
+
+ @Override
+ public void accept(Visitor visitor) {
+ visitor.visit(this);
+ }
+}
@@ -60,6 +60,7 @@ public void customPegDownTests() {
test("pegdown/Quoted Blockquote");
test("pegdown/Smartypants");
test("pegdown/Tables");
+ test("pegdown/Wikilinks");
}
@Test(dependsOnMethods = "customPegDownTests")
@@ -0,0 +1,11 @@
+<h1>Wikilinks</h1>
+<p>Wikilinks are simple URIs like <a href=
+"./Autolinks.html">Autolinks</a>,<br/>
+which will be converted by pegdown.</p>
+<p>Another example with spaces: <a href="./Special-Chars.html">Special Chars</a>.</p>
+<p>The following links should work just normally:</p>
+<ul>
+<li><a href="http://example">example</a></li>
+<li><a href="http://example">ex@mple</a></li>
+<li><a href="http://example">example://</a></li>
+</ul>
@@ -0,0 +1,12 @@
+# Wikilinks
+
+Wikilinks are simple URIs like [[Autolinks]],
+which will be converted by pegdown.
+
+Another example with spaces: [[Special Chars]].
+
+The following links should work just normally:
+
+* [example](http://example)
+* [ex@mple](http://example)
+* [example://](http://example)

0 comments on commit ec23ce5

Please sign in to comment.