aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2024-09-13 20:01:04 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-09-13 20:01:04 +0800
commit7f3faf7dd4cbb1a42775b17ac4a7ed93749e0917 (patch)
tree1a43f2100ad65cdb8acc9b15612720c9b9dc884f /src
parent444e66905207efac253320d8558d5922d4f8291a (diff)
style: More code blocks
Diffstat (limited to 'src')
-rw-r--r--src/editor.mjs10
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'
4import { defaultAliasesForRenderer, parseConfigsFromYaml } from 'mapclay' 4import { defaultAliasesForRenderer, parseConfigsFromYaml } from 'mapclay'
5import { createDocLinks } from './dumbymap.mjs' 5import { createDocLinks } from './dumbymap.mjs'
6 6
7// Set up Editor {{{ 7// Set up Containers {{{
8 8
9const HtmlContainer = document.querySelector(".result-html") 9const HtmlContainer = document.querySelector(".result-html")
10const textArea = document.querySelector(".editor textarea") 10const 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
24const getStateFromHash = (hash) => { 26const getStateFromHash = (hash) => {
@@ -40,7 +42,6 @@ const contentFromHash = initialState.content
40const lastContent = localStorage.getItem('editorContent') 42const lastContent = localStorage.getItem('editorContent')
41const 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' 43const 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 {{{
44const editor = new EasyMDE({ 45const 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
84const cm = editor.codemirror 85const cm = editor.codemirror
86// }}}
87// Set up logic about editor content {{{
85markdown2HTML(HtmlContainer, editor.value()) 88markdown2HTML(HtmlContainer, editor.value())
86createDocLinks(HtmlContainer) 89createDocLinks(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
117window.onhashchange = () => { 119window.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 {{{
177const getLineWithRenderer = (anchor) => { 179const 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