@codemirror/lang-markdown
Advanced tools
Comparing version 6.1.1 to 6.2.0
@@ -0,1 +1,7 @@ | ||
## 6.2.0 (2023-06-23) | ||
### New features | ||
The markdown package now installs a completion source that completes HTML tags when in Markdown context. | ||
## 6.1.1 (2023-04-13) | ||
@@ -2,0 +8,0 @@ |
@@ -82,4 +82,10 @@ import { KeyBinding } from '@codemirror/view'; | ||
base?: Language; | ||
/** | ||
By default, the extension installs an autocompletion source that | ||
completes HTML tags when a `<` is typed. Set this to false to | ||
disable this. | ||
*/ | ||
completeHTMLTags?: boolean; | ||
}): LanguageSupport; | ||
export { commonmarkLanguage, deleteMarkupBackward, insertNewlineContinueMarkup, markdown, markdownKeymap, markdownLanguage }; |
@@ -1,6 +0,7 @@ | ||
import { EditorSelection, Prec } from '@codemirror/state'; | ||
import { EditorSelection, 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 { CompletionContext } from '@codemirror/autocomplete'; | ||
import { parser, GFM, Subscript, Superscript, Emoji, MarkdownParser, parseCode } from '@lezer/markdown'; | ||
import { html } from '@codemirror/lang-html'; | ||
import { html, htmlCompletionSource } from '@codemirror/lang-html'; | ||
import { NodeProp } from '@lezer/common'; | ||
@@ -348,3 +349,3 @@ | ||
function markdown(config = {}) { | ||
let { codeLanguages, defaultCodeLanguage, addKeymap = true, base: { parser } = commonmarkLanguage } = config; | ||
let { codeLanguages, defaultCodeLanguage, addKeymap = true, base: { parser } = commonmarkLanguage, completeHTMLTags = true } = config; | ||
if (!(parser instanceof MarkdownParser)) | ||
@@ -365,5 +366,32 @@ throw new RangeError("Base parser provided to `markdown` should be a Markdown parser"); | ||
support.push(Prec.high(keymap.of(markdownKeymap))); | ||
return new LanguageSupport(mkLang(parser.configure(extensions)), support); | ||
let lang = mkLang(parser.configure(extensions)); | ||
if (completeHTMLTags) | ||
support.push(lang.data.of({ autocomplete: htmlTagCompletion })); | ||
return new LanguageSupport(lang, support); | ||
} | ||
function htmlTagCompletion(context) { | ||
let { state, pos } = context, m = /<[:\-\.\w\u00b7-\uffff]*$/.exec(state.sliceDoc(pos - 25, pos)); | ||
if (!m) | ||
return null; | ||
let tree = syntaxTree(state).resolveInner(pos, -1); | ||
while (tree && !tree.type.isTop) { | ||
if (tree.name == "CodeBlock" || tree.name == "FencedCode" || tree.name == "ProcessingInstructionBlock" || | ||
tree.name == "CommentBlock" || tree.name == "Link" || tree.name == "Image") | ||
return null; | ||
tree = tree.parent; | ||
} | ||
return { | ||
from: pos - m[0].length, to: pos, | ||
options: htmlTagCompletions(), | ||
validFor: /^<[:\-\.\w\u00b7-\uffff]*$/ | ||
}; | ||
} | ||
let _tagCompletions = null; | ||
function htmlTagCompletions() { | ||
if (_tagCompletions) | ||
return _tagCompletions; | ||
let result = htmlCompletionSource(new CompletionContext(EditorState.create({ extensions: htmlNoMatch }), 0, true)); | ||
return _tagCompletions = result ? result.options : []; | ||
} | ||
export { commonmarkLanguage, deleteMarkupBackward, insertNewlineContinueMarkup, markdown, markdownKeymap, markdownLanguage }; |
{ | ||
"name": "@codemirror/lang-markdown", | ||
"version": "6.1.1", | ||
"version": "6.2.0", | ||
"description": "Markdown language support for the CodeMirror code editor", | ||
@@ -29,2 +29,3 @@ "scripts": { | ||
"dependencies": { | ||
"@codemirror/autocomplete": "^6.7.1", | ||
"@codemirror/lang-html": "^6.0.0", | ||
@@ -38,3 +39,3 @@ "@codemirror/language": "^6.3.0", | ||
"devDependencies": { | ||
"@codemirror/buildhelper": "^0.1.5" | ||
"@codemirror/buildhelper": "^1.0.0" | ||
}, | ||
@@ -41,0 +42,0 @@ "repository": { |
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
55831
9
869
7