generated from halo-dev/plugin-starter
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mermaid): add dark mode support for mermaid
- Loading branch information
Showing
4 changed files
with
16 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,6 @@ | |
|
||
@Data | ||
public class BasicConfig { | ||
String dark_class_selector; | ||
String mermaid_selector; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
package run.halo.plugin.textdiagram; | ||
|
||
public class JSInjector { | ||
static String getParsedKatexScript(String mermaid_selector) { | ||
static String getParsedKatexScript(String darkClassSelector, String mermaid_selector) { | ||
String katexScript = """ | ||
<script defer src="/plugins/text-diagram/assets/static/mermaid.min.js"></script> | ||
<script> | ||
document.addEventListener("DOMContentLoaded", function() { | ||
const postBody = document.body | ||
mermaid.initialize({ startOnLoad: false }); | ||
let darkModel = document.querySelector('%s') | ||
mermaid.initialize({ | ||
startOnLoad: false, | ||
theme: darkModel?'dark':'default' | ||
}); | ||
mermaid.run({ | ||
querySelector: '%s', | ||
}); | ||
}); | ||
</script> | ||
"""; | ||
return String.format(katexScript, mermaid_selector); | ||
return String.format(katexScript, darkClassSelector, mermaid_selector); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters