mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
Revert "fix: Cleanup unused Markdown4j Parser"
This reverts commit e9fb0df57b7b5b3737b467c7c0d9ab3de852f5e8.
This commit is contained in:
parent
33fb800bf3
commit
9268695ea0
9 changed files with 388 additions and 245 deletions
|
|
@ -33,27 +33,57 @@ import org.apache.zeppelin.scheduler.SchedulerFactory;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* MarkdownInterpreter interpreter for Zeppelin.
|
||||
*/
|
||||
/** MarkdownInterpreter interpreter for Zeppelin. */
|
||||
public class Markdown extends Interpreter {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Markdown.class);
|
||||
|
||||
private PegdownParser parser;
|
||||
private MarkdownParser parser;
|
||||
|
||||
/** Markdown Parser Type. */
|
||||
public enum MarkdownParserType {
|
||||
PEGDOWN {
|
||||
@Override
|
||||
public String toString() {
|
||||
return PARSER_TYPE_PEGDOWN;
|
||||
}
|
||||
},
|
||||
|
||||
MARKDOWN4j {
|
||||
@Override
|
||||
public String toString() {
|
||||
return PARSER_TYPE_MARKDOWN4J;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final String MARKDOWN_PARSER_TYPE = "markdown.parser.type";
|
||||
public static final String PARSER_TYPE_PEGDOWN = "pegdown";
|
||||
public static final String PARSER_TYPE_MARKDOWN4J = "markdown4j";
|
||||
|
||||
public Markdown(Properties property) {
|
||||
super(property);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
parser = new PegdownParser();
|
||||
public static MarkdownParser createMarkdownParser(String parserType) {
|
||||
LOGGER.debug("Creating " + parserType + " markdown interpreter");
|
||||
|
||||
if (MarkdownParserType.PEGDOWN.toString().equals(parserType)) {
|
||||
return new PegdownParser();
|
||||
} else {
|
||||
/** default parser. */
|
||||
return new Markdown4jParser();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
public void open() {
|
||||
String parserType = getProperty(MARKDOWN_PARSER_TYPE);
|
||||
parser = createMarkdownParser(parserType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {}
|
||||
|
||||
@Override
|
||||
public InterpreterResult interpret(String markdownText, InterpreterContext interpreterContext) {
|
||||
String html;
|
||||
|
|
@ -69,8 +99,7 @@ public class Markdown extends Interpreter {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void cancel(InterpreterContext context) {
|
||||
}
|
||||
public void cancel(InterpreterContext context) {}
|
||||
|
||||
@Override
|
||||
public FormType getFormType() {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.zeppelin.markdown;
|
||||
|
||||
import org.markdown4j.Markdown4jProcessor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/** Markdown Parser using markdown4j processor . */
|
||||
public class Markdown4jParser implements MarkdownParser {
|
||||
private Markdown4jProcessor processor;
|
||||
|
||||
public Markdown4jParser() {
|
||||
processor = new Markdown4jProcessor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String render(String markdownText) {
|
||||
String html = "";
|
||||
|
||||
try {
|
||||
html = processor.process(markdownText);
|
||||
} catch (IOException e) {
|
||||
// convert checked exception to non-checked exception
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return html;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.zeppelin.markdown;
|
||||
|
||||
/** Abstract Markdown Parser. */
|
||||
public interface MarkdownParser {
|
||||
String render(String markdownText);
|
||||
}
|
||||
|
|
@ -23,10 +23,7 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Implementation of Var to support parameter parsing.
|
||||
*
|
||||
* @param <K> Key type
|
||||
* @param <V> Value type
|
||||
* Implementation of Var to support parameter parsing
|
||||
*/
|
||||
public class ParamVar<K, V> extends Var<Map<K, V>> {
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import org.pegdown.plugins.PegDownPlugins;
|
|||
/**
|
||||
* Markdown Parser using pegdown processor.
|
||||
*/
|
||||
public class PegdownParser {
|
||||
public class PegdownParser implements MarkdownParser {
|
||||
private PegDownProcessor processor;
|
||||
|
||||
public static final long PARSING_TIMEOUT_AS_MILLIS = 5000;
|
||||
|
|
@ -32,12 +32,13 @@ public class PegdownParser {
|
|||
|
||||
public PegdownParser() {
|
||||
PegDownPlugins plugins = new PegDownPlugins.Builder()
|
||||
.withPlugin(PegdownYumlPlugin.class)
|
||||
.withPlugin(PegdownWebSequencelPlugin.class)
|
||||
.build();
|
||||
.withPlugin(PegdownYumlPlugin.class)
|
||||
.withPlugin(PegdownWebSequencelPlugin.class)
|
||||
.build();
|
||||
processor = new PegDownProcessor(OPTIONS, PARSING_TIMEOUT_AS_MILLIS, plugins);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String render(String markdownText) {
|
||||
String html = "";
|
||||
String parsed = processor.markdownToHtml(markdownText);
|
||||
|
|
@ -55,9 +56,9 @@ public class PegdownParser {
|
|||
*/
|
||||
public static String wrapWithMarkdownClassDiv(String html) {
|
||||
return new StringBuilder()
|
||||
.append("<div class=\"markdown-body\">\n")
|
||||
.append(html)
|
||||
.append("\n</div>")
|
||||
.toString();
|
||||
.append("<div class=\"markdown-body\">\n")
|
||||
.append(html)
|
||||
.append("\n</div>")
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,14 +38,14 @@ import java.net.URLEncoder;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* Pegdown plugin for Websequence diagram.
|
||||
* Pegdown plugin for Websequence diagram
|
||||
*/
|
||||
public class PegdownWebSequencelPlugin extends Parser implements BlockPluginParser {
|
||||
|
||||
public PegdownWebSequencelPlugin() {
|
||||
super(PegdownParser.OPTIONS,
|
||||
PegdownParser.PARSING_TIMEOUT_AS_MILLIS,
|
||||
DefaultParseRunnerProvider);
|
||||
PegdownParser.PARSING_TIMEOUT_AS_MILLIS,
|
||||
DefaultParseRunnerProvider);
|
||||
}
|
||||
|
||||
public PegdownWebSequencelPlugin(Integer options,
|
||||
|
|
@ -57,32 +57,34 @@ public class PegdownWebSequencelPlugin extends Parser implements BlockPluginPars
|
|||
|
||||
public static final String TAG = "%%%";
|
||||
|
||||
Rule startMarker() {
|
||||
Rule StartMarker() {
|
||||
return Sequence(Spn1(), TAG, Sp(), "sequence", Sp());
|
||||
}
|
||||
|
||||
String endMarker() {
|
||||
String EndMarker() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
Rule body() {
|
||||
Rule Body() {
|
||||
return OneOrMore(TestNot(TAG), BaseParser.ANY);
|
||||
}
|
||||
|
||||
Rule block() {
|
||||
Rule BlockRule() {
|
||||
StringBuilderVar style = new StringBuilderVar();
|
||||
StringBuilderVar body = new StringBuilderVar();
|
||||
|
||||
return NodeSequence(
|
||||
startMarker(),
|
||||
String("style="),
|
||||
Sequence(OneOrMore(Letter()), style.append(match()), Spn1()),
|
||||
Sequence(body(), body.append(match())),
|
||||
endMarker(),
|
||||
push(
|
||||
new ExpImageNode("title",
|
||||
createWebsequenceUrl(style.getString(), body.getString()),
|
||||
new TextNode(""))));
|
||||
StartMarker(),
|
||||
String("style="),
|
||||
Sequence(OneOrMore(Letter()), style.append(match()), Spn1()),
|
||||
Sequence(Body(), body.append(match())),
|
||||
EndMarker(),
|
||||
push(
|
||||
new ExpImageNode("title",
|
||||
createWebsequenceUrl(style.getString(), body.getString()),
|
||||
new TextNode(""))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static String createWebsequenceUrl(String style,
|
||||
|
|
@ -95,12 +97,12 @@ public class PegdownWebSequencelPlugin extends Parser implements BlockPluginPars
|
|||
|
||||
try {
|
||||
String query = new StringBuilder()
|
||||
.append("style=")
|
||||
.append(style)
|
||||
.append("&message=")
|
||||
.append(URLEncoder.encode(content, "UTF-8"))
|
||||
.append("&apiVersion=1")
|
||||
.toString();
|
||||
.append("style=")
|
||||
.append(style)
|
||||
.append("&message=")
|
||||
.append(URLEncoder.encode(content, "UTF-8"))
|
||||
.append("&apiVersion=1")
|
||||
.toString();
|
||||
|
||||
URL url = new URL("http://www.websequencediagrams.com");
|
||||
URLConnection conn = url.openConnection();
|
||||
|
|
@ -110,9 +112,7 @@ public class PegdownWebSequencelPlugin extends Parser implements BlockPluginPars
|
|||
writer.flush();
|
||||
|
||||
StringBuilder response = new StringBuilder();
|
||||
reader =
|
||||
new BufferedReader(
|
||||
new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
|
||||
reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
response.append(line);
|
||||
|
|
@ -141,6 +141,6 @@ public class PegdownWebSequencelPlugin extends Parser implements BlockPluginPars
|
|||
|
||||
@Override
|
||||
public Rule[] blockPluginRules() {
|
||||
return new Rule[]{block()};
|
||||
return new Rule[]{BlockRule()};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,14 +33,14 @@ import java.net.URLEncoder;
|
|||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Pegdown plugin for YUML.
|
||||
* Pegdown plugin for YUML
|
||||
*/
|
||||
public class PegdownYumlPlugin extends Parser implements BlockPluginParser {
|
||||
|
||||
public PegdownYumlPlugin() {
|
||||
super(PegdownParser.OPTIONS,
|
||||
PegdownParser.PARSING_TIMEOUT_AS_MILLIS,
|
||||
DefaultParseRunnerProvider);
|
||||
PegdownParser.PARSING_TIMEOUT_AS_MILLIS,
|
||||
DefaultParseRunnerProvider);
|
||||
}
|
||||
|
||||
public PegdownYumlPlugin(Integer options,
|
||||
|
|
@ -52,45 +52,44 @@ public class PegdownYumlPlugin extends Parser implements BlockPluginParser {
|
|||
|
||||
public static final String TAG = "%%%";
|
||||
|
||||
Rule startMarker() {
|
||||
Rule StartMarker() {
|
||||
return Sequence(Spn1(), TAG, Sp(), "yuml", Sp());
|
||||
}
|
||||
|
||||
String endMarker() {
|
||||
String EndMarker() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
Rule parameterName() {
|
||||
Rule ParameterName() {
|
||||
return FirstOf("type", "style", "scale", "format", "dir");
|
||||
}
|
||||
|
||||
Rule body() {
|
||||
Rule Body() {
|
||||
return OneOrMore(TestNot(TAG), BaseParser.ANY);
|
||||
}
|
||||
|
||||
Rule block() {
|
||||
Rule BlockRule() {
|
||||
ParamVar<String, String> params = new ParamVar<String, String>();
|
||||
StringBuilderVar name = new StringBuilderVar();
|
||||
StringBuilderVar value = new StringBuilderVar();
|
||||
StringBuilderVar body = new StringBuilderVar();
|
||||
|
||||
return NodeSequence(
|
||||
startMarker(),
|
||||
ZeroOrMore(
|
||||
Sequence(
|
||||
parameterName(), name.append(match()),
|
||||
String("="),
|
||||
OneOrMore(Alphanumeric()), value.append(match())),
|
||||
Sp(),
|
||||
params.put(name.getString(), value.getString()),
|
||||
name.clear(), value.clear())
|
||||
, body(), body.append(match())
|
||||
, endMarker()
|
||||
, push(
|
||||
new ExpImageNode(
|
||||
"title",
|
||||
createYumlUrl(params.get(), body.getString()),
|
||||
new TextNode(""))));
|
||||
StartMarker(),
|
||||
ZeroOrMore(
|
||||
Sequence(
|
||||
ParameterName(), name.append(match()),
|
||||
String("="),
|
||||
OneOrMore(Alphanumeric()), value.append(match())
|
||||
),
|
||||
Sp(),
|
||||
params.put(name.getString(), value.getString()),
|
||||
name.clear(), value.clear()
|
||||
)
|
||||
, Body(), body.append(match())
|
||||
, EndMarker()
|
||||
, push(new ExpImageNode("title", createYumlUrl(params.get(), body.getString()), new TextNode("")))
|
||||
);
|
||||
}
|
||||
|
||||
public static String createYumlUrl(Map<String, String> params, String body) {
|
||||
|
|
@ -119,25 +118,23 @@ public class PegdownYumlPlugin extends Parser implements BlockPluginParser {
|
|||
|
||||
mergedStyle.append(style);
|
||||
|
||||
if (null != params.get("dir")) {
|
||||
if (null != params.get("dir"))
|
||||
mergedStyle.append(";dir:" + params.get("dir"));
|
||||
}
|
||||
|
||||
if (null != params.get("scale")) {
|
||||
if (null != params.get("scale"))
|
||||
mergedStyle.append(";scale:" + params.get("scale"));
|
||||
}
|
||||
|
||||
return new StringBuilder()
|
||||
.append("http://yuml.me/diagram/")
|
||||
.append(mergedStyle.toString() + "/")
|
||||
.append(type + "/")
|
||||
.append(encodedBody)
|
||||
.append("." + format)
|
||||
.toString();
|
||||
.append("http://yuml.me/diagram/")
|
||||
.append(mergedStyle.toString() + "/")
|
||||
.append(type + "/")
|
||||
.append(encodedBody)
|
||||
.append("." + format)
|
||||
.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rule[] blockPluginRules() {
|
||||
return new Rule[]{block()};
|
||||
return new Rule[]{BlockRule()};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.zeppelin.markdown;
|
||||
|
||||
import org.apache.zeppelin.interpreter.InterpreterResult;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class Markdown4jParserTest {
|
||||
|
||||
Markdown md;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
Properties props = new Properties();
|
||||
props.put(Markdown.MARKDOWN_PARSER_TYPE, Markdown.PARSER_TYPE_MARKDOWN4J);
|
||||
md = new Markdown(props);
|
||||
md.open();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
md.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStrikethrough() {
|
||||
InterpreterResult result = md.interpret("This is ~~deleted~~ text", null);
|
||||
assertEquals("<p>This is <s>deleted</s> text</p>\n", result.message());
|
||||
}
|
||||
}
|
||||
|
|
@ -32,9 +32,6 @@ import org.junit.Assert;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test for PegdownParser.
|
||||
*/
|
||||
public class PegdownParserTest {
|
||||
|
||||
Markdown md;
|
||||
|
|
@ -42,6 +39,7 @@ public class PegdownParserTest {
|
|||
@Before
|
||||
public void setUp() throws Exception {
|
||||
Properties props = new Properties();
|
||||
props.put(Markdown.MARKDOWN_PARSER_TYPE, Markdown.PARSER_TYPE_PEGDOWN);
|
||||
md = new Markdown(props);
|
||||
md.open();
|
||||
}
|
||||
|
|
@ -82,39 +80,39 @@ public class PegdownParserTest {
|
|||
public void testStrikethrough() {
|
||||
InterpreterResult result = md.interpret("This is ~~deleted~~ text", null);
|
||||
assertEquals(
|
||||
wrapWithMarkdownClassDiv("<p>This is <del>deleted</del> text</p>"), result.message());
|
||||
wrapWithMarkdownClassDiv("<p>This is <del>deleted</del> text</p>"), result.message());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testItalics() {
|
||||
InterpreterResult result = md.interpret("This is *italics* text", null);
|
||||
assertEquals(
|
||||
wrapWithMarkdownClassDiv("<p>This is <em>italics</em> text</p>"), result.message());
|
||||
wrapWithMarkdownClassDiv("<p>This is <em>italics</em> text</p>"), result.message());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStrongEmphasis() {
|
||||
InterpreterResult result = md.interpret("This is **strong emphasis** text", null);
|
||||
assertEquals(
|
||||
wrapWithMarkdownClassDiv("<p>This is <strong>strong emphasis</strong> text</p>"),
|
||||
result.message());
|
||||
wrapWithMarkdownClassDiv("<p>This is <strong>strong emphasis</strong> text</p>"),
|
||||
result.message());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderedList() {
|
||||
String input =
|
||||
new StringBuilder()
|
||||
.append("1. First ordered list item\n")
|
||||
.append("2. Another item")
|
||||
.toString();
|
||||
new StringBuilder()
|
||||
.append("1. First ordered list item\n")
|
||||
.append("2. Another item")
|
||||
.toString();
|
||||
|
||||
String expected =
|
||||
new StringBuilder()
|
||||
.append("<ol>\n")
|
||||
.append(" <li>First ordered list item</li>\n")
|
||||
.append(" <li>Another item</li>\n")
|
||||
.append("</ol>")
|
||||
.toString();
|
||||
new StringBuilder()
|
||||
.append("<ol>\n")
|
||||
.append(" <li>First ordered list item</li>\n")
|
||||
.append(" <li>Another item</li>\n")
|
||||
.append("</ol>")
|
||||
.toString();
|
||||
|
||||
InterpreterResult result = md.interpret(input, null);
|
||||
assertEquals(wrapWithMarkdownClassDiv(expected), result.message());
|
||||
|
|
@ -123,20 +121,20 @@ public class PegdownParserTest {
|
|||
@Test
|
||||
public void testUnorderedList() {
|
||||
String input =
|
||||
new StringBuilder()
|
||||
.append("* Unordered list can use asterisks\n")
|
||||
.append("- Or minuses\n")
|
||||
.append("+ Or pluses")
|
||||
.toString();
|
||||
new StringBuilder()
|
||||
.append("* Unordered list can use asterisks\n")
|
||||
.append("- Or minuses\n")
|
||||
.append("+ Or pluses")
|
||||
.toString();
|
||||
|
||||
String expected =
|
||||
new StringBuilder()
|
||||
.append("<ul>\n")
|
||||
.append(" <li>Unordered list can use asterisks</li>\n")
|
||||
.append(" <li>Or minuses</li>\n")
|
||||
.append(" <li>Or pluses</li>\n")
|
||||
.append("</ul>")
|
||||
.toString();
|
||||
new StringBuilder()
|
||||
.append("<ul>\n")
|
||||
.append(" <li>Unordered list can use asterisks</li>\n")
|
||||
.append(" <li>Or minuses</li>\n")
|
||||
.append(" <li>Or pluses</li>\n")
|
||||
.append("</ul>")
|
||||
.toString();
|
||||
|
||||
InterpreterResult result = md.interpret(input, null);
|
||||
assertEquals(wrapWithMarkdownClassDiv(expected), result.message());
|
||||
|
|
@ -145,49 +143,49 @@ public class PegdownParserTest {
|
|||
@Test
|
||||
public void testLinks() {
|
||||
String input =
|
||||
new StringBuilder()
|
||||
.append("[I'm an inline-style link](https://www.google.com)\n")
|
||||
.append("\n")
|
||||
.append(
|
||||
"[I'm an inline-style link with title](https://www.google.com \"Google's Homepage\")\n")
|
||||
.append("\n")
|
||||
.append("[I'm a reference-style link][Arbitrary case-insensitive reference text]\n")
|
||||
.append("\n")
|
||||
.append("[I'm a relative reference to a repository file](../blob/master/LICENSE)\n")
|
||||
.append("\n")
|
||||
.append("[You can use numbers for reference-style link definitions][1]\n")
|
||||
.append("\n")
|
||||
.append("Or leave it empty and use the [link text itself].\n")
|
||||
.append("\n")
|
||||
.append("URLs and URLs in angle brackets will automatically get turned into links. \n")
|
||||
.append("http://www.example.com or <http://www.example.com> and sometimes \n")
|
||||
.append("example.com (but not on Github, for example).\n")
|
||||
.append("\n")
|
||||
.append("Some text to show that the reference links can follow later.\n")
|
||||
.append("\n")
|
||||
.append("[arbitrary case-insensitive reference text]: https://www.mozilla.org\n")
|
||||
.append("[1]: http://slashdot.org\n")
|
||||
.append("[link text itself]: http://www.reddit.com")
|
||||
.toString();
|
||||
new StringBuilder()
|
||||
.append("[I'm an inline-style link](https://www.google.com)\n")
|
||||
.append("\n")
|
||||
.append(
|
||||
"[I'm an inline-style link with title](https://www.google.com \"Google's Homepage\")\n")
|
||||
.append("\n")
|
||||
.append("[I'm a reference-style link][Arbitrary case-insensitive reference text]\n")
|
||||
.append("\n")
|
||||
.append("[I'm a relative reference to a repository file](../blob/master/LICENSE)\n")
|
||||
.append("\n")
|
||||
.append("[You can use numbers for reference-style link definitions][1]\n")
|
||||
.append("\n")
|
||||
.append("Or leave it empty and use the [link text itself].\n")
|
||||
.append("\n")
|
||||
.append("URLs and URLs in angle brackets will automatically get turned into links. \n")
|
||||
.append("http://www.example.com or <http://www.example.com> and sometimes \n")
|
||||
.append("example.com (but not on Github, for example).\n")
|
||||
.append("\n")
|
||||
.append("Some text to show that the reference links can follow later.\n")
|
||||
.append("\n")
|
||||
.append("[arbitrary case-insensitive reference text]: https://www.mozilla.org\n")
|
||||
.append("[1]: http://slashdot.org\n")
|
||||
.append("[link text itself]: http://www.reddit.com")
|
||||
.toString();
|
||||
|
||||
String expected =
|
||||
new StringBuilder()
|
||||
.append(
|
||||
"<p><a href=\"https://www.google.com\">I’m an inline-style link</a></p>\n")
|
||||
.append(
|
||||
"<p><a href=\"https://www.google.com\" title=\"Google's Homepage\">I’m an inline-style link with title</a></p>\n")
|
||||
.append(
|
||||
"<p><a href=\"https://www.mozilla.org\">I’m a reference-style link</a></p>\n")
|
||||
.append(
|
||||
"<p><a href=\"../blob/master/LICENSE\">I’m a relative reference to a repository file</a></p>\n")
|
||||
.append(
|
||||
"<p><a href=\"http://slashdot.org\">You can use numbers for reference-style link definitions</a></p>\n")
|
||||
.append(
|
||||
"<p>Or leave it empty and use the <a href=\"http://www.reddit.com\">link text itself</a>.</p>\n")
|
||||
.append(
|
||||
"<p>URLs and URLs in angle brackets will automatically get turned into links.<br/><a href=\"http://www.example.com\">http://www.example.com</a> or <a href=\"http://www.example.com\">http://www.example.com</a> and sometimes<br/>example.com (but not on Github, for example).</p>\n")
|
||||
.append("<p>Some text to show that the reference links can follow later.</p>")
|
||||
.toString();
|
||||
new StringBuilder()
|
||||
.append(
|
||||
"<p><a href=\"https://www.google.com\">I’m an inline-style link</a></p>\n")
|
||||
.append(
|
||||
"<p><a href=\"https://www.google.com\" title=\"Google's Homepage\">I’m an inline-style link with title</a></p>\n")
|
||||
.append(
|
||||
"<p><a href=\"https://www.mozilla.org\">I’m a reference-style link</a></p>\n")
|
||||
.append(
|
||||
"<p><a href=\"../blob/master/LICENSE\">I’m a relative reference to a repository file</a></p>\n")
|
||||
.append(
|
||||
"<p><a href=\"http://slashdot.org\">You can use numbers for reference-style link definitions</a></p>\n")
|
||||
.append(
|
||||
"<p>Or leave it empty and use the <a href=\"http://www.reddit.com\">link text itself</a>.</p>\n")
|
||||
.append(
|
||||
"<p>URLs and URLs in angle brackets will automatically get turned into links.<br/><a href=\"http://www.example.com\">http://www.example.com</a> or <a href=\"http://www.example.com\">http://www.example.com</a> and sometimes<br/>example.com (but not on Github, for example).</p>\n")
|
||||
.append("<p>Some text to show that the reference links can follow later.</p>")
|
||||
.toString();
|
||||
|
||||
InterpreterResult result = md.interpret(input, null);
|
||||
assertEquals(wrapWithMarkdownClassDiv(expected), result.message());
|
||||
|
|
@ -197,71 +195,71 @@ public class PegdownParserTest {
|
|||
public void testInlineCode() {
|
||||
InterpreterResult result = md.interpret("Inline `code` has `back-ticks around` it.", null);
|
||||
assertEquals(
|
||||
wrapWithMarkdownClassDiv(
|
||||
"<p>Inline <code>code</code> has <code>back-ticks around</code> it.</p>"),
|
||||
result.message());
|
||||
wrapWithMarkdownClassDiv(
|
||||
"<p>Inline <code>code</code> has <code>back-ticks around</code> it.</p>"),
|
||||
result.message());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBlockQuotes() {
|
||||
InterpreterResult r1 =
|
||||
md.interpret(
|
||||
"> Blockquotes are very handy in email to emulate reply text.\n"
|
||||
+ "> This line is part of the same quote.",
|
||||
null);
|
||||
md.interpret(
|
||||
"> Blockquotes are very handy in email to emulate reply text.\n"
|
||||
+ "> This line is part of the same quote.",
|
||||
null);
|
||||
assertEquals(
|
||||
wrapWithMarkdownClassDiv(
|
||||
"<blockquote>\n"
|
||||
+ " <p>Blockquotes are very handy in email to emulate reply text.<br/>This line is part of the same quote.</p>\n"
|
||||
+ "</blockquote>"),
|
||||
r1.message());
|
||||
wrapWithMarkdownClassDiv(
|
||||
"<blockquote>\n"
|
||||
+ " <p>Blockquotes are very handy in email to emulate reply text.<br/>This line is part of the same quote.</p>\n"
|
||||
+ "</blockquote>"),
|
||||
r1.message());
|
||||
|
||||
InterpreterResult r2 =
|
||||
md.interpret(
|
||||
"> This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can *put* **MarkdownInterpreter** into a blockquote. ",
|
||||
null);
|
||||
md.interpret(
|
||||
"> This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can *put* **MarkdownInterpreter** into a blockquote. ",
|
||||
null);
|
||||
assertEquals(
|
||||
wrapWithMarkdownClassDiv(
|
||||
"<blockquote>\n"
|
||||
+ " <p>This is a very long line that will still be quoted properly when it wraps. Oh boy let’s keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can <em>put</em> <strong>MarkdownInterpreter</strong> into a blockquote. </p>\n"
|
||||
+ "</blockquote>"),
|
||||
r2.message());
|
||||
wrapWithMarkdownClassDiv(
|
||||
"<blockquote>\n"
|
||||
+ " <p>This is a very long line that will still be quoted properly when it wraps. Oh boy let’s keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can <em>put</em> <strong>MarkdownInterpreter</strong> into a blockquote. </p>\n"
|
||||
+ "</blockquote>"),
|
||||
r2.message());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleTable() {
|
||||
String input =
|
||||
new StringBuilder()
|
||||
.append("MarkdownInterpreter | Less | Pretty\n")
|
||||
.append("--- | --- | ---\n")
|
||||
.append("*Still* | `renders` | **nicely**\n")
|
||||
.append("1 | 2 | 3")
|
||||
.toString();
|
||||
new StringBuilder()
|
||||
.append("MarkdownInterpreter | Less | Pretty\n")
|
||||
.append("--- | --- | ---\n")
|
||||
.append("*Still* | `renders` | **nicely**\n")
|
||||
.append("1 | 2 | 3")
|
||||
.toString();
|
||||
|
||||
String expected =
|
||||
new StringBuilder()
|
||||
.append("<table>\n")
|
||||
.append(" <thead>\n")
|
||||
.append(" <tr>\n")
|
||||
.append(" <th>MarkdownInterpreter </th>\n")
|
||||
.append(" <th>Less </th>\n")
|
||||
.append(" <th>Pretty</th>\n")
|
||||
.append(" </tr>\n")
|
||||
.append(" </thead>\n")
|
||||
.append(" <tbody>\n")
|
||||
.append(" <tr>\n")
|
||||
.append(" <td><em>Still</em> </td>\n")
|
||||
.append(" <td><code>renders</code> </td>\n")
|
||||
.append(" <td><strong>nicely</strong></td>\n")
|
||||
.append(" </tr>\n")
|
||||
.append(" <tr>\n")
|
||||
.append(" <td>1 </td>\n")
|
||||
.append(" <td>2 </td>\n")
|
||||
.append(" <td>3</td>\n")
|
||||
.append(" </tr>\n")
|
||||
.append(" </tbody>\n")
|
||||
.append("</table>")
|
||||
.toString();
|
||||
new StringBuilder()
|
||||
.append("<table>\n")
|
||||
.append(" <thead>\n")
|
||||
.append(" <tr>\n")
|
||||
.append(" <th>MarkdownInterpreter </th>\n")
|
||||
.append(" <th>Less </th>\n")
|
||||
.append(" <th>Pretty</th>\n")
|
||||
.append(" </tr>\n")
|
||||
.append(" </thead>\n")
|
||||
.append(" <tbody>\n")
|
||||
.append(" <tr>\n")
|
||||
.append(" <td><em>Still</em> </td>\n")
|
||||
.append(" <td><code>renders</code> </td>\n")
|
||||
.append(" <td><strong>nicely</strong></td>\n")
|
||||
.append(" </tr>\n")
|
||||
.append(" <tr>\n")
|
||||
.append(" <td>1 </td>\n")
|
||||
.append(" <td>2 </td>\n")
|
||||
.append(" <td>3</td>\n")
|
||||
.append(" </tr>\n")
|
||||
.append(" </tbody>\n")
|
||||
.append("</table>")
|
||||
.toString();
|
||||
|
||||
InterpreterResult result = md.interpret(input, null);
|
||||
assertEquals(wrapWithMarkdownClassDiv(expected), result.message());
|
||||
|
|
@ -270,37 +268,37 @@ public class PegdownParserTest {
|
|||
@Test
|
||||
public void testAlignedTable() {
|
||||
String input =
|
||||
new StringBuilder()
|
||||
.append("| First Header | Second Header | Third Header |\n")
|
||||
.append("| :----------- | :-----------: | -------------------: |\n")
|
||||
.append("| First row | Data | Very long data entry |\n")
|
||||
.append("| Second row | **Cell** | *Cell* |")
|
||||
.toString();
|
||||
new StringBuilder()
|
||||
.append("| First Header | Second Header | Third Header |\n")
|
||||
.append("| :----------- | :-----------: | -------------------: |\n")
|
||||
.append("| First row | Data | Very long data entry |\n")
|
||||
.append("| Second row | **Cell** | *Cell* |")
|
||||
.toString();
|
||||
|
||||
String expected =
|
||||
new StringBuilder()
|
||||
.append("<table>\n")
|
||||
.append(" <thead>\n")
|
||||
.append(" <tr>\n")
|
||||
.append(" <th align=\"left\">First Header </th>\n")
|
||||
.append(" <th align=\"center\">Second Header </th>\n")
|
||||
.append(" <th align=\"right\">Third Header </th>\n")
|
||||
.append(" </tr>\n")
|
||||
.append(" </thead>\n")
|
||||
.append(" <tbody>\n")
|
||||
.append(" <tr>\n")
|
||||
.append(" <td align=\"left\">First row </td>\n")
|
||||
.append(" <td align=\"center\">Data </td>\n")
|
||||
.append(" <td align=\"right\">Very long data entry </td>\n")
|
||||
.append(" </tr>\n")
|
||||
.append(" <tr>\n")
|
||||
.append(" <td align=\"left\">Second row </td>\n")
|
||||
.append(" <td align=\"center\"><strong>Cell</strong> </td>\n")
|
||||
.append(" <td align=\"right\"><em>Cell</em> </td>\n")
|
||||
.append(" </tr>\n")
|
||||
.append(" </tbody>\n")
|
||||
.append("</table>")
|
||||
.toString();
|
||||
new StringBuilder()
|
||||
.append("<table>\n")
|
||||
.append(" <thead>\n")
|
||||
.append(" <tr>\n")
|
||||
.append(" <th align=\"left\">First Header </th>\n")
|
||||
.append(" <th align=\"center\">Second Header </th>\n")
|
||||
.append(" <th align=\"right\">Third Header </th>\n")
|
||||
.append(" </tr>\n")
|
||||
.append(" </thead>\n")
|
||||
.append(" <tbody>\n")
|
||||
.append(" <tr>\n")
|
||||
.append(" <td align=\"left\">First row </td>\n")
|
||||
.append(" <td align=\"center\">Data </td>\n")
|
||||
.append(" <td align=\"right\">Very long data entry </td>\n")
|
||||
.append(" </tr>\n")
|
||||
.append(" <tr>\n")
|
||||
.append(" <td align=\"left\">Second row </td>\n")
|
||||
.append(" <td align=\"center\"><strong>Cell</strong> </td>\n")
|
||||
.append(" <td align=\"right\"><em>Cell</em> </td>\n")
|
||||
.append(" </tr>\n")
|
||||
.append(" </tbody>\n")
|
||||
.append("</table>")
|
||||
.toString();
|
||||
|
||||
InterpreterResult result = md.interpret(input, null);
|
||||
assertEquals(wrapWithMarkdownClassDiv(expected), result.message());
|
||||
|
|
@ -309,14 +307,14 @@ public class PegdownParserTest {
|
|||
@Test
|
||||
public void testWebsequencePlugin() {
|
||||
String input =
|
||||
new StringBuilder()
|
||||
.append("\n \n %%% sequence style=modern-blue\n")
|
||||
.append("title Authentication Sequence\n")
|
||||
.append("Alice->Bob: Authentication Request\n")
|
||||
.append("note right of Bob: Bob thinks about it\n")
|
||||
.append("Bob->Alice: Authentication Response\n")
|
||||
.append(" %%% ")
|
||||
.toString();
|
||||
new StringBuilder()
|
||||
.append("\n \n %%% sequence style=modern-blue\n")
|
||||
.append("title Authentication Sequence\n")
|
||||
.append("Alice->Bob: Authentication Request\n")
|
||||
.append("note right of Bob: Bob thinks about it\n")
|
||||
.append("Bob->Alice: Authentication Response\n")
|
||||
.append(" %%% ")
|
||||
.toString();
|
||||
|
||||
InterpreterResult result = md.interpret(input, null);
|
||||
assertThat(result.message(), CoreMatchers.containsString("<img src=\"http://www.websequencediagrams.com/?png="));
|
||||
|
|
@ -325,12 +323,12 @@ public class PegdownParserTest {
|
|||
@Test
|
||||
public void testYumlPlugin() {
|
||||
String input = new StringBuilder()
|
||||
.append("\n \n %%% yuml style=nofunky scale=120 format=svg\n")
|
||||
.append("[Customer]<>-orders>[Order]\n")
|
||||
.append("[Order]++-0..>[LineItem]\n")
|
||||
.append("[Order]-[note:Aggregate root.]\n")
|
||||
.append(" %%% ")
|
||||
.toString();
|
||||
.append("\n \n %%% yuml style=nofunky scale=120 format=svg\n")
|
||||
.append("[Customer]<>-orders>[Order]\n")
|
||||
.append("[Order]++-0..>[LineItem]\n")
|
||||
.append("[Order]-[note:Aggregate root.]\n")
|
||||
.append(" %%% ")
|
||||
.toString();
|
||||
|
||||
InterpreterResult result = md.interpret(input, null);
|
||||
assertThat(result.message(), CoreMatchers.containsString("<img src=\"http://yuml.me/diagram/"));
|
||||
|
|
|
|||
Loading…
Reference in a new issue