aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/css/index.css3
-rw-r--r--src/editor.mjs19
2 files changed, 20 insertions, 2 deletions
diff --git a/src/css/index.css b/src/css/index.css
index 93a4918..0997779 100644
--- a/src/css/index.css
+++ b/src/css/index.css
@@ -64,7 +64,8 @@ body {
64} 64}
65 65
66/* FIXME For those empty line (no child with cm-comment) */ 66/* FIXME For those empty line (no child with cm-comment) */
67.CodeMirror-line:has(.cm-comment) { 67.inside-code-block,
68.CodeMirror-line:has(.cm-formatting-code-block) {
68 background: rgba(0,0,0,.05) !important; 69 background: rgba(0,0,0,.05) !important;
69 70
70 .cm-comment { 71 .cm-comment {
diff --git a/src/editor.mjs b/src/editor.mjs
index 5470b64..d1b4ba1 100644
--- a/src/editor.mjs
+++ b/src/editor.mjs
@@ -89,10 +89,27 @@ if (queryParams.get('render')) {
89 toggleMaps(HtmlContainer) 89 toggleMaps(HtmlContainer)
90} 90}
91 91
92// Quick hack to style lines inside code block
93const addClassToCodeLines = () => {
94 const lines = cm.getLineHandle(0).parent.lines
95 let insideCodeBlock = false
96 lines.forEach((line, index) => {
97 if (line.text.match(/^````*/)) {
98 insideCodeBlock = !insideCodeBlock
99 } else if (insideCodeBlock) {
100 cm.addLineClass(index, "text", "inside-code-block")
101 } else {
102 cm.removeLineClass(index, "text", "inside-code-block")
103 }
104 })
105}
106addClassToCodeLines()
107
92// Re-render HTML by editor content 108// Re-render HTML by editor content
93cm.on("change", () => { 109cm.on("change", (_, obj) => {
94 markdown2HTML(HtmlContainer, editor.value()) 110 markdown2HTML(HtmlContainer, editor.value())
95 createDocLinks(HtmlContainer) 111 createDocLinks(HtmlContainer)
112 addClassToCodeLines()
96}) 113})
97// }}} 114// }}}
98 115