use of org.commonmark.renderer.html.HtmlRenderer in project symja_android_library by axkr.
the class AJAXDocServlet method generateHTMLString.
public static String generateHTMLString(final String markdownStr) {
List<Extension> EXTENSIONS = //
Arrays.asList(TeXExtension.create(), TablesExtension.create());
Parser parser = //
Parser.builder().extensions(EXTENSIONS).build();
Node document = parser.parse(markdownStr);
HtmlRenderer renderer = //
HtmlRenderer.builder().extensions(EXTENSIONS).nodeRendererFactory(new HtmlNodeRendererFactory() {
@Override
public NodeRenderer create(HtmlNodeRendererContext context) {
return new DocNodeRenderer(context);
}
}).build();
return renderer.render(document);
}
use of org.commonmark.renderer.html.HtmlRenderer in project symja_android_library by axkr.
the class MarkdownToHTML method generateHTMLString.
/**
* Generate markdown links for Symja function reference.
*
* @param sourceLocation source directory for funtions (*.md) files
*/
public static void generateHTMLString(final File sourceLocation, String function, boolean javadoc) {
if (sourceLocation.exists()) {
// Get the list of the files contained in the package
final String[] files = sourceLocation.list();
if (files != null) {
for (int i = 0; i < files.length; i++) {
if (files[i].endsWith(".md")) {
String className = files[i].substring(0, files[i].length() - 3);
if (className.equals(function)) {
File file = new File(sourceLocation + "/" + files[i]);
String html;
try {
Set<Extension> EXTENSIONS = Collections.singleton(TablesExtension.create());
Parser parser = Parser.builder().extensions(EXTENSIONS).build();
Node document = parser.parse(Files.asCharSource(file, StandardCharsets.UTF_8).read());
HtmlRenderer renderer = HtmlRenderer.builder().extensions(EXTENSIONS).build();
html = renderer.render(document);
if (javadoc) {
html = html.replace("<blockquote>", "");
html = html.replace("</blockquote>", "");
String[] lines = html.split("\\n");
System.out.println("/**");
for (int j = 0; j < lines.length; j++) {
if (lines[j].startsWith("<h3>Github</h3>")) {
// don't include link to github implementation
break;
}
if (!lines[j].startsWith("<h2>")) {
System.out.println(" * " + lines[j]);
}
}
System.out.println(" */");
} else {
System.out.println(html);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
}
}
use of org.commonmark.renderer.html.HtmlRenderer in project diary by billthefarmer.
the class DiaryWidgetProvider method getText.
// getText
@SuppressWarnings("deprecation")
private CharSequence getText(Context context) {
// Get preferences
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
// Get folder
folder = preferences.getString(Settings.PREF_FOLDER, Diary.DIARY);
markdown = preferences.getBoolean(Settings.PREF_MARKDOWN, true);
// Get date
DateFormat format = DateFormat.getDateInstance(DateFormat.MEDIUM);
String date = format.format(new Date());
// Get text
CharSequence text = Diary.read(getFile());
if (markdown) {
// Use commonmark
Parser parser = Parser.builder().build();
Node document = parser.parse(text.toString());
HtmlRenderer renderer = HtmlRenderer.builder().build();
String html = renderer.render(document);
text = Html.fromHtml(html);
}
return text;
}
use of org.commonmark.renderer.html.HtmlRenderer in project codeu-2018-team12 by codeu-2018-team12.
the class TextFormatter method formatForDisplay.
public static String formatForDisplay(String input) {
// Parses input and replaces markdown characters with the appropriate HTML
Parser parser = Parser.builder().build();
Node document = parser.parse(input);
HtmlRenderer renderer = HtmlRenderer.builder().build();
String parsedInput = renderer.render(document);
// Removes unneeded <p> tags
int parsedInputLength = parsedInput.length();
if (parsedInput.startsWith("<p>")) {
parsedInput = parsedInput.substring(3, parsedInputLength - 5);
}
// Ensures that new line characters are displayed correctly
parsedInput = parsedInput.replaceAll("(\r\n|\n\r|\r|\n)", "<br />");
// Replaces emoji aliases with Hexadecimal values ready for display in HTML
String finalOutput = EmojiParser.parseToUnicode(parsedInput);
finalOutput = EmojiParser.parseToHtmlHexadecimal(finalOutput);
return finalOutput;
}
use of org.commonmark.renderer.html.HtmlRenderer in project xian by happyyangyuan.
the class MdToHtml method mdToHtml.
/**
* @param md the markdown string.
* @return converted html
*/
public static String mdToHtml(String md) {
Parser parser = Parser.builder().build();
Node document = parser.parse(md);
HtmlRenderer renderer = HtmlRenderer.builder().build();
return renderer.render(document);
}
Aggregations