Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
vsch committed Oct 27, 2015
1 parent 6c32ab4 commit 3052c39
Show file tree
Hide file tree
Showing 11 changed files with 204 additions and 60 deletions.
11 changes: 9 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,13 @@ public interface Extensions {
*/
static final int EXTANCHORLINKS = 0x00400000;

/**
* 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 wrapping the header content as without EXTANCHORLINKS: `<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
19 changes: 17 additions & 2 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
Loading

0 comments on commit 3052c39

Please sign in to comment.