@codemirror/lang-markdown
Advanced tools
Comparing version 6.2.0 to 6.2.1
@@ -0,1 +1,7 @@ | ||
## 6.2.1 (2023-09-14) | ||
### Bug fixes | ||
Make `insertNewlineContinueMarkup` and `deleteMarkupBackward` use tabs for indentation when appropriate. | ||
## 6.2.0 (2023-06-23) | ||
@@ -2,0 +8,0 @@ |
@@ -1,4 +0,4 @@ | ||
import { EditorSelection, Prec, EditorState } from '@codemirror/state'; | ||
import { EditorSelection, countColumn, Prec, EditorState } from '@codemirror/state'; | ||
import { keymap } from '@codemirror/view'; | ||
import { defineLanguageFacet, foldNodeProp, indentNodeProp, languageDataProp, foldService, syntaxTree, Language, LanguageDescription, ParseContext, LanguageSupport } from '@codemirror/language'; | ||
import { defineLanguageFacet, foldNodeProp, indentNodeProp, languageDataProp, foldService, syntaxTree, Language, LanguageDescription, ParseContext, indentUnit, LanguageSupport } from '@codemirror/language'; | ||
import { CompletionContext } from '@codemirror/autocomplete'; | ||
@@ -126,7 +126,7 @@ import { parser, GFM, Subscript, Superscript, Emoji, MarkdownParser, parseCode } from '@lezer/markdown'; | ||
} | ||
else if (node.name == "Blockquote" && (match = /^[ \t]*>( ?)/.exec(line.text.slice(startPos)))) { | ||
else 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 = /^([ \t]*)\d+([.)])([ \t]*)/.exec(line.text.slice(startPos)))) { | ||
(match = /^( *)\d+([.)])( *)/.exec(line.text.slice(startPos)))) { | ||
let after = match[3], len = match[0].length; | ||
@@ -140,3 +140,3 @@ if (after.length >= 4) { | ||
else if (node.name == "ListItem" && node.parent.name == "BulletList" && | ||
(match = /^([ \t]*)([-+*])([ \t]{1,4}\[[ xX]\])?([ \t]+)/.exec(line.text.slice(startPos)))) { | ||
(match = /^( *)([-+*])( {1,4}\[[ xX]\])?( +)/.exec(line.text.slice(startPos)))) { | ||
let after = match[4], len = match[0].length; | ||
@@ -176,2 +176,20 @@ if (after.length > 4) { | ||
} | ||
function normalizeIndent(content, state) { | ||
let blank = /^[ \t]*/.exec(content)[0].length; | ||
if (!blank || state.facet(indentUnit) != "\t") | ||
return content; | ||
let col = countColumn(content, 4, blank); | ||
let space = ""; | ||
for (let i = col; i > 0;) { | ||
if (i >= 4) { | ||
space += "\t"; | ||
i -= 4; | ||
} | ||
else { | ||
space += " "; | ||
i--; | ||
} | ||
} | ||
return space + content.slice(blank); | ||
} | ||
/** | ||
@@ -227,5 +245,5 @@ This command, when invoked in Markdown context with cursor | ||
for (let i = 0, e = context.length - 2; i <= e; i++) { | ||
insert += context[i].blank(i < e ? context[i + 1].from - insert.length : null, i < e); | ||
insert += context[i].blank(i < e ? countColumn(line.text, 4, context[i + 1].from) - insert.length : null, i < e); | ||
} | ||
insert += state.lineBreak; | ||
insert = normalizeIndent(insert + state.lineBreak, state); | ||
return { range: EditorSelection.cursor(pos + insert.length), changes: { from: line.from, insert } }; | ||
@@ -252,3 +270,3 @@ } | ||
insert += i == e && !continued ? context[i].marker(doc, 1) | ||
: context[i].blank(i < e ? context[i + 1].from - insert.length : null); | ||
: context[i].blank(i < e ? countColumn(line.text, 4, context[i + 1].from) - insert.length : null); | ||
} | ||
@@ -259,3 +277,3 @@ } | ||
from--; | ||
insert = state.lineBreak + insert; | ||
insert = state.lineBreak + normalizeIndent(insert, state); | ||
changes.push({ from, to: pos, insert }); | ||
@@ -324,4 +342,9 @@ return { range: EditorSelection.cursor(from + insert.length), changes }; | ||
// Replace a list item marker with blank space | ||
if (inner.item && inner.node.from < inner.item.from && /\S/.test(line.text.slice(inner.from, inner.to))) | ||
return { range, changes: { from: start, to: line.from + inner.to, insert: inner.blank(inner.to - inner.from) } }; | ||
if (inner.item && inner.node.from < inner.item.from && /\S/.test(line.text.slice(inner.from, inner.to))) { | ||
let insert = inner.blank(countColumn(line.text, 4, inner.to) - countColumn(line.text, 4, inner.from)); | ||
if (start == line.from) | ||
insert = normalizeIndent(insert, state); | ||
return { range: EditorSelection.cursor(start + insert.length), | ||
changes: { from: start, to: line.from + inner.to, insert } }; | ||
} | ||
// Delete one level of indentation | ||
@@ -328,0 +351,0 @@ if (start < pos) |
{ | ||
"name": "@codemirror/lang-markdown", | ||
"version": "6.2.0", | ||
"version": "6.2.1", | ||
"description": "Markdown language support for the CodeMirror code editor", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57703
914