forked from raysteam/zeppelin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ZEPPELIN-1614] Remove markdown4j dep
### What is this PR for? Remove unmanaged, old library markdown4j dep which exists just for Websequence and YUML plugins. (related to apache#1384) By adding Websequence and YUML plugins to pegdown - Removing markdown4j dependency which is unmanaged library currently. - Addtionally, we can remove `markdown.parser.type` options in **markdown interpreter** - Fixing some bugs in Websequence and YUML plugins - Enable others to add more plugins using pegdown sytnax. ### What type of PR is it? Improvement ### Todos Nothing ### What is the Jira issue? [JIRA - ZEPPELIN-1614](https://issues.apache.org/jira/browse/ZEPPELIN-1614) ### How should this be tested? Some functional tests are included. ### Screenshots (if appropriate) ### Questions: * Does the licenses files need update? - YES * Is there breaking changes for older versions? - NO * Does this needs documentation? - YES Author: 1ambda <[email protected]> Closes apache#1594 from 1ambda/feat/remove-markdown4j-dep and squashes the following commits: 5af1607 [1ambda] fix: Failed tests in InterpreterRestApiTest c57fdcb [1ambda] docs: Update markdown.md 5c62236 [1ambda] docs: Update upgrade.md for '%md' a1e779d [1ambda] style: Use zeppelin checkstyle.xml 13e0dc4 [1ambda] Update: interpreter setting and docs de3549d [1ambda] chore: Cleanup duplicated markdown4j license 7c5d41e [1ambda] fix: Parse style param optionally in webseq 8831ca1 [1ambda] fix: Wrap exceptions in catch stmt 9268695 [1ambda] Revert "fix: Cleanup unused Markdown4j Parser" 33fb800 [1ambda] Revert "docs: Remove markdown.parser.type option" fddc459 [1ambda] Revert "chore: Remove markdown4j dep and update license" a59ebbd [1ambda] Revert "fix: Set {} to avoid 503" 4e48933 [1ambda] Revert "fix: Parse style param optionally in webseq" 8cfb2c8 [1ambda] Revert "fix: style and misspell in docs" 73956e0 [1ambda] Revert "fix: Propagate exception in YUML plugin" 1b7787f [1ambda] fix: Propagate exception in YUML plugin c656d08 [1ambda] fix: style and misspell in docs dc4f110 [1ambda] fix: Parse style param optionally in webseq b43e14e [1ambda] fix: Set {} to avoid 503 c48cc53 [1ambda] chore: Remove markdown4j dep and update license 81fdfcc [1ambda] docs: Remove markdown.parser.type option cf19f0b [1ambda] fix: Cleanup unused Markdown4j Parser 98b2809 [1ambda] fix: Add missing docs 3e9716d [1ambda] feat: Yuml markdown plugin 3247c67 [1ambda] feat: Support webseq markdown plugin
- Loading branch information
Showing
16 changed files
with
436 additions
and
44 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
File renamed without changes
Binary file modified
BIN
+10.9 KB
(120%)
docs/assets/themes/zeppelin/img/docs-img/markdown-interpreter-setting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
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
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
41 changes: 41 additions & 0 deletions
41
markdown/src/main/java/org/apache/zeppelin/markdown/ParamVar.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,41 @@ | ||
/* | ||
* 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.parboiled.support.Var; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Implementation of Var to support parameter parsing. | ||
* | ||
* @param <K> Key | ||
* @param <V> Value | ||
*/ | ||
public class ParamVar<K, V> extends Var<Map<K, V>> { | ||
|
||
public ParamVar() { | ||
super(new HashMap<K, V>()); | ||
} | ||
|
||
public boolean put(K key, V value) { | ||
get().put(key, value); | ||
return true; | ||
} | ||
} |
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
149 changes: 149 additions & 0 deletions
149
markdown/src/main/java/org/apache/zeppelin/markdown/PegdownWebSequencelPlugin.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,149 @@ | ||
/* | ||
* 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.commons.io.IOUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.parboiled.BaseParser; | ||
import org.parboiled.Rule; | ||
import org.parboiled.support.StringBuilderVar; | ||
import org.pegdown.Parser; | ||
import org.pegdown.ast.ExpImageNode; | ||
import org.pegdown.ast.TextNode; | ||
import org.pegdown.plugins.BlockPluginParser; | ||
import org.pegdown.plugins.PegDownPlugins; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.io.OutputStreamWriter; | ||
import java.net.URL; | ||
import java.net.URLConnection; | ||
import java.net.URLEncoder; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
/** | ||
* Pegdown plugin for Websequence diagram | ||
*/ | ||
public class PegdownWebSequencelPlugin extends Parser implements BlockPluginParser { | ||
|
||
private static final String WEBSEQ_URL = "http://www.websequencediagrams.com"; | ||
|
||
public PegdownWebSequencelPlugin() { | ||
super(PegdownParser.OPTIONS, | ||
PegdownParser.PARSING_TIMEOUT_AS_MILLIS, | ||
DefaultParseRunnerProvider); | ||
} | ||
|
||
public PegdownWebSequencelPlugin(Integer opts, Long millis, ParseRunnerProvider provider, | ||
PegDownPlugins plugins) { | ||
super(opts, millis, provider, plugins); | ||
} | ||
|
||
public static final String TAG = "%%%"; | ||
|
||
Rule StartMarker() { | ||
return Sequence(Spn1(), TAG, Sp(), "sequence", Sp()); | ||
} | ||
|
||
String EndMarker() { | ||
return TAG; | ||
} | ||
|
||
Rule Body() { | ||
return OneOrMore(TestNot(TAG), BaseParser.ANY); | ||
} | ||
|
||
Rule BlockRule() { | ||
StringBuilderVar style = new StringBuilderVar(); | ||
StringBuilderVar body = new StringBuilderVar(); | ||
|
||
return NodeSequence( | ||
StartMarker(), | ||
Optional( | ||
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, | ||
String content) { | ||
|
||
style = StringUtils.defaultString(style, "default"); | ||
|
||
OutputStreamWriter writer = null; | ||
BufferedReader reader = null; | ||
|
||
String webSeqUrl = ""; | ||
|
||
try { | ||
String query = new StringBuilder() | ||
.append("style=") | ||
.append(style) | ||
.append("&message=") | ||
.append(URLEncoder.encode(content, "UTF-8")) | ||
.append("&apiVersion=1") | ||
.toString(); | ||
|
||
URL url = new URL(WEBSEQ_URL); | ||
URLConnection conn = url.openConnection(); | ||
conn.setDoOutput(true); | ||
writer = new OutputStreamWriter(conn.getOutputStream(), StandardCharsets.UTF_8); | ||
writer.write(query); | ||
writer.flush(); | ||
|
||
StringBuilder response = new StringBuilder(); | ||
reader = new BufferedReader( | ||
new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8)); | ||
String line; | ||
while ((line = reader.readLine()) != null) { | ||
response.append(line); | ||
} | ||
|
||
writer.close(); | ||
reader.close(); | ||
|
||
String json = response.toString(); | ||
|
||
int start = json.indexOf("?png="); | ||
int end = json.indexOf("\"", start); | ||
|
||
if (start != -1 && end != -1) { | ||
webSeqUrl = WEBSEQ_URL + "/" + json.substring(start, end); | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException("Failed to get proper response from websequencediagrams.com", e); | ||
} finally { | ||
IOUtils.closeQuietly(writer); | ||
IOUtils.closeQuietly(reader); | ||
} | ||
|
||
return webSeqUrl; | ||
} | ||
|
||
@Override | ||
public Rule[] blockPluginRules() { | ||
return new Rule[]{BlockRule()}; | ||
} | ||
} |
Oops, something went wrong.