Skip to content

Commit

Permalink
fix(PrinterMermaid): mermaid-offine.html online Fixed #16
Browse files Browse the repository at this point in the history
  • Loading branch information
LinWanCen committed Jan 14, 2025
1 parent a637dd9 commit c130f22
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@
<grid row="10" column="3" row-span="1" col-span="2" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="73a1a" class="javax.swing.JTextField" binding="mermaidJsLink">
<component id="73a1a" class="javax.swing.JTextField" binding="mermaidOnline">
<constraints>
<grid row="11" column="0" row-span="1" col-span="5" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
Expand All @@ -569,7 +569,9 @@
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
<properties>
<text value=""/>
</properties>
</component>
<vspacer id="5f29f">
<constraints>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public GraphWindow(@NotNull Project project, ToolWindow toolWindow) {
UiUtils.onChange(exclude, projectState.getExclude(), projectState::setExclude);
UiUtils.onChange(otherInclude, projectState.getOtherInclude(), projectState::setOtherInclude);
UiUtils.onChange(otherExclude, projectState.getOtherExclude(), projectState::setOtherExclude);
UiUtils.onChange(mermaidJsLink, appState.getMermaidJsLink(), appState::setMermaidJsLink);
UiUtils.onChange(mermaidOnline, appState.getMermaidOnline(), appState::setMermaidOnline);
UiUtils.onChange(tempPath, appState.getTempPath(), appState::setTempPath);
resetSetting.addActionListener(e -> {
include.setText(DrawGraphProjectState.getDefault().getInclude());
Expand Down Expand Up @@ -190,7 +190,7 @@ public void closeAutoLoad() {
private JTextField otherInclude;
private JTextField otherExclude;
private JCheckBox online;
private JTextField mermaidJsLink;
private JTextField mermaidOnline;
private JTextField tempPath;
// endregion setting
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.github.linwancen.plugin.graph.printer

import com.github.linwancen.plugin.graph.parser.RelData
import com.github.linwancen.plugin.graph.settings.DrawGraphAppState
import com.github.linwancen.plugin.graph.settings.Setting
import com.github.linwancen.plugin.graph.ui.DrawGraphBundle
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.Task
Expand Down Expand Up @@ -89,25 +88,27 @@ class PrinterMermaid : Printer() {
src, """
<!-- https://cdn.jsdelivr.net/npm/[email protected]/dist/mermaid.js -->
<!-- change it in DrawGraphSetting.properties -->
<script src="${if (appState.online) appState.mermaidJsLink else appState.mermaidLink}"></script>
<script src="${appState.mermaidOffline}"></script>
"""
)
// language="html"
val online = temp(
src, """
<script src="${Setting.message("mermaid_js_link")}"></script>
<script src="${appState.mermaidOnline}"></script>
"""
)
val path = appState.tempPath
try {
File(path).mkdirs()
if (appState.online) {
func.accept(online)
} else {
func.accept(offline)
}

File(path).mkdirs()
val offlinePath = "$path/mermaid-offline.html"
Files.write(Path.of(offlinePath), offline.toByteArray(StandardCharsets.UTF_8))
func.accept(offline)

val onlinePath = "$path/mermaid-online.html"
File(onlinePath).parentFile.mkdirs()
Files.write(Path.of(offlinePath), offline.toByteArray(StandardCharsets.UTF_8))
Files.write(Path.of(onlinePath), online.toByteArray(StandardCharsets.UTF_8))
} catch (e: Exception) {
func.accept("${offline}\n${ExceptionUtil.getThrowableText(e)}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class DrawGraphAppState : PersistentStateComponent<DrawGraphAppState?>, Abstract
var online = Setting.message("online") == "true"
var path = PathInit.path
var tempPath = if (path != null) "$path/draw-graph" else "draw-graph"
var mermaidJsLink = Setting.message("mermaid_js_link")
val mermaidLink
val mermaidOffline
get() = "file:///$tempPath/mermaid.js"
var mermaidOnline = Setting.message("mermaid_js_link")

override fun getState(): DrawGraphAppState {
return this
Expand Down

0 comments on commit c130f22

Please sign in to comment.