37 lines
802 B
Java
37 lines
802 B
Java
package com.madeorsk.smartnotes;
|
|
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
|
|
import com.vladsch.flexmark.html.HtmlRenderer;
|
|
import com.vladsch.flexmark.parser.Parser;
|
|
|
|
public class Utils
|
|
{
|
|
private static Parser parser = Parser.builder().build();
|
|
private static HtmlRenderer htmlRenderer = HtmlRenderer.builder().build();
|
|
|
|
public static String loadText(String path)
|
|
{
|
|
try
|
|
{
|
|
InputStream is = Utils.class.getResourceAsStream(path);
|
|
String result = "";
|
|
byte[] buffer = new byte[1024 * 8];
|
|
while (is.read(buffer) > 0)
|
|
result += new String(buffer);
|
|
return result.trim();
|
|
}
|
|
catch (IOException e)
|
|
{
|
|
e.printStackTrace();
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static String markdownToHtml(String markdown)
|
|
{
|
|
return htmlRenderer.render(parser.parse(markdown));
|
|
}
|
|
}
|