use of org.commonmark.node.Node in project gitiles by GerritCodeReview.
the class Navbar method extractSiteTitle.
private void extractSiteTitle() {
for (Node c = node.getFirstChild(); c != null; c = c.getNext()) {
if (c instanceof Heading) {
Heading h = (Heading) c;
if (h.getLevel() == 1) {
siteTitle = MarkdownUtil.getInnerText(h);
h.unlink();
break;
}
}
}
}
use of org.commonmark.node.Node in project gitiles by GerritCodeReview.
the class MarkdownUtil method trimPreviousWhitespace.
static void trimPreviousWhitespace(Node node) {
Node prev = node.getPrevious();
if (prev instanceof Text) {
Text prevText = (Text) prev;
String s = prevText.getLiteral();
prevText.setLiteral(CharMatcher.whitespace().trimTrailingFrom(s));
}
}
use of org.commonmark.node.Node 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.node.Node 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.node.Node 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;
}
Aggregations