Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 70 - Update to pegdown-1.5.0 #72

Merged
merged 6 commits into from
Mar 13, 2015
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 6 additions & 6 deletions nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -231,20 +231,20 @@
</test-dependencies>
<public-packages/>
<class-path-extension>
<runtime-relative-path>ext/parboiled-java-1.1.6.jar</runtime-relative-path>
<binary-origin>release/modules/ext/parboiled-java-1.1.6.jar</binary-origin>
<runtime-relative-path>ext/parboiled-java-1.1.7.jar</runtime-relative-path>
<binary-origin>release/modules/ext/parboiled-java-1.1.7.jar</binary-origin>
</class-path-extension>
<class-path-extension>
<runtime-relative-path>ext/pegdown-1.4.2.jar</runtime-relative-path>
<binary-origin>release/modules/ext/pegdown-1.4.2.jar</binary-origin>
<runtime-relative-path>ext/pegdown-1.5.0.jar</runtime-relative-path>
<binary-origin>release/modules/ext/pegdown-1.5.0.jar</binary-origin>
</class-path-extension>
<class-path-extension>
<runtime-relative-path>ext/asm-util-4.1.jar</runtime-relative-path>
<binary-origin>release/modules/ext/asm-util-4.1.jar</binary-origin>
</class-path-extension>
<class-path-extension>
<runtime-relative-path>ext/parboiled-core-1.1.6.jar</runtime-relative-path>
<binary-origin>release/modules/ext/parboiled-core-1.1.6.jar</binary-origin>
<runtime-relative-path>ext/parboiled-core-1.1.7.jar</runtime-relative-path>
<binary-origin>release/modules/ext/parboiled-core-1.1.7.jar</binary-origin>
</class-path-extension>
<class-path-extension>
<runtime-relative-path>ext/asm-4.1.jar</runtime-relative-path>
Expand Down
Binary file removed release/modules/ext/parboiled-core-1.1.6.jar
Binary file not shown.
Binary file added release/modules/ext/parboiled-core-1.1.7.jar
Binary file not shown.
Binary file removed release/modules/ext/parboiled-java-1.1.6.jar
Binary file not shown.
Binary file added release/modules/ext/parboiled-java-1.1.7.jar
Binary file not shown.
Binary file removed release/modules/ext/pegdown-1.4.2.jar
Binary file not shown.
Binary file added release/modules/ext/pegdown-1.5.0.jar
Binary file not shown.
40 changes: 37 additions & 3 deletions src/flow/netbeans/markdown/PreviewLinkRenderer.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package flow.netbeans.markdown;

import java.net.MalformedURLException;
Expand All @@ -12,14 +11,26 @@
import org.pegdown.ast.WikiLinkNode;

/**
* Turns pegdown AST link nodes into rendered links, optionally resolving relative URLs to
* absolute URLs using a given base URL.
*
* @author Holger Stenger
*/
public class PreviewLinkRenderer extends LinkRenderer {

/** The base URL against which absolute URLs should be resolved. */
private final URL baseUrl;

/** Indicates whether relative URLs should be resolved against the base URL. */
private final boolean resolveLinkUrls;

/**
* Create a new link renderer that will optionally resolve relative URLs to absolute URLs.
*
* @param baseUrl the base URL against which relative URLs will be resolved.
* @param resolveLinkUrls if true, relative URLs in rendered links will be resolved to
* absolute URLs with the given base URL.
*/
public PreviewLinkRenderer(URL baseUrl, boolean resolveLinkUrls) {
super();
this.baseUrl = baseUrl;
Expand Down Expand Up @@ -51,6 +62,14 @@ public LinkRenderer.Rendering render(RefLinkNode node, String url, String title,
return transform(super.render(node, url, title, text));
}

/**
* Resolves relative URLs against a base URL to return an absolute URL.
*
* @param uriText the possibly relative URL to resolve
* @return the absolute form of the provided relative URL; if the URL is already absolute, or if it
* would otherwise result in an invalid URL when resolved against the base URL, then the
* original string is returned unmodified
*/
private String resolveUrl(final String uriText) {
try {
return baseUrl.toURI().resolve(uriText).toURL().toExternalForm();
Expand All @@ -62,11 +81,26 @@ private String resolveUrl(final String uriText) {
return uriText;
}

/**
* Transforms the rendered link's href URL to its absolute form using a base URL,
* if URL resolution is turned on.
*
* @param rendering the previously rendered link
* @return if URL resolution is turned on and the link is relative, then the rendered
* link with the href URL in its absolute form using the base URL provided to
* this renderer; otherwise the original rendered link
*/
private LinkRenderer.Rendering transform(LinkRenderer.Rendering rendering) {
if (resolveLinkUrls && (rendering.href != null)) {
rendering.href = resolveUrl(rendering.href);
LinkRenderer.Rendering resolvedRendering = new LinkRenderer.Rendering(
resolveUrl(rendering.href), rendering.text);
for (LinkRenderer.Attribute attr : rendering.attributes) {
resolvedRendering.withAttribute(attr);
}
return resolvedRendering;
} else {
return rendering;
}
return rendering;
}

}
8 changes: 7 additions & 1 deletion src/flow/netbeans/markdown/csl/MarkdownInlineVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package flow.netbeans.markdown.csl;

import org.pegdown.ast.AbbreviationNode;
import org.pegdown.ast.AnchorLinkNode;
import org.pegdown.ast.AutoLinkNode;
import org.pegdown.ast.BlockQuoteNode;
import org.pegdown.ast.BulletListNode;
Expand Down Expand Up @@ -61,6 +62,11 @@ public void visit(AbbreviationNode node) {
visitChildren(node);
}

@Override
public void visit(AnchorLinkNode node) {
plainText.append(node.getText());
}

@Override
public void visit(AutoLinkNode node) {
plainText.append(node.getText());
Expand Down Expand Up @@ -258,7 +264,7 @@ public void visit(SuperNode node) {
public void visit(Node node) {
visitChildren(node);
}

@Override
public void visit(StrikeNode node) {
visitChildren(node);
Expand Down
5 changes: 5 additions & 0 deletions src/flow/netbeans/markdown/csl/MarkdownTOCVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.netbeans.modules.csl.api.StructureItem;
import org.openide.filesystems.FileObject;
import org.pegdown.ast.AbbreviationNode;
import org.pegdown.ast.AnchorLinkNode;
import org.pegdown.ast.AutoLinkNode;
import org.pegdown.ast.BlockQuoteNode;
import org.pegdown.ast.BulletListNode;
Expand Down Expand Up @@ -68,6 +69,10 @@ public List<OffsetRange> getOffsetRanges() {
public void visit(AbbreviationNode node) {
}

@Override
public void visit(AnchorLinkNode node) {
}

@Override
public void visit(AutoLinkNode node) {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package flow.netbeans.markdown.highlighter;

import org.pegdown.ast.AbbreviationNode;
import org.pegdown.ast.AnchorLinkNode;
import org.pegdown.ast.AutoLinkNode;
import org.pegdown.ast.BlockQuoteNode;
import org.pegdown.ast.BulletListNode;
Expand Down Expand Up @@ -90,6 +91,11 @@ public void visit(AbbreviationNode node) {
endTreeToken();
}

@Override
public void visit(AnchorLinkNode node) {
addLeafTreeToken(MarkdownTokenId.ANCHORLINK, node);
}

@Override
public void visit(AutoLinkNode node) {
addLeafTreeToken(MarkdownTokenId.AUTOLINK, node);
Expand Down
3 changes: 2 additions & 1 deletion src/flow/netbeans/markdown/highlighter/MarkdownTokenId.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
public enum MarkdownTokenId implements TokenId {

ABBREVIATION,
ANCHORLINK,
AUTOLINK,
BLOCKQUOTE,
BULLETLIST,
Expand Down Expand Up @@ -45,7 +46,7 @@ public enum MarkdownTokenId implements TokenId {
REF_LINK,
WHITESPACE,
STRIKETHROUGH;

private static final Language<MarkdownTokenId> LANGUAGE = new LanguageHierarchy<MarkdownTokenId>() {

@Override
Expand Down