Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use mermaid for rendering diagrams #37

Merged
merged 3 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ ENTRYPOINT ["app/bin/app"]
RUN apt-get update -y && apt-get install -y texlive-full
RUN apt-get update -y && apt-get install -y xournalpp
RUN apt-get update -y && apt-get install -y pandoc
RUN apt-get update -y && apt-get install -y npm nodejs
RUN npm install -g n && n stable
RUN npm install -g @mermaid-js/mermaid-cli
COPY mmdc-puppeteer-config.json .

COPY app/build/distributions/app.tar FileSpider.tar
RUN tar -xf FileSpider.tar
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,31 @@ class Renderer {
Renderer().tempDir().resolveLinks().outputFile("text/html", "html") { it.fileName }

private val markdownRenderer =
Renderer().tempDir().command(10) {
listOf(
"pandoc",
"-f", "markdown",
"-o", "out.html",
"-s",
"--katex=/libs/katex/",
"--metadata", "title=${it.document.title}",
it.fileName
)
}
Renderer().tempDir()
.copy({ it.fileName }, { "tmp0.md" })
.command(2) {
listOf(
"mmdc",
"-p", "/opt/filespider/mmdc-puppeteer-config.json",
"-i", "tmp0.md",
"-o", "tmp1.md",
"-e", "png",
"-w", "19200px",
)
}
.replace(mapOf("!\\[diagram\\]\\((\\.\\/tmp1-[0-9]+\\.png)\\)" to "<img src=\"\\1\" style=\"max-width: 100%\" \\/>")) { "tmp1.md" }
.command(10) {
listOf(
"pandoc",
"-f", "markdown",
"-o", "out.html",
"-s",
"--katex=http://localhost:80/libs/katex/",
"--metadata", "title=${it.document.title}",
"--self-contained",
"tmp1.md"
)
}
.resolveLinks { "out.html" }.outputFile("text/html", "html") { "out.html" }

private val latexRenderer = Renderer().tempDir().command(10) {
Expand Down Expand Up @@ -161,6 +175,11 @@ class Renderer {
filenameProvider
)
}
fun copy(srcProvider: (RenderMeta) -> String, dstProvider: (RenderMeta) -> String): Renderer {
return addStep {
Files.copy(Paths.get(it.workingDirectory.toString(), srcProvider(it)), Paths.get(it.workingDirectory.toString(), dstProvider(it)))
}
}

fun render(document: Document, fsService: FileSystemService): RenderedDocument? {
return render(
Expand Down
3 changes: 3 additions & 0 deletions backend/mmdc-puppeteer-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"args": ["--no-sandbox"]
}