Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Currently _pegdown_ supports the following extensions over standard Markdown:
* EXTANCHORLINKS: Generate anchor links for headers using complete contents of the header.
* Spaces and non-alphanumerics replaced by `-`, multiple dashes trimmed to one.
* Anchor link is added as first element inside the header with empty content: `<h1><a name="header"></a>header</h1>`
* EXTANCHORLINKS_WRAP: used in conjunction with above to create an anchor that wraps header content: `<h1><a name="header">header</a></h1>`

Note: _pegdown_ differs from the original Markdown in that it ignores in-word emphasis as in

Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name := "pegdown"

version := "1.6.0"
version := "1.6.4"

homepage := Some(new URL("http://pegdown.org"))

Expand Down
10 changes: 8 additions & 2 deletions src/main/java/org/pegdown/Extensions.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public interface Extensions {

/**
* All of the smartypants prettyfications. Equivalent to SMARTS + QUOTES.
*
*
* @see <a href="http://daringfireball.net/projects/smartypants/">Smartypants</a>
*/
static final int SMARTYPANTS = SMARTS + QUOTES;
Expand Down Expand Up @@ -71,7 +71,7 @@ public interface Extensions {
* @see <a href="http://fletcherpenney.net/multimarkdown/users_guide/">MultiMarkdown</a>
*/
static final int TABLES = 0x20;

/**
* PHP Markdown Extra style definition lists.
* Additionally supports the small extension proposed in the article referenced below.
Expand Down Expand Up @@ -153,6 +153,12 @@ public interface Extensions {
*/
static final int EXTANCHORLINKS = 0x00400000;

/**
* EXTANCHORLINKS should wrap header content instead of creating an empty anchor.
* Anchor link wrapps the header content: `<h1><a name="header-a">header a</a></h1>`
*/
static final int EXTANCHORLINKS_WRAP = 0x00800000;

/**
* All Optionals other than Suppress and FORCELISTITEMPARA which is a backwards compatibility extension
*
Expand Down
30 changes: 26 additions & 4 deletions src/main/java/org/pegdown/LinkRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import org.parboiled.common.StringUtils;
import org.pegdown.ast.*;

import static org.pegdown.FastEncoder.*;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

import static org.pegdown.FastEncoder.encode;
import static org.pegdown.FastEncoder.obfuscate;

/**
* A LinkRenderer is responsible for turning an AST node representing a link into a {@link LinkRenderer.Rendering}
* instance, which hold the actual properties of the link as it is going to be rendered.
Expand Down Expand Up @@ -50,6 +51,20 @@ public Rendering withAttribute(String name, String value) {
}

public Rendering withAttribute(Attribute attr) {
int iMax = attributes.size();

// vsch: a little wasteful, a Map would be better, but we don't have too many attributes and
// this will not break code for those that have implemented their own derived ToHtmlSerializers.
for (int i = 0; i < iMax; i++) {
Attribute attribute = attributes.get(i);
if (attribute.name.equals(attr.name)) {
// vsch: need to handle setting multiple classes, works for values too
// concatenate them with space between values, as for class
attr = new Attribute(attr.name, attribute.value + " " + attr.value);
attributes.remove(i);
break;
}
}
attributes.add(attr);
return this;
}
Expand Down Expand Up @@ -97,10 +112,17 @@ public Rendering render(WikiLinkNode node) {
int pos;
if ((pos = text.indexOf("|")) >= 0) {
url = text.substring(0, pos);
text = text.substring(pos+1);
text = text.substring(pos + 1);
}

// vsch: #200 WikiLinks can have anchor # refs
String suffix = "";
if ((pos = url.lastIndexOf("#")) >= 0) {
suffix = url.substring(pos);
url = url.substring(0, pos);
}

url = "./" + URLEncoder.encode(url.replace(' ', '-'), "UTF-8") + ".html";
url = "./" + URLEncoder.encode(url.replace(' ', '-'), "UTF-8") + ".html" + suffix;
return new Rendering(url, text);
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException();
Expand Down
Loading