Skip to content

Commit

Permalink
Make sure commands return false inside fenced code
Browse files Browse the repository at this point in the history
FIX: Make Markdown-specific commands return false inside fenced code.

See https://discuss.codemirror.net/t/python-fencedcode-indentation-inconsistent/8909
  • Loading branch information
marijnh committed Dec 17, 2024
1 parent f2c652e commit 24e43e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
11 changes: 4 additions & 7 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,15 @@ class Context {
}

function getContext(node: SyntaxNode, doc: Text) {
let nodes = []
let nodes: SyntaxNode[] = [], context: Context[] = []
for (let cur: SyntaxNode | null = node; cur; cur = cur.parent) {
if (cur.name == "ListItem" || cur.name == "Blockquote" || cur.name == "FencedCode")
nodes.push(cur)
if (cur.name == "FencedCode") return context
if (cur.name == "ListItem" || cur.name == "Blockquote") nodes.push(cur)
}
let context = []
for (let i = nodes.length - 1; i >= 0; i--) {
let node = nodes[i], match
let line = doc.lineAt(node.from), startPos = node.from - line.from
if (node.name == "FencedCode") {
context.push(new Context(node, startPos, startPos, "", "", "", null))
} else if (node.name == "Blockquote" && (match = /^ *>( ?)/.exec(line.text.slice(startPos)))) {
if (node.name == "Blockquote" && (match = /^ *>( ?)/.exec(line.text.slice(startPos)))) {
context.push(new Context(node, startPos, startPos + match[0].length, "", match[1], ">", null))
} else if (node.name == "ListItem" && node.parent!.name == "OrderedList" &&
(match = /^( *)\d+([.)])( *)/.exec(line.text.slice(startPos)))) {
Expand Down
6 changes: 3 additions & 3 deletions test/test-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ describe("insertNewlineContinueMarkup", () => {
test("1. x\n2. |y", "1. x\n2.\n3. |y")
})

it("doesn't continue lists in fenced code", () => {
test("- ```foo|", "- ```foo\n |")
test("> - ```foo|", "> - ```foo\n> |")
it("doesn't take effect in fenced code", () => {
test("- ```foo|", "- ```foo|")
test("> - ```foo|", "> - ```foo|")
})

it("continues nested task lists at the right level", () => {
Expand Down

0 comments on commit 24e43e6

Please sign in to comment.