diff options
author | tim-zh <tim.zhlobich@gmail.com> | 2016-11-14 18:17:10 +0300 |
---|---|---|
committer | tim-zh <tim.zhlobich@gmail.com> | 2016-11-14 18:17:10 +0300 |
commit | 9269863fbdcd94cce39582f6638d9f94bdaa1706 (patch) | |
tree | c8602052beccbeb1b9bb4371c9d6307ac013c98d /tools/gui/src | |
parent | 2ef3cc9b722da0d0b61966871ba0a0b24e0d7739 (diff) | |
download | cbt-9269863fbdcd94cce39582f6638d9f94bdaa1706.tar.gz cbt-9269863fbdcd94cce39582f6638d9f94bdaa1706.tar.bz2 cbt-9269863fbdcd94cce39582f6638d9f94bdaa1706.zip |
readme.md handling
Diffstat (limited to 'tools/gui/src')
-rw-r--r-- | tools/gui/src/Main.scala | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/tools/gui/src/Main.scala b/tools/gui/src/Main.scala index 7bb299c..f2f8ee1 100644 --- a/tools/gui/src/Main.scala +++ b/tools/gui/src/Main.scala @@ -3,6 +3,9 @@ import java.net.MalformedURLException import java.nio.file.attribute.BasicFileAttributes import java.nio.file.{FileVisitResult, Files, Path, SimpleFileVisitor} +import org.commonmark.parser.Parser +import org.commonmark.renderer.html.HtmlRenderer + import scala.io.Source import scala.util.{Failure, Success, Try} import scalaj.http.Http @@ -73,7 +76,13 @@ object Main { val path = param("path") handleIoException { val file = new File(path) - Success(Source.fromFile(file).mkString) + Success { + val content = Source.fromFile(file).mkString + if (file.getName.endsWith(".md")) + parseMd(content) + else + content + } } case _ => Failure(new MalformedURLException(s"Incorrect path: $path")) @@ -125,6 +134,13 @@ object Main { s"""{"name":"${file.getName}","path":"${file.getAbsolutePath}"$data}""" } + private def parseMd(s: String) = { + val parser = Parser.builder().build() + val document = parser.parse(s) + val renderer = HtmlRenderer.builder().build() + renderer.render(document) + } + private class FileCopier(source: File, target: File) extends SimpleFileVisitor[Path] { def copy() = Files.walkFileTree(source.toPath, this) |