aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authortim-zh <tim.zhlobich@gmail.com>2016-11-14 18:17:10 +0300
committertim-zh <tim.zhlobich@gmail.com>2016-11-14 18:17:10 +0300
commit9269863fbdcd94cce39582f6638d9f94bdaa1706 (patch)
treec8602052beccbeb1b9bb4371c9d6307ac013c98d /tools
parent2ef3cc9b722da0d0b61966871ba0a0b24e0d7739 (diff)
downloadcbt-9269863fbdcd94cce39582f6638d9f94bdaa1706.tar.gz
cbt-9269863fbdcd94cce39582f6638d9f94bdaa1706.tar.bz2
cbt-9269863fbdcd94cce39582f6638d9f94bdaa1706.zip
readme.md handling
Diffstat (limited to 'tools')
-rw-r--r--tools/gui/build/build.scala3
-rw-r--r--tools/gui/resources/web/definitions.js4
-rw-r--r--tools/gui/resources/web/index.html2
-rw-r--r--tools/gui/resources/web/styles.css14
-rw-r--r--tools/gui/src/Main.scala18
5 files changed, 34 insertions, 7 deletions
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 : ("<pre><code>" + data + "</code></pre>"));
});
});
}
+ 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 @@
<div id="examples"></div>
<div id="example-browser">
<div id="file-browser"></div>
- <pre id="code-browser"><code></code></pre>
+ <div id="code-browser"></div>
</div>
<hr>
<button id="copy-project-btn" onclick="copyProject()">copy example</button>
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)