diff --git a/snark-document-builder/src/main/kotlin/DocumentBuilder.kt b/snark-document-builder/src/main/kotlin/DocumentBuilder.kt index a65eeaa..0692b0a 100644 --- a/snark-document-builder/src/main/kotlin/DocumentBuilder.kt +++ b/snark-document-builder/src/main/kotlin/DocumentBuilder.kt @@ -8,15 +8,27 @@ import kotlinx.html.* import kotlinx.html.dom.createHTMLDocument import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import com.fasterxml.jackson.module.kotlin.readValue +import kotlinx.serialization.json.Json + +private val SNARK_HTML_RENDER = "snark-document-builder/src/main/nodejs/HtmlRenderer.js" +fun getHtml(ast_string: String): String +{ + return ProcessBuilder("node", SNARK_HTML_RENDER, ast_string) + .redirectOutput(ProcessBuilder.Redirect.PIPE) + .redirectError(ProcessBuilder.Redirect.INHERIT) + .start().inputStream.bufferedReader().readText() +} private val DEFAULT_DOCUMENT_ROOT = "main.md" public suspend fun buildDocument(documentDirectory: Directory): String { val dependencyGraph = buildDependencyGraph(documentDirectory) + val root: MdAstRoot = dependencyGraph.nodes[""]!!.mdAst - return jacksonObjectMapper().writeValueAsString(root) - // TODO прикрутить html + // return getHtml(jacksonObjectMapper().writeValueAsString(root)) + // return jacksonObjectMapper().writeValueAsString(root) + return root.toString() } public suspend fun buildDependencyGraph(root: Directory): DependencyGraph { diff --git a/snark-document-builder/src/main/nodejs/HtmlRenderer.js b/snark-document-builder/src/main/nodejs/HtmlRenderer.js new file mode 100644 index 0000000..dc9cda0 --- /dev/null +++ b/snark-document-builder/src/main/nodejs/HtmlRenderer.js @@ -0,0 +1,16 @@ +import {toHast} from 'mdast-util-to-hast' +import {toHtml} from 'hast-util-to-html' + +main() + +function main() +{ + if (process.argv.length < 3) + throw "No input" + + const md_ast = JSON.parse(process.argv[2]) + const hast = toHast(md_ast) + const html = toHtml(hast) + + console.log(html) +}