Skip to content

Commit

Permalink
markdown: Support flowcharts with mermaid, by @fgtham, closes #720 (PR
Browse files Browse the repository at this point in the history
…#1581)


The flexmark GitlabExtension already has support for mermaid flowcharts
etc. This change adds the required JavaScript asset. Mermaid graphs can
be added as code of type 'mermaid':


\`\`\`mermaid
flowchart LR
    id1["This is the (text) in the box"]
\`\`\`
  • Loading branch information
fgtham authored Feb 5, 2022
1 parent 7b84c40 commit 0812c17
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public class MarkdownTextConverter extends TextConverter {
" {left: '$$', right: '$$', display: true}, { left: '$', right: '$', display: false }," +
"]});\n";

public static final String HTML_MERMAID_INCLUDE = "<script src='file:///android_asset/mermaid/mermaid.min.js'></script>";

//########################
//## Converter library
//########################
Expand Down Expand Up @@ -197,6 +199,11 @@ public String convertMarkup(String markup, Context context, boolean isExportInLi
markup = markup.replaceAll("(?ms)^([$]{2}.*?[$]{2})$", "<div>\n$1\n</div>");
}

// Enable Mermaid
if (markup.contains("```mermaid")) {
head += HTML_MERMAID_INCLUDE;
}

// Enable View (block) code syntax highlighting
final String xt = getViewHlPrismIncludes(context, (appSettings.isDarkThemeEnabled() ? "-tomorrow" : ""));
head += xt;
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/raw/licenses_3rd_party.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
~° from scratch are placed in the
~° thirdparty directory and MIT licensed.

* Mermaid
~° Copyright Mermaid authors


`---------------`
<small>Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
3 changes: 3 additions & 0 deletions app/thirdparty/assets/mermaid/mermaid.min.js

Large diffs are not rendered by default.

0 comments on commit 0812c17

Please sign in to comment.