-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initialize Markdown project with marked parser ported in Java. See
- Loading branch information
1 parent
698a4e0
commit 6616fec
Showing
24 changed files
with
957 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> | ||
<classpathentry kind="src" path="src/main/java"/> | ||
<classpathentry kind="src" path="src/main/resources"/> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/bin | ||
/target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>org.eclipse.tm4e.markdown</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.pde.ManifestBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.pde.SchemaBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.m2e.core.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.m2e.core.maven2Nature</nature> | ||
<nature>org.eclipse.pde.PluginNature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Manifest-Version: 1.0 | ||
Bundle-ManifestVersion: 2 | ||
Bundle-Name: %pluginName | ||
Bundle-Vendor: %providerName | ||
Bundle-Localization: plugin | ||
Bundle-SymbolicName: org.eclipse.tm4e.markdown;singleton:=true | ||
Bundle-Version: 1.0.0.qualifier | ||
Require-Bundle: org.eclipse.core.runtime | ||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8 | ||
Export-Package: org.eclipse.tm4e.markdown, | ||
org.eclipse.tm4e.markdown.marked | ||
Bundle-ActivationPolicy: lazy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
source.. = src/main/java/,\ | ||
src/main/resources/ | ||
bin.includes = META-INF/,\ | ||
.,\ | ||
plugin.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
############################################################################### | ||
# Copyright (c) 2015-2016 Angelo Zerr and others. | ||
# All rights reserved. This program and the accompanying materials | ||
# are made available under the terms of the Eclipse Public License v1.0 | ||
# which accompanies this distribution, and is available at | ||
# http://www.eclipse.org/legal/epl-v10.html | ||
# | ||
# Contributors: | ||
# Angelo Zerr <[email protected]> - Initial API and implementation | ||
############################################################################### | ||
pluginName=TextMate support in Eclipse IDE - Markdown | ||
providerName=Angelo ZERR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>org.eclipse.tm4e.markdown</artifactId> | ||
<packaging>eclipse-plugin</packaging> | ||
<parent> | ||
<groupId>org.eclipse</groupId> | ||
<artifactId>org.eclipse.tm4e</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
</project> |
39 changes: 39 additions & 0 deletions
39
org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/TMMarkdownPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* Copyright (c) 2015-2016 Angelo ZERR. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Angelo Zerr <[email protected]> - initial API and implementation | ||
*/ | ||
package org.eclipse.tm4e.markdown; | ||
|
||
import org.osgi.framework.BundleActivator; | ||
import org.osgi.framework.BundleContext; | ||
|
||
/** | ||
* OSGi Activator for TextMate Markdown bundle. | ||
* | ||
*/ | ||
public class TMMarkdownPlugin implements BundleActivator { | ||
|
||
public static final String PLUGIN_ID = "org.eclipse.tm4e.markdown"; | ||
|
||
private static BundleContext context; | ||
|
||
static BundleContext getContext() { | ||
return context; | ||
} | ||
|
||
@Override | ||
public void start(BundleContext bundleContext) throws Exception { | ||
TMMarkdownPlugin.context = bundleContext; | ||
} | ||
|
||
@Override | ||
public void stop(BundleContext bundleContext) throws Exception { | ||
TMMarkdownPlugin.context = null; | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/BlockRules.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package org.eclipse.tm4e.markdown.marked; | ||
|
||
import java.util.regex.Matcher; | ||
|
||
public class BlockRules { | ||
|
||
private static final String _tag = "(?!(?:" + "a|em|strong|small|s|cite|q|dfn|abbr|data|time|code" | ||
+ "|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo" | ||
+ "|span|br|wbr|ins|del|img)\\b)\\w+(?!:\\/|[^\\w\\s@]*@)\\b"; | ||
|
||
public static BlockRules normal = normal(); | ||
public static BlockRules gfm = gfm(); | ||
public static BlockRules tables = tables(); | ||
|
||
public final RegExp newline; | ||
public final RegExp code; | ||
public final RegExp fences; | ||
public final RegExp hr; | ||
public final RegExp heading; | ||
public final RegExp nptable; | ||
public final RegExp lheading; | ||
public final RegExp blockquote; | ||
public final RegExp list; | ||
public final RegExp html; | ||
public final RegExp def; | ||
public final RegExp table; | ||
public final RegExp paragraph; | ||
public final RegExp text; | ||
public final RegExp bullet; | ||
public final RegExp item; | ||
|
||
public BlockRules(RegExp newline, RegExp code, RegExp fences, RegExp hr, RegExp heading, RegExp nptable, | ||
RegExp lheading, RegExp blockquote, RegExp list, RegExp html, RegExp def, RegExp table, RegExp paragraph, | ||
RegExp text, RegExp bullet, RegExp item) { | ||
this.newline = newline; | ||
this.code = code; | ||
this.fences = fences; | ||
this.hr = hr; | ||
this.heading = heading; | ||
this.nptable = nptable; | ||
this.lheading = lheading; | ||
this.blockquote = blockquote; | ||
this.list = list; | ||
this.html = html; | ||
this.def = def; | ||
this.table = table; | ||
this.paragraph = paragraph; | ||
this.text = text; | ||
this.bullet = bullet; | ||
this.item = item; | ||
} | ||
|
||
private static BlockRules block() { | ||
RegExp newline = new RegExp("^\\n+"); | ||
RegExp code = new RegExp("^( {4}[^\\n]+\\n*)+/"); | ||
RegExp fences = new RegExp(""); | ||
RegExp hr = new RegExp("^( *[-*_]){3,} *(?:\\n+|$)"); | ||
RegExp heading = new RegExp("^ *(#{1,6}) *([^\\n]+?) *#* *(?:\\n+|$)"); | ||
RegExp nptable = new RegExp(""); | ||
RegExp lheading = new RegExp("^([^\\n]+)\\n *(=|-){2,} *(?:\\n+|$)"); | ||
RegExp blockquote = new RegExp("^( *>[^\\n]+(\\n(?!def)[^\\n]+)*\\n*)+"); | ||
RegExp list = new RegExp("^( *)(bull) [\\s\\S]+?(?:hr|def|\\n{2,}(?! )(?!\\1bull )\\n*|\\s*$)"); | ||
RegExp html = new RegExp("^ *(?:comment *(?:\\n|\\s*$)|closed *(?:\\n{2,}|\\s*$)|closing *(?:\\n{2,}|\\s*$))"); | ||
RegExp def = new RegExp("^ *\\[([^\\]]+)\\]: *<?([^\\s>]+)>?(?: +[\"(]([^\\n]+)[\")])? *(?:\\n+|$)"); | ||
RegExp table = RegExp.noop(); | ||
RegExp paragraph = new RegExp("^((?:[^\\n]+\\n?(?!hr|heading|lheading|blockquote|tag|def))+)\\n*"); | ||
RegExp text = new RegExp("^[^\\n]+"); | ||
RegExp bullet = new RegExp("(?:[*+-]|\\d+\\.)"); | ||
RegExp item = new RegExp("^( *)(bull) [^\\n]*(?:\\n(?!\\1bull )[^\\n]*)*"); | ||
|
||
item.replaceAll("bull", bullet); | ||
list.replaceAll("bull", bullet).replace("hr", "\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))").replace("def", | ||
"\\n+(?=" + def.source + ")"); | ||
blockquote.replace("def", def); | ||
paragraph.replace("hr", hr).replace("heading", heading).replace("lheading", lheading) | ||
.replace("blockquote", blockquote).replace("tag", "<" + _tag).replace("def", def); | ||
return new BlockRules(newline, code, fences, hr, heading, nptable, lheading, blockquote, list, html, def, table, | ||
paragraph, text, bullet, item); | ||
} | ||
|
||
private static BlockRules normal() { | ||
return block(); | ||
} | ||
|
||
private static BlockRules gfm() { | ||
BlockRules gfm = normal(); | ||
gfm.fences.source = "^ *(`{3,}|~{3,})[ \\.]*(\\S+)? *\\n([\\s\\S]*?)\\s*\\1 *(?:\\n+|$)"; | ||
// gfm.paragraph.source = "^"; | ||
gfm.heading.source = "^ *(#{1,6}) +([^\\n]+?) *#* *(?:\\n+|$)"; | ||
String pattern = "(?!" + gfm.fences.source.replaceFirst("\\\\1", "\\\\2") + "|" | ||
+ gfm.list.source.replaceFirst("\\\\1", "\\\\3") + "|"; | ||
//pattern = pattern.replaceAll("\\\"", "\\\\\""); | ||
//pattern = pattern.replaceAll("[$]", "\\\\\\$"); | ||
gfm.paragraph.replace("\\(\\?\\!", pattern); | ||
return gfm; | ||
} | ||
|
||
private static BlockRules tables() { | ||
BlockRules tables = gfm(); | ||
|
||
return tables; | ||
} | ||
} |
155 changes: 155 additions & 0 deletions
155
org.eclipse.tm4e.markdown/src/main/java/org/eclipse/tm4e/markdown/marked/HTMLRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
package org.eclipse.tm4e.markdown.marked; | ||
|
||
import static org.eclipse.tm4e.markdown.marked.Helpers.escape; | ||
|
||
public class HTMLRenderer implements IRenderer { | ||
|
||
private final StringBuilder html; | ||
|
||
public HTMLRenderer() { | ||
this.html = new StringBuilder(); | ||
} | ||
|
||
@Override | ||
public void code(String code, String lang, boolean escaped) { | ||
if (lang == null) { | ||
html.append("<pre><code>"); | ||
html.append(escaped ? code : escape(code, true)); | ||
html.append("\n</code></pre>"); | ||
} else { | ||
html.append("<pre><code>"); | ||
html.append(escaped ? code : escape(code, true)); | ||
html.append("\n</code></pre>"); | ||
} | ||
} | ||
|
||
@Override | ||
public void blockquote(String quote) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public void html(String html) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public void heading(String text, int level, String raw) { | ||
html.append("<h"); | ||
html.append(level); | ||
html.append(" id=\""); | ||
html.append("\">"); | ||
html.append(text); | ||
html.append("</h"); | ||
html.append(level); | ||
html.append(">\n"); | ||
} | ||
|
||
@Override | ||
public void hr() { | ||
html.append("<hr />\n"); | ||
} | ||
|
||
@Override | ||
public void list(String body, boolean ordered) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public void listitem(String text) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public void startParagraph() { | ||
html.append("<p>"); | ||
} | ||
|
||
@Override | ||
public void endParagraph() { | ||
html.append("</p>\n"); | ||
} | ||
|
||
@Override | ||
public void table(String header, String body) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public void tablerow(String content) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public void tablecell(String content, String flags) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public void startEm() { | ||
html.append("<em>"); | ||
} | ||
|
||
@Override | ||
public void endEm() { | ||
html.append("</em>"); | ||
} | ||
|
||
@Override | ||
public void startStrong() { | ||
html.append("<strong>"); | ||
} | ||
|
||
@Override | ||
public void endStrong() { | ||
html.append("</strong>"); | ||
} | ||
|
||
@Override | ||
public void codespan(String text) { | ||
html.append("<code>"); | ||
html.append(text); | ||
html.append("</code>"); | ||
} | ||
|
||
@Override | ||
public void br() { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public void del(String text) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public void link(String href, String title, String text) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public void image(String href, String title, String text) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public void text(String text) { | ||
html.append(text); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return html.toString(); | ||
} | ||
} |
Oops, something went wrong.