diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2024-09-13 20:01:04 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2024-09-13 20:01:04 +0800 |
commit | 7f3faf7dd4cbb1a42775b17ac4a7ed93749e0917 (patch) | |
tree | 1a43f2100ad65cdb8acc9b15612720c9b9dc884f /src/editor.mjs | |
parent | 444e66905207efac253320d8558d5922d4f8291a (diff) |
style: More code blocks
Diffstat (limited to 'src/editor.mjs')
-rw-r--r-- | src/editor.mjs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/editor.mjs b/src/editor.mjs index 2df4279..b99e34f 100644 --- a/src/editor.mjs +++ b/src/editor.mjs | |||
@@ -4,7 +4,7 @@ import { markdown2HTML, generateMaps } from './dumbymap' | |||
4 | import { defaultAliasesForRenderer, parseConfigsFromYaml } from 'mapclay' | 4 | import { defaultAliasesForRenderer, parseConfigsFromYaml } from 'mapclay' |
5 | import { createDocLinks } from './dumbymap.mjs' | 5 | import { createDocLinks } from './dumbymap.mjs' |
6 | 6 | ||
7 | // Set up Editor {{{ | 7 | // Set up Containers {{{ |
8 | 8 | ||
9 | const HtmlContainer = document.querySelector(".result-html") | 9 | const HtmlContainer = document.querySelector(".result-html") |
10 | const textArea = document.querySelector(".editor textarea") | 10 | const textArea = document.querySelector(".editor textarea") |
@@ -19,6 +19,8 @@ const toggleMaps = (container) => { | |||
19 | container.setAttribute('data-layout', 'none') | 19 | container.setAttribute('data-layout', 'none') |
20 | } | 20 | } |
21 | } | 21 | } |
22 | // }}} | ||
23 | // Set up EasyMDE {{{ | ||
22 | 24 | ||
23 | // Content values for editor | 25 | // Content values for editor |
24 | const getStateFromHash = (hash) => { | 26 | const getStateFromHash = (hash) => { |
@@ -40,7 +42,6 @@ const contentFromHash = initialState.content | |||
40 | const lastContent = localStorage.getItem('editorContent') | 42 | const lastContent = localStorage.getItem('editorContent') |
41 | const defaultContent = '## Links\n\n- [Go to marker](geo:24,121?id=foo,leaflet&text=normal "Link Test")\n\n```map\nid: foo\nuse: Maplibre\n```\n' | 43 | const defaultContent = '## Links\n\n- [Go to marker](geo:24,121?id=foo,leaflet&text=normal "Link Test")\n\n```map\nid: foo\nuse: Maplibre\n```\n' |
42 | 44 | ||
43 | // Set up EasyMDE {{{ | ||
44 | const editor = new EasyMDE({ | 45 | const editor = new EasyMDE({ |
45 | element: textArea, | 46 | element: textArea, |
46 | indentWithTabs: false, | 47 | indentWithTabs: false, |
@@ -82,6 +83,8 @@ const editor = new EasyMDE({ | |||
82 | }); | 83 | }); |
83 | 84 | ||
84 | const cm = editor.codemirror | 85 | const cm = editor.codemirror |
86 | // }}} | ||
87 | // Set up logic about editor content {{{ | ||
85 | markdown2HTML(HtmlContainer, editor.value()) | 88 | markdown2HTML(HtmlContainer, editor.value()) |
86 | createDocLinks(HtmlContainer) | 89 | createDocLinks(HtmlContainer) |
87 | 90 | ||
@@ -111,7 +114,6 @@ cm.on("change", (_, obj) => { | |||
111 | createDocLinks(HtmlContainer) | 114 | createDocLinks(HtmlContainer) |
112 | addClassToCodeLines() | 115 | addClassToCodeLines() |
113 | }) | 116 | }) |
114 | // }}} | ||
115 | 117 | ||
116 | // Reload editor content by hash value | 118 | // Reload editor content by hash value |
117 | window.onhashchange = () => { | 119 | window.onhashchange = () => { |
@@ -176,6 +178,8 @@ const insideCodeblockForMap = (anchor) => { | |||
176 | // FUNCTION: Get Renderer by cursor position in code block {{{ | 178 | // FUNCTION: Get Renderer by cursor position in code block {{{ |
177 | const getLineWithRenderer = (anchor) => { | 179 | const getLineWithRenderer = (anchor) => { |
178 | const currentLine = anchor.line | 180 | const currentLine = anchor.line |
181 | if (!cm.getLine) return null | ||
182 | |||
179 | const match = (line) => cm.getLine(line).match(/^use: /) | 183 | const match = (line) => cm.getLine(line).match(/^use: /) |
180 | 184 | ||
181 | if (match(currentLine)) return currentLine | 185 | if (match(currentLine)) return currentLine |