Skip to content

Commit f8c8615

Browse files
author
Amelia Wattenberger
committed
markdown: hide code start block
1 parent de3c5f9 commit f8c8615

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

blocks/file-blocks/markdown-edit/copy-widget.tsx

+15
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ export const copy = ({
8989
Decoration.mark({
9090
class: "cm-copy-html-tag",
9191
});
92+
const instructionDecoration = () =>
93+
Decoration.mark({
94+
class: "cm-instruction",
95+
});
9296
const rawLinkDecoration = (url: string) =>
9397
Decoration.mark({
9498
tagName: "a",
@@ -127,6 +131,10 @@ export const copy = ({
127131
Decoration.line({
128132
class: "cm-copy-blockquote",
129133
});
134+
const codeBlockStartDecoration = () =>
135+
Decoration.line({
136+
class: "cm-code-start",
137+
});
130138
const codeBlockDecoration = () =>
131139
Decoration.line({
132140
class: "cm-code",
@@ -198,6 +206,10 @@ export const copy = ({
198206
const newDecoration = linkDecoration(text, linkText, absoluteUrl);
199207
widgets.push(newDecoration.range(from, to));
200208
}
209+
} else if (type.name === "CodeInfo") {
210+
let text = state.doc.sliceString(from, to);
211+
const newDecoration = instructionDecoration();
212+
widgets.push(newDecoration.range(from, to));
201213
} else if (type.name === "URL") {
202214
let text = state.doc.sliceString(from, to);
203215
const endOfLink = /\)/.exec(text);
@@ -225,6 +237,9 @@ export const copy = ({
225237
const linePosition = state.doc.lineAt(i);
226238
widgets.push(newDecoration.range(linePosition.from));
227239
}
240+
const newStartDecoration = codeBlockStartDecoration();
241+
const previousLineFrom = state.doc.lineAt(fromLine.from - 1).from;
242+
widgets.push(newStartDecoration.range(previousLineFrom));
228243
// widgets.push(newDecoration.range(from));
229244
} else if (["HTMLTag", "HTMLBlock"].includes(type.name)) {
230245
let text = state.doc.sliceString(from, to);

blocks/file-blocks/markdown-edit/style.css

+2
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ html body div.cm-editor .cm-line::selection {
234234
.cm-activeLine .cm-instruction,
235235
.cm-activeLine .ͼu,
236236
.cm-activeLine .cm-image,
237+
.cm-activeLine + .cm-code-start,
238+
.cm-activeLine + .cm-code-start .cm-instruction,
237239
.cm-activeLine + .cm-image-container + .cm-line .cm-image,
238240
.cm-activeLine + .cm-image-container + .cm-line .cm-image-alt,
239241
.cm-activeLine + .cm-image-container + .cm-line .cm-instruction,

0 commit comments

Comments
 (0)