From 0f9668593b1aa6cceecf64766cbc048dfa2bb84f Mon Sep 17 00:00:00 2001 From: Panagiotis Georgakopoulos Date: Wed, 22 Dec 2021 13:50:25 +0200 Subject: [PATCH] Export parseCode from markdown *parser* --- dist/index.d.ts | 7 ++++++- dist/index.es.js | 15 ++++++++++----- package-lock.json | 14 +++++++------- package.json | 2 +- src/basic-setup.ts | 2 ++ 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/dist/index.d.ts b/dist/index.d.ts index 60e3671..167410d 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -4876,6 +4876,11 @@ declare class InlineContext { elt(tree: Tree, at: number): Element$1; } +declare function parseCode(config: { + codeParser?: (info: string) => null | Parser; + htmlParser?: Parser; +}): MarkdownExtension; + /** Language support for [GFM](https://github.github.com/gfm/) plus subscript, superscript, and emoji syntax. @@ -5109,4 +5114,4 @@ Create an instance of the collaborative editing plugin. */ declare function collab(config?: CollabConfig): Extension; -export { Annotation, Compartment, Decoration, EditorSelection, EditorState, EditorView, Facet, HighlightStyle, NodeProp, PostgreSQL, SelectionRange, StateEffect, StateField, StreamLanguage, Text, Transaction, TreeCursor, ViewPlugin, ViewUpdate, WidgetType, index as autocomplete, bracketMatching, closeBrackets, closeBracketsKeymap, collab, combineConfig, commentKeymap, completionKeymap, defaultHighlightStyle, defaultKeymap, drawSelection, foldGutter, foldKeymap, highlightSelectionMatches, highlightSpecialChars, history, historyKeymap, html, htmlLanguage, indentLess, indentMore, indentOnInput, indentUnit, javascript, javascriptLanguage, julia as julia_andrey, julia$1 as julia_legacy, keymap, lineNumbers, markdown, markdownLanguage, parseMixed, placeholder, python, pythonLanguage, rectangularSelection, searchKeymap, sql, syntaxTree, tags }; +export { Annotation, Compartment, Decoration, EditorSelection, EditorState, EditorView, Facet, HighlightStyle, NodeProp, PostgreSQL, SelectionRange, StateEffect, StateField, StreamLanguage, Text, Transaction, TreeCursor, ViewPlugin, ViewUpdate, WidgetType, index as autocomplete, bracketMatching, closeBrackets, closeBracketsKeymap, collab, combineConfig, commentKeymap, completionKeymap, defaultHighlightStyle, defaultKeymap, drawSelection, foldGutter, foldKeymap, highlightSelectionMatches, highlightSpecialChars, history, historyKeymap, html, htmlLanguage, indentLess, indentMore, indentOnInput, indentUnit, javascript, javascriptLanguage, julia as julia_andrey, julia$1 as julia_legacy, keymap, lineNumbers, markdown, markdownLanguage, parseCode, parseMixed, placeholder, python, pythonLanguage, rectangularSelection, searchKeymap, sql, syntaxTree, tags }; diff --git a/dist/index.es.js b/dist/index.es.js index 2dd071a..5701528 100644 --- a/dist/index.es.js +++ b/dist/index.es.js @@ -24538,11 +24538,16 @@ function resolveConfig(spec) { if (!rest || !conf) return conf || rest; let conc = (a, b) => (a || none).concat(b || none); - return { props: conc(conf.props, rest.props), + let wrapA = conf.wrap, wrapB = rest.wrap; + return { + props: conc(conf.props, rest.props), defineNodes: conc(conf.defineNodes, rest.defineNodes), parseBlock: conc(conf.parseBlock, rest.parseBlock), parseInline: conc(conf.parseInline, rest.parseInline), - remove: conc(conf.remove, rest.remove) }; + remove: conc(conf.remove, rest.remove), + wrap: !wrapA ? wrapB : !wrapB ? wrapA : + (inner, input, fragments, ranges) => wrapA(wrapB(inner, input, fragments, ranges), input, fragments, ranges) + }; } function findName(names, name) { let found = names.indexOf(name); @@ -25073,11 +25078,11 @@ class FragmentCursor { return tree && tree.prop(NodeProp.contextHash) == hash; } takeNodes(cx) { - let cur = this.cursor, off = this.fragment.offset; + let cur = this.cursor, off = this.fragment.offset, fragEnd = this.fragmentEnd - (this.fragment.openEnd ? 1 : 0); let start = cx.absoluteLineStart, end = start, blockI = cx.block.children.length; let prevEnd = end, prevI = blockI; for (;;) { - if (cur.to - off >= this.fragmentEnd) { + if (cur.to - off > fragEnd) { if (cur.type.isAnonymous && cur.firstChild()) continue; break; @@ -27911,4 +27916,4 @@ function collab(config = {}) { return [collabField, collabConfig.of(Object.assign({ generatedID: Math.floor(Math.random() * 1e9).toString(36) }, config))]; } -export { Annotation, Compartment, Decoration, EditorSelection, EditorState, EditorView, Facet, HighlightStyle, NodeProp, PostgreSQL, SelectionRange, StateEffect, StateField, StreamLanguage, Text, Transaction, TreeCursor, ViewPlugin, ViewUpdate, WidgetType, index as autocomplete, bracketMatching, closeBrackets, closeBracketsKeymap, collab, combineConfig, commentKeymap, completionKeymap, defaultHighlightStyle, defaultKeymap, drawSelection, foldGutter, foldKeymap, highlightSelectionMatches, highlightSpecialChars, history, historyKeymap, html, htmlLanguage, indentLess, indentMore, indentOnInput, indentUnit, javascript, javascriptLanguage, julia as julia_andrey, julia$1 as julia_legacy, keymap, lineNumbers, markdown, markdownLanguage, parseMixed, placeholder, python, pythonLanguage, rectangularSelection, searchKeymap, sql, syntaxTree, tags$1 as tags }; +export { Annotation, Compartment, Decoration, EditorSelection, EditorState, EditorView, Facet, HighlightStyle, NodeProp, PostgreSQL, SelectionRange, StateEffect, StateField, StreamLanguage, Text, Transaction, TreeCursor, ViewPlugin, ViewUpdate, WidgetType, index as autocomplete, bracketMatching, closeBrackets, closeBracketsKeymap, collab, combineConfig, commentKeymap, completionKeymap, defaultHighlightStyle, defaultKeymap, drawSelection, foldGutter, foldKeymap, highlightSelectionMatches, highlightSpecialChars, history, historyKeymap, html, htmlLanguage, indentLess, indentMore, indentOnInput, indentUnit, javascript, javascriptLanguage, julia as julia_andrey, julia$1 as julia_legacy, keymap, lineNumbers, markdown, markdownLanguage, parseCode, parseMixed, placeholder, python, pythonLanguage, rectangularSelection, searchKeymap, sql, syntaxTree, tags$1 as tags }; diff --git a/package-lock.json b/package-lock.json index 01b99e6..4768456 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,7 +34,7 @@ "@codemirror/stream-parser": "^0.19.2", "@codemirror/view": "^0.19.9", "@lezer/common": "^0.15.7", - "@lezer/markdown": "^0.15.0", + "@lezer/markdown": "^0.15.3", "@lezer/python": "^0.15.0", "esbuild": "^0.12.28", "lang-julia": "^0.1.0", @@ -574,9 +574,9 @@ } }, "node_modules/@lezer/markdown": { - "version": "0.15.2", - "resolved": "https://registry.npmjs.org/@lezer/markdown/-/markdown-0.15.2.tgz", - "integrity": "sha512-Rimbyk2opxYUPv9VfdnBF6z0qhga2OmdXktBkZ0SGOD0Yuq2Cm6kHXVR92gJ8naRZARGnqWkpDECrXEBWtd6sQ==", + "version": "0.15.3", + "resolved": "https://registry.npmjs.org/@lezer/markdown/-/markdown-0.15.3.tgz", + "integrity": "sha512-Wq9WGO5l4cnRKtJVDuJZtP3YZgCGpeexBhIvzvm4bmSmqqVMMWk+PUu8vX5KejT16wV1iV73EKn4/P/+lUFcFA==", "dependencies": { "@lezer/common": "^0.15.0" } @@ -2784,9 +2784,9 @@ } }, "@lezer/markdown": { - "version": "0.15.2", - "resolved": "https://registry.npmjs.org/@lezer/markdown/-/markdown-0.15.2.tgz", - "integrity": "sha512-Rimbyk2opxYUPv9VfdnBF6z0qhga2OmdXktBkZ0SGOD0Yuq2Cm6kHXVR92gJ8naRZARGnqWkpDECrXEBWtd6sQ==", + "version": "0.15.3", + "resolved": "https://registry.npmjs.org/@lezer/markdown/-/markdown-0.15.3.tgz", + "integrity": "sha512-Wq9WGO5l4cnRKtJVDuJZtP3YZgCGpeexBhIvzvm4bmSmqqVMMWk+PUu8vX5KejT16wV1iV73EKn4/P/+lUFcFA==", "requires": { "@lezer/common": "^0.15.0" } diff --git a/package.json b/package.json index 27d5d4c..df3d814 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "@codemirror/stream-parser": "^0.19.2", "@codemirror/view": "^0.19.9", "@lezer/common": "^0.15.7", - "@lezer/markdown": "^0.15.0", + "@lezer/markdown": "^0.15.3", "@lezer/python": "^0.15.0", "esbuild": "^0.12.28", "lang-julia": "^0.1.0", diff --git a/src/basic-setup.ts b/src/basic-setup.ts index 73e5de1..9d8f882 100644 --- a/src/basic-setup.ts +++ b/src/basic-setup.ts @@ -29,6 +29,7 @@ import { completionKeymap } from "@codemirror/autocomplete" import { commentKeymap } from "@codemirror/comment" import { TreeCursor, NodeProp, parseMixed } from "@lezer/common" import { markdown, markdownLanguage } from "@codemirror/lang-markdown" +import { parseCode } from "@lezer/markdown" import { html, htmlLanguage } from "@codemirror/lang-html" import { javascript, javascriptLanguage } from "@codemirror/lang-javascript" import { sql, PostgreSQL } from "@codemirror/lang-sql" @@ -86,6 +87,7 @@ export { // Syntax Highlighting magic markdown, markdownLanguage, + parseCode, parseMixed, html, htmlLanguage,