From 9269863fbdcd94cce39582f6638d9f94bdaa1706 Mon Sep 17 00:00:00 2001 From: tim-zh Date: Mon, 14 Nov 2016 18:17:10 +0300 Subject: readme.md handling --- tools/gui/build/build.scala | 3 ++- tools/gui/resources/web/definitions.js | 4 +++- tools/gui/resources/web/index.html | 2 +- tools/gui/resources/web/styles.css | 14 +++++++++++--- tools/gui/src/Main.scala | 18 +++++++++++++++++- 5 files changed, 34 insertions(+), 7 deletions(-) (limited to 'tools') diff --git a/tools/gui/build/build.scala b/tools/gui/build/build.scala index 5312e55..f9e800b 100644 --- a/tools/gui/build/build.scala +++ b/tools/gui/build/build.scala @@ -5,7 +5,8 @@ class Build(val context: Context) extends BaseBuild { override def dependencies = { super.dependencies ++ Resolver(mavenCentral).bind( MavenDependency("org.eclipse.jetty", "jetty-server", "9.3.12.v20160915"), - MavenDependency("org.scalaj", "scalaj-http_" + constants.scalaMajorVersion, "2.3.0") + ScalaDependency("org.scalaj", "scalaj-http", "2.3.0"), + MavenDependency("com.atlassian.commonmark", "commonmark", "0.7.1") ) } diff --git a/tools/gui/resources/web/definitions.js b/tools/gui/resources/web/definitions.js index d1313d4..466cf59 100644 --- a/tools/gui/resources/web/definitions.js +++ b/tools/gui/resources/web/definitions.js @@ -215,9 +215,11 @@ let Examples = { ajax("/example/file", {path: node.path}).done(data => { var codeBrowser = $("#code-browser"); codeBrowser.show(); - codeBrowser.html(data); + codeBrowser.html(node.name.endsWith(".md") ? data : ("
" + data + "
")); }); }); } + if (node.name.toLowerCase() == "readme.md") + div.click(); } }; diff --git a/tools/gui/resources/web/index.html b/tools/gui/resources/web/index.html index 100c65b..9bf76f8 100644 --- a/tools/gui/resources/web/index.html +++ b/tools/gui/resources/web/index.html @@ -52,7 +52,7 @@
-
+

diff --git a/tools/gui/resources/web/styles.css b/tools/gui/resources/web/styles.css index 759dd06..6e2bc8e 100644 --- a/tools/gui/resources/web/styles.css +++ b/tools/gui/resources/web/styles.css @@ -31,7 +31,10 @@ hr { } pre { - margin: 0 0 1em 0; + margin: 0; + font-size: 1rem; + background: #000; + padding: 0.2em; } button, .small-btn { @@ -218,6 +221,7 @@ button, .entry { #example-browser { width: 100%; float: left; + margin-bottom: 1em; } #file-browser { @@ -245,17 +249,21 @@ button, .entry { } .browser-node > div { - margin-left: 2em; + margin-left: 1em; } .file-node { cursor: pointer; } -.file-node:hover, .selected-node { +.file-node:hover { color: #dc322f; } +.selected-node { + color: #27b3d9; +} + .even-node { background: #073642; } 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) -- cgit v1.2.3