From 2816c18f2176edccb9e3523ecbf1dad76105da5a Mon Sep 17 00:00:00 2001 From: Yuriy Demidov Date: Wed, 5 Jun 2024 17:36:14 +0300 Subject: [PATCH] feat!: transfer connection of markdown-it-attrs plugin to YfmConfigs extension (#263) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - renamed: * `ExtensionDeps.parser` ––> `ExtensionDeps.markupParser` * `ExtensionDeps.parserWithoutAttrs` ––> `ExtensionDeps.textParser` - added ability to apply configureMd() only for one type of parser - renamed YfmDist extension to YfmConfigs - removed usage of markdown-it-attrs plugin from wysiwyg core module - using markdown-it-attrs plugin in YfmConfigs extension via `builder.configureMd()` - you can pass markdown-it-attrs options via `extensionOptions` of `useMarkdownEditor()` hook ```js // old usage useMarkdownEditor({attrs: {/* options of markdown-it-attrs */}}); // new usage useMarkdownEditor({ extensionOptions: { yfmConfigs: {attrs: {/* options of markdown-it-attrs */}}, }, }); ``` --- src/bundle/Editor.ts | 5 +-- src/core/Editor.ts | 27 +++++++------- src/core/ExtensionBuilder.ts | 37 +++++++++++++++++-- src/core/ExtensionsManager.ts | 29 +++++---------- src/core/types/extension.ts | 6 +-- .../base/BaseSchema/BaseSchema.test.ts | 6 ++- .../behavior/Clipboard/clipboard.ts | 6 +-- src/extensions/behavior/Clipboard/index.ts | 4 +- .../markdown/Blockquote/Blockquote.test.ts | 6 ++- src/extensions/markdown/Bold/Bold.test.ts | 6 ++- src/extensions/markdown/Breaks/Breaks.test.ts | 6 ++- src/extensions/markdown/Code/Code.test.ts | 6 ++- .../markdown/CodeBlock/CodeBlock.test.ts | 6 ++- .../markdown/Deflist/Deflist.test.ts | 6 ++- .../markdown/Heading/Heading.test.ts | 6 ++- .../HorizontalRule/HorizontalRule.test.ts | 6 ++- src/extensions/markdown/Html/Html.test.ts | 6 ++- src/extensions/markdown/Image/Image.test.ts | 6 ++- src/extensions/markdown/Italic/Italic.test.ts | 6 ++- src/extensions/markdown/Link/Link.test.ts | 6 ++- src/extensions/markdown/Link/paste-plugin.ts | 2 +- src/extensions/markdown/Link/utils.ts | 2 +- src/extensions/markdown/Lists/Lists.test.ts | 6 ++- src/extensions/markdown/Mark/Mark.test.ts | 6 ++- src/extensions/markdown/Strike/Strike.test.ts | 6 ++- .../markdown/Subscript/Subscript.test.ts | 6 ++- .../markdown/Superscript/Superscript.test.ts | 6 ++- src/extensions/markdown/Table/Table.test.ts | 6 ++- .../markdown/Table/actions/tableActions.ts | 6 +-- .../markdown/Underline/Underline.test.ts | 6 ++- src/extensions/yfm/Checkbox/Checkbox.test.ts | 6 ++- src/extensions/yfm/Color/Color.test.ts | 6 ++- .../yfm/Emoji/EmojiSpecs/EmojiSpecs.test.ts | 6 ++- src/extensions/yfm/ImgSize/YfmImage.test.ts | 6 ++- src/extensions/yfm/Math/Math.test.ts | 6 ++- src/extensions/yfm/Mermaid/Mermaid.test.ts | 6 ++- .../yfm/Monospace/Monospace.test.ts | 6 ++- src/extensions/yfm/Video/Video.test.ts | 6 ++- .../yfm/YfmConfigs/YfmConfigsSpecs/index.ts | 26 +++++++++++++ .../yfm/{YfmDist => YfmConfigs}/index.ts | 10 +++-- .../yfm/{YfmDist => YfmConfigs}/yfm.scss | 0 src/extensions/yfm/YfmCut/YfmCut.test.ts | 6 ++- .../yfm/YfmDist/YfmDistSpecs/index.ts | 11 ------ src/extensions/yfm/YfmFile/YfmFile.test.ts | 6 ++- .../yfm/YfmHeading/YfmHeading.test.ts | 14 +++++-- src/extensions/yfm/YfmNote/YfmNote.test.ts | 6 ++- src/extensions/yfm/YfmTable/YfmTable.test.ts | 6 ++- src/extensions/yfm/YfmTabs/YfmTabs.test.ts | 6 ++- src/extensions/yfm/index.ts | 7 ++-- src/extensions/yfm/specs.ts | 7 ++-- 50 files changed, 287 insertions(+), 110 deletions(-) create mode 100644 src/extensions/yfm/YfmConfigs/YfmConfigsSpecs/index.ts rename src/extensions/yfm/{YfmDist => YfmConfigs}/index.ts (61%) rename src/extensions/yfm/{YfmDist => YfmConfigs}/yfm.scss (100%) delete mode 100644 src/extensions/yfm/YfmDist/YfmDistSpecs/index.ts diff --git a/src/bundle/Editor.ts b/src/bundle/Editor.ts index 19e8393a..4196dbda 100644 --- a/src/bundle/Editor.ts +++ b/src/bundle/Editor.ts @@ -106,7 +106,7 @@ type ChangeEditorModeOptions = { export type EditorOptions = Pick< WysiwygEditorOptions, - 'allowHTML' | 'linkify' | 'linkifyTlds' | 'attrs' | 'extensions' + 'allowHTML' | 'linkify' | 'linkifyTlds' | 'extensions' > & { initialMarkup?: MarkupString; /** @default 'wysiwyg' */ @@ -148,7 +148,6 @@ export class EditorImpl extends SafeEventEmitter implements EditorI #allowHTML?: boolean; #linkify?: boolean; #linkifyTlds?: string | string[]; - #attrs?: WysiwygEditorOptions['attrs']; #extensions?: WysiwygEditorOptions['extensions']; #renderStorage: ReactRenderStorage; #fileUploadHandler?: FileUploadHandler; @@ -238,7 +237,6 @@ export class EditorImpl extends SafeEventEmitter implements EditorI allowHTML: this.#allowHTML, linkify: this.#linkify, linkifyTlds: this.#linkifyTlds, - attrs: this.#attrs, onChange: () => this.emit('rerender-toolbar', null), onDocChange: () => this.emit('change', null), }); @@ -288,7 +286,6 @@ export class EditorImpl extends SafeEventEmitter implements EditorI this.#markup = opts.initialMarkup ?? ''; - this.#attrs = opts.attrs; this.#linkify = opts.linkify; this.#linkifyTlds = opts.linkifyTlds; this.#allowHTML = opts.allowHTML; diff --git a/src/core/Editor.ts b/src/core/Editor.ts index a1029504..8d6ee457 100644 --- a/src/core/Editor.ts +++ b/src/core/Editor.ts @@ -23,11 +23,6 @@ export type WysiwygEditorOptions = { allowHTML?: boolean; linkify?: boolean; linkifyTlds?: string | string[]; - /** markdown-it-attrs options */ - attrs?: { - leftDelimiter?: string; - rightDelimiter?: string; - }; /** Call on any state change (move cursor, change selection, etc...) */ onChange?: OnChange; /** Call only if document change */ @@ -66,20 +61,26 @@ export class WysiwygEditor implements CommonEditor, ActionStorage { domElem, initialContent = '', extensions = () => {}, - attrs: attrsOpts, allowHTML, linkify, linkifyTlds, onChange, onDocChange, }: WysiwygEditorOptions) { - const {schema, parser, serializer, nodeViews, markViews, plugins, rawActions, actions} = - ExtensionsManager.process(extensions, { - // "breaks" option only affects the renderer, but not the parser - mdOpts: {html: allowHTML, linkify, breaks: true}, - attrsOpts: {...attrsOpts, allowedAttributes: ['id']}, - linkifyTlds, - }); + const { + schema, + markupParser: parser, + serializer, + nodeViews, + markViews, + plugins, + rawActions, + actions, + } = ExtensionsManager.process(extensions, { + // "breaks" option only affects the renderer, but not the parser + mdOpts: {html: allowHTML, linkify, breaks: true}, + linkifyTlds, + }); const state = EditorState.create({ schema, diff --git a/src/core/ExtensionBuilder.ts b/src/core/ExtensionBuilder.ts index e0151c03..7e883535 100644 --- a/src/core/ExtensionBuilder.ts +++ b/src/core/ExtensionBuilder.ts @@ -17,6 +17,20 @@ import type {Keymap} from './types/keymap'; type InputRulesConfig = Parameters[0]; type ExtensionWithParams = (builder: ExtensionBuilder, ...params: any[]) => void; +type ConfigureMdParams = { + /** + * Apply this configurtion to text parser + * + * @default true + */ + text?: boolean; + /** + * Apply this configurtion to markup parser + * + * @default true + */ + markup?: boolean; +}; type ConfigureMdCallback = (md: MarkdownIt) => MarkdownIt; type AddPmNodeCallback = () => ExtensionNodeSpec; @@ -64,7 +78,7 @@ export class ExtensionBuilder { readonly PluginPriority = ExtensionBuilder.PluginPriority; /* eslint-enable @typescript-eslint/member-ordering */ - #confMdCbs: ConfigureMdCallback[] = []; + #confMdCbs: {cb: ConfigureMdCallback; params: Required}[] = []; #nodeSpecs: Record = {}; #markSpecs: Record = {}; #plugins: {cb: AddPmPluginCallback; priority: number}[] = []; @@ -83,8 +97,14 @@ export class ExtensionBuilder { return this; } - configureMd(cb: ConfigureMdCallback): this { - this.#confMdCbs.push(cb); + configureMd(cb: ConfigureMdCallback, params: ConfigureMdParams = {}): this { + this.#confMdCbs.push({ + cb, + params: { + text: params.text ?? true, + markup: params.markup ?? true, + }, + }); return this; } @@ -137,7 +157,16 @@ export class ExtensionBuilder { const actions = this.#actions.slice(); return { - configureMd: (md) => confMd.reduce((pMd, cb) => cb(pMd), md), + configureMd: (md, parserType) => + confMd.reduce((pMd, {cb, params}) => { + if (parserType === 'text' && params.text) { + return cb(pMd); + } + if (parserType === 'markup' && params.markup) { + return cb(pMd); + } + return pMd; + }, md), nodes: () => { let map = OrderedMap.from({}); for (const {name, cb} of Object.values(nodes)) { diff --git a/src/core/ExtensionsManager.ts b/src/core/ExtensionsManager.ts index 596f0d0d..b69dad85 100644 --- a/src/core/ExtensionsManager.ts +++ b/src/core/ExtensionsManager.ts @@ -1,5 +1,4 @@ import MarkdownIt from 'markdown-it'; -import attrsPlugin, {AttrsOptions} from 'markdown-it-attrs'; // eslint-disable-line import/no-extraneous-dependencies import type {Plugin} from 'prosemirror-state'; import {ActionsManager} from './ActionsManager'; @@ -24,11 +23,6 @@ type ExtensionsManagerParams = { type ExtensionsManagerOptions = { mdOpts?: MarkdownIt.Options; - attrsOpts?: { - leftDelimiter?: string; - rightDelimiter?: string; - allowedAttributes?: string[]; - }; linkifyTlds?: string | string[]; }; @@ -44,8 +38,8 @@ export class ExtensionsManager { #nodeViewCreators = new Map NodeViewConstructor>(); #markViewCreators = new Map MarkViewConstructor>(); - #md: MarkdownIt; - #mdWithoutAttrs: MarkdownIt; + #mdForMarkup: MarkdownIt; + #mdForText: MarkdownIt; #extensions: Extension; #builder: ExtensionBuilder; @@ -59,15 +53,12 @@ export class ExtensionsManager { constructor({extensions, options = {}}: ExtensionsManagerParams) { this.#extensions = extensions; - this.#md = new MarkdownIt(options.mdOpts ?? {}).use( - attrsPlugin, - options.attrsOpts ?? {}, - ); - this.#mdWithoutAttrs = new MarkdownIt(options.mdOpts ?? {}); + this.#mdForMarkup = new MarkdownIt(options.mdOpts ?? {}); + this.#mdForText = new MarkdownIt(options.mdOpts ?? {}); if (options.linkifyTlds) { - this.#md.linkify.tlds(options.linkifyTlds, true); - this.#mdWithoutAttrs.linkify.tlds(options.linkifyTlds, true); + this.#mdForMarkup.linkify.tlds(options.linkifyTlds, true); + this.#mdForText.linkify.tlds(options.linkifyTlds, true); } // TODO: add prefilled context @@ -97,8 +88,8 @@ export class ExtensionsManager { private processExtensions() { this.#spec = this.#builder.use(this.#extensions).build(); - this.#md = this.#spec.configureMd(this.#md); - this.#mdWithoutAttrs = this.#spec.configureMd(this.#mdWithoutAttrs); + this.#mdForMarkup = this.#spec.configureMd(this.#mdForMarkup, 'markup'); + this.#mdForText = this.#spec.configureMd(this.#mdForText, 'text'); this.#spec.nodes().forEach(this.processNode); this.#spec.marks().forEach(this.processMark); } @@ -126,8 +117,8 @@ export class ExtensionsManager { this.#deps = { schema, actions: new ActionsManager(), - parser: this.#parserRegistry.createParser(schema, this.#md), - parserWithoutAttrs: this.#parserRegistry.createParser(schema, this.#mdWithoutAttrs), + markupParser: this.#parserRegistry.createParser(schema, this.#mdForMarkup), + textParser: this.#parserRegistry.createParser(schema, this.#mdForText), serializer: this.#serializerRegistry.createSerializer(), }; } diff --git a/src/core/types/extension.ts b/src/core/types/extension.ts index 1024f5b8..b91485f9 100644 --- a/src/core/types/extension.ts +++ b/src/core/types/extension.ts @@ -15,7 +15,7 @@ export type ExtensionWithOptions = (builder: ExtensionBuilder, options: T) => export type ExtensionAuto = T extends void ? Extension : ExtensionWithOptions; export type ExtensionSpec = { - configureMd(md: MarkdownIt): MarkdownIt; + configureMd(md: MarkdownIt, parserType: 'text' | 'markup'): MarkdownIt; nodes(): OrderedMap; marks(): OrderedMap; plugins(deps: ExtensionDeps): Plugin[]; @@ -44,8 +44,8 @@ export type ExtensionMarkSpec = { export type ExtensionDeps = { readonly schema: Schema; - readonly parser: Parser; - readonly parserWithoutAttrs: Parser; + readonly textParser: Parser; + readonly markupParser: Parser; readonly serializer: Serializer; readonly actions: ActionStorage; }; diff --git a/src/extensions/base/BaseSchema/BaseSchema.test.ts b/src/extensions/base/BaseSchema/BaseSchema.test.ts index cbed2b19..2c4aea1f 100644 --- a/src/extensions/base/BaseSchema/BaseSchema.test.ts +++ b/src/extensions/base/BaseSchema/BaseSchema.test.ts @@ -5,7 +5,11 @@ import {ExtensionsManager} from '../../../core'; import {BaseNode, BaseSchemaSpecs} from './BaseSchemaSpecs'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSchemaSpecs, {}), }).buildDeps(); diff --git a/src/extensions/behavior/Clipboard/clipboard.ts b/src/extensions/behavior/Clipboard/clipboard.ts index 7036bbac..95268f56 100644 --- a/src/extensions/behavior/Clipboard/clipboard.ts +++ b/src/extensions/behavior/Clipboard/clipboard.ts @@ -14,7 +14,7 @@ import {isInsideCode} from './code'; import {DataTransferType, extractTextContentFromHtml, isIosSafariShare} from './utils'; export type ClipboardPluginOptions = { - yfmParser: Parser; + mdParser: Parser; textParser: Parser; serializer: Serializer; pasteFileHandler?: (file: File) => void; @@ -22,7 +22,7 @@ export type ClipboardPluginOptions = { export const clipboard = ({ textParser, - yfmParser, + mdParser, serializer, pasteFileHandler, }: ClipboardPluginOptions) => { @@ -120,7 +120,7 @@ export const clipboard = ({ let parser: Parser; let dataFormat: string; if (e.clipboardData.types.includes(DataTransferType.Yfm)) { - parser = yfmParser; + parser = mdParser; dataFormat = DataTransferType.Yfm; } else { parser = textParser; diff --git a/src/extensions/behavior/Clipboard/index.ts b/src/extensions/behavior/Clipboard/index.ts index cb85425d..1e2ee8b9 100644 --- a/src/extensions/behavior/Clipboard/index.ts +++ b/src/extensions/behavior/Clipboard/index.ts @@ -11,8 +11,8 @@ export const Clipboard: ExtensionAuto = (builder, opts) => { builder.addPlugin( (deps) => clipboard({ - yfmParser: deps.parser, - textParser: deps.parserWithoutAttrs, + mdParser: deps.markupParser, + textParser: deps.textParser, serializer: deps.serializer, pasteFileHandler: opts.pasteFileHandler, }), diff --git a/src/extensions/markdown/Blockquote/Blockquote.test.ts b/src/extensions/markdown/Blockquote/Blockquote.test.ts index 6a3d747f..0a3defcf 100644 --- a/src/extensions/markdown/Blockquote/Blockquote.test.ts +++ b/src/extensions/markdown/Blockquote/Blockquote.test.ts @@ -7,7 +7,11 @@ import {BaseNode, BaseSpecsPreset} from '../../base/specs'; import {BlockquoteSpecs, blockquoteNodeName} from './BlockquoteSpecs'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(BlockquoteSpecs), }).buildDeps(); diff --git a/src/extensions/markdown/Bold/Bold.test.ts b/src/extensions/markdown/Bold/Bold.test.ts index d90d7f20..390ccc67 100644 --- a/src/extensions/markdown/Bold/Bold.test.ts +++ b/src/extensions/markdown/Bold/Bold.test.ts @@ -7,7 +7,11 @@ import {BaseNode, BaseSpecsPreset} from '../../base/specs'; import {BoldSpecs, boldMarkName} from './BoldSpecs'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(BoldSpecs), }).buildDeps(); diff --git a/src/extensions/markdown/Breaks/Breaks.test.ts b/src/extensions/markdown/Breaks/Breaks.test.ts index 8686fdbc..00b988b4 100644 --- a/src/extensions/markdown/Breaks/Breaks.test.ts +++ b/src/extensions/markdown/Breaks/Breaks.test.ts @@ -8,7 +8,11 @@ import {BoldSpecs, boldMarkName} from '../../markdown/Bold/BoldSpecs'; import {BreakNodeName, BreaksSpecs} from './BreaksSpecs'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(BreaksSpecs, {}).use(BoldSpecs), }).buildDeps(); diff --git a/src/extensions/markdown/Code/Code.test.ts b/src/extensions/markdown/Code/Code.test.ts index e880342a..6e8904f8 100644 --- a/src/extensions/markdown/Code/Code.test.ts +++ b/src/extensions/markdown/Code/Code.test.ts @@ -9,7 +9,11 @@ import {ItalicSpecs, italicMarkName} from '../Italic/ItalicSpecs'; import {CodeSpecs, codeMarkName} from './CodeSpecs'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(BoldSpecs).use(CodeSpecs).use(ItalicSpecs), }).buildDeps(); diff --git a/src/extensions/markdown/CodeBlock/CodeBlock.test.ts b/src/extensions/markdown/CodeBlock/CodeBlock.test.ts index 6a64d8af..bcbafe9e 100644 --- a/src/extensions/markdown/CodeBlock/CodeBlock.test.ts +++ b/src/extensions/markdown/CodeBlock/CodeBlock.test.ts @@ -7,7 +7,11 @@ import {BaseNode, BaseSpecsPreset} from '../../base/specs'; import {CodeBlockNodeAttr, CodeBlockSpecs, codeBlockNodeName} from './CodeBlockSpecs'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(CodeBlockSpecs, {}), }).buildDeps(); diff --git a/src/extensions/markdown/Deflist/Deflist.test.ts b/src/extensions/markdown/Deflist/Deflist.test.ts index afd2ea3b..2c6b5306 100644 --- a/src/extensions/markdown/Deflist/Deflist.test.ts +++ b/src/extensions/markdown/Deflist/Deflist.test.ts @@ -7,7 +7,11 @@ import {BaseNode, BaseSpecsPreset} from '../../base/specs'; import {DeflistNode, DeflistSpecs} from './DeflistSpecs'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(DeflistSpecs, {}), }).buildDeps(); diff --git a/src/extensions/markdown/Heading/Heading.test.ts b/src/extensions/markdown/Heading/Heading.test.ts index 4de0b30c..b37ed93c 100644 --- a/src/extensions/markdown/Heading/Heading.test.ts +++ b/src/extensions/markdown/Heading/Heading.test.ts @@ -9,7 +9,11 @@ import {BoldSpecs, boldMarkName} from '../Bold/BoldSpecs'; import {HeadingSpecs} from './HeadingSpecs'; import {headingLevelAttr, headingNodeName} from './const'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(HeadingSpecs, {}).use(BoldSpecs), }).buildDeps(); diff --git a/src/extensions/markdown/HorizontalRule/HorizontalRule.test.ts b/src/extensions/markdown/HorizontalRule/HorizontalRule.test.ts index 3847d754..6c7e4c71 100644 --- a/src/extensions/markdown/HorizontalRule/HorizontalRule.test.ts +++ b/src/extensions/markdown/HorizontalRule/HorizontalRule.test.ts @@ -11,7 +11,11 @@ import { horizontalRuleNodeName, } from './HorizontalRuleSpecs'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(HorizontalRuleSpecs), }).buildDeps(); diff --git a/src/extensions/markdown/Html/Html.test.ts b/src/extensions/markdown/Html/Html.test.ts index db2e2dd6..2d92f3d0 100644 --- a/src/extensions/markdown/Html/Html.test.ts +++ b/src/extensions/markdown/Html/Html.test.ts @@ -8,7 +8,11 @@ import {HtmlAttr, HtmlNode} from './const'; import {Html} from './index'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSchema, {}).use(Html), options: {mdOpts: {html: true}}, }).buildDeps(); diff --git a/src/extensions/markdown/Image/Image.test.ts b/src/extensions/markdown/Image/Image.test.ts index 9bb76f0a..d4746665 100644 --- a/src/extensions/markdown/Image/Image.test.ts +++ b/src/extensions/markdown/Image/Image.test.ts @@ -6,7 +6,11 @@ import {BaseNode, BaseSpecsPreset} from '../../base/specs'; import {ImageAttr, ImageSpecs, imageNodeName} from './ImageSpecs'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(ImageSpecs), }).buildDeps(); diff --git a/src/extensions/markdown/Italic/Italic.test.ts b/src/extensions/markdown/Italic/Italic.test.ts index 58acbaf8..39a322c5 100644 --- a/src/extensions/markdown/Italic/Italic.test.ts +++ b/src/extensions/markdown/Italic/Italic.test.ts @@ -7,7 +7,11 @@ import {BaseNode, BaseSpecsPreset} from '../../base/specs'; import {ItalicSpecs, italicMarkName} from './ItalicSpecs'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(ItalicSpecs), }).buildDeps(); diff --git a/src/extensions/markdown/Link/Link.test.ts b/src/extensions/markdown/Link/Link.test.ts index daa446ac..9c067804 100644 --- a/src/extensions/markdown/Link/Link.test.ts +++ b/src/extensions/markdown/Link/Link.test.ts @@ -6,7 +6,11 @@ import {BaseNode, BaseSpecsPreset} from '../../base/specs'; import {LinkAttr, LinkSpecs, linkMarkName} from './LinkSpecs'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(LinkSpecs), }).buildDeps(); diff --git a/src/extensions/markdown/Link/paste-plugin.ts b/src/extensions/markdown/Link/paste-plugin.ts index f85942c0..9c72f370 100644 --- a/src/extensions/markdown/Link/paste-plugin.ts +++ b/src/extensions/markdown/Link/paste-plugin.ts @@ -7,7 +7,7 @@ import {imageType} from '../Image'; import {LinkAttr, linkType} from './index'; -export function linkPasteEnhance({parser}: ExtensionDeps) { +export function linkPasteEnhance({markupParser: parser}: ExtensionDeps) { return new Plugin({ props: { handleDOMEvents: { diff --git a/src/extensions/markdown/Link/utils.ts b/src/extensions/markdown/Link/utils.ts index 89e4e940..7fc493cb 100644 --- a/src/extensions/markdown/Link/utils.ts +++ b/src/extensions/markdown/Link/utils.ts @@ -4,7 +4,7 @@ const isString = (str: unknown): str is string => typeof str === 'string'; const notEmpty = (str: string): boolean => str.length > 0; export const normalizeUrlFactory = - ({parser}: ExtensionDeps) => + ({markupParser: parser}: ExtensionDeps) => (url: string) => { if (isString(url)) { url = url.trim(); diff --git a/src/extensions/markdown/Lists/Lists.test.ts b/src/extensions/markdown/Lists/Lists.test.ts index 9e2e747f..d41be985 100644 --- a/src/extensions/markdown/Lists/Lists.test.ts +++ b/src/extensions/markdown/Lists/Lists.test.ts @@ -6,7 +6,11 @@ import {BaseNode, BaseSpecsPreset} from '../../base/specs'; import {ListNode, ListsSpecs} from './ListsSpecs'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(ListsSpecs), }).buildDeps(); diff --git a/src/extensions/markdown/Mark/Mark.test.ts b/src/extensions/markdown/Mark/Mark.test.ts index edb2757a..539bf960 100644 --- a/src/extensions/markdown/Mark/Mark.test.ts +++ b/src/extensions/markdown/Mark/Mark.test.ts @@ -7,7 +7,11 @@ import {BaseNode, BaseSpecsPreset} from '../../base/specs'; import {MarkSpecs, markMarkName} from './MarkSpecs'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(MarkSpecs), }).buildDeps(); diff --git a/src/extensions/markdown/Strike/Strike.test.ts b/src/extensions/markdown/Strike/Strike.test.ts index e1d98c97..b49dbba5 100644 --- a/src/extensions/markdown/Strike/Strike.test.ts +++ b/src/extensions/markdown/Strike/Strike.test.ts @@ -7,7 +7,11 @@ import {BaseNode, BaseSpecsPreset} from '../../base/specs'; import {StrikeSpecs, strikeMarkName} from './StrikeSpecs'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(StrikeSpecs), }).buildDeps(); diff --git a/src/extensions/markdown/Subscript/Subscript.test.ts b/src/extensions/markdown/Subscript/Subscript.test.ts index d7415ecd..b0658853 100644 --- a/src/extensions/markdown/Subscript/Subscript.test.ts +++ b/src/extensions/markdown/Subscript/Subscript.test.ts @@ -7,7 +7,11 @@ import {BaseNode, BaseSpecsPreset} from '../../base/specs'; import {SubscriptSpecs, subscriptMarkName} from './SubscriptSpecs'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(SubscriptSpecs), }).buildDeps(); diff --git a/src/extensions/markdown/Superscript/Superscript.test.ts b/src/extensions/markdown/Superscript/Superscript.test.ts index 5d9493e7..f19d330f 100644 --- a/src/extensions/markdown/Superscript/Superscript.test.ts +++ b/src/extensions/markdown/Superscript/Superscript.test.ts @@ -7,7 +7,11 @@ import {BaseNode, BaseSpecsPreset} from '../../base/specs'; import {SuperscriptSpecs, superscriptMarkName} from './SuperscriptSpecs'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(SuperscriptSpecs), }).buildDeps(); diff --git a/src/extensions/markdown/Table/Table.test.ts b/src/extensions/markdown/Table/Table.test.ts index 064eb8cc..42a3c58e 100644 --- a/src/extensions/markdown/Table/Table.test.ts +++ b/src/extensions/markdown/Table/Table.test.ts @@ -9,7 +9,11 @@ import {BlockquoteSpecs, blockquoteNodeName} from '../Blockquote/BlockquoteSpecs import {TableSpecs} from './TableSpecs'; import {CellAlign, TableAttrs, TableNode} from './const'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(BlockquoteSpecs).use(TableSpecs), }).buildDeps(); diff --git a/src/extensions/markdown/Table/actions/tableActions.ts b/src/extensions/markdown/Table/actions/tableActions.ts index 8d53002e..d9229e73 100644 --- a/src/extensions/markdown/Table/actions/tableActions.ts +++ b/src/extensions/markdown/Table/actions/tableActions.ts @@ -39,10 +39,10 @@ const removeTable: Command = (state, dispatch) => { return false; }; -export const createTableAction = ({parser}: ExtensionDeps): ActionSpec => ({ +export const createTableAction = ({markupParser}: ExtensionDeps): ActionSpec => ({ isActive: isIntoTable, - isEnable: createTableFactory(parser), - run: createTableFactory(parser), + isEnable: createTableFactory(markupParser), + run: createTableFactory(markupParser), }); export const deleteTableAction: ActionSpec = { diff --git a/src/extensions/markdown/Underline/Underline.test.ts b/src/extensions/markdown/Underline/Underline.test.ts index 515d25e7..bdd53999 100644 --- a/src/extensions/markdown/Underline/Underline.test.ts +++ b/src/extensions/markdown/Underline/Underline.test.ts @@ -7,7 +7,11 @@ import {BaseNode, BaseSpecsPreset} from '../../base/specs'; import {UnderlineSpecs, underlineMarkName} from './UnderlineSpecs'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(UnderlineSpecs), }).buildDeps(); diff --git a/src/extensions/yfm/Checkbox/Checkbox.test.ts b/src/extensions/yfm/Checkbox/Checkbox.test.ts index 0b8a99c6..99e42edc 100644 --- a/src/extensions/yfm/Checkbox/Checkbox.test.ts +++ b/src/extensions/yfm/Checkbox/Checkbox.test.ts @@ -7,7 +7,11 @@ import {BoldSpecs, boldMarkName} from '../../markdown/specs'; import {CheckboxNode, CheckboxSpecs} from './CheckboxSpecs'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder .use(BaseSpecsPreset, {}) diff --git a/src/extensions/yfm/Color/Color.test.ts b/src/extensions/yfm/Color/Color.test.ts index 7cf67362..b7d5b72a 100644 --- a/src/extensions/yfm/Color/Color.test.ts +++ b/src/extensions/yfm/Color/Color.test.ts @@ -7,7 +7,11 @@ import {BaseNode, BaseSpecsPreset} from '../../base/specs'; import {ColorSpecs, colorMarkName} from './ColorSpecs'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(ColorSpecs, { validateClassNameColorName: (color) => color !== 'something', diff --git a/src/extensions/yfm/Emoji/EmojiSpecs/EmojiSpecs.test.ts b/src/extensions/yfm/Emoji/EmojiSpecs/EmojiSpecs.test.ts index 8ec04ce9..5a735d6c 100644 --- a/src/extensions/yfm/Emoji/EmojiSpecs/EmojiSpecs.test.ts +++ b/src/extensions/yfm/Emoji/EmojiSpecs/EmojiSpecs.test.ts @@ -6,7 +6,11 @@ import {BaseNode, BaseSpecsPreset} from '../../../../extensions/specs'; import {EmojiSpecs} from './EmojiSpecs'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(EmojiSpecs, {defs: {ddd: 'x'}}), }).buildDeps(); diff --git a/src/extensions/yfm/ImgSize/YfmImage.test.ts b/src/extensions/yfm/ImgSize/YfmImage.test.ts index 8ad15dfc..81079f76 100644 --- a/src/extensions/yfm/ImgSize/YfmImage.test.ts +++ b/src/extensions/yfm/ImgSize/YfmImage.test.ts @@ -7,7 +7,11 @@ import {BaseNode, BaseSchema} from '../../base/BaseSchema'; import {ImgSizeSpecs} from './ImgSizeSpecs'; import {ImgSizeAttr, imageNodeName} from './const'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSchema, {}).use(ImgSizeSpecs, {}), }).buildDeps(); diff --git a/src/extensions/yfm/Math/Math.test.ts b/src/extensions/yfm/Math/Math.test.ts index 74078188..118ebd81 100644 --- a/src/extensions/yfm/Math/Math.test.ts +++ b/src/extensions/yfm/Math/Math.test.ts @@ -6,7 +6,11 @@ import {BaseNode, BaseSpecsPreset} from '../../base/specs'; import {MathNode, MathSpecs} from './MathSpecs'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(MathSpecs), }).buildDeps(); diff --git a/src/extensions/yfm/Mermaid/Mermaid.test.ts b/src/extensions/yfm/Mermaid/Mermaid.test.ts index d7a15e0f..ee1f96a5 100644 --- a/src/extensions/yfm/Mermaid/Mermaid.test.ts +++ b/src/extensions/yfm/Mermaid/Mermaid.test.ts @@ -7,7 +7,11 @@ import {BaseNode, BaseSpecsPreset} from '../../../extensions/specs'; import {MermaidSpecs} from './MermaidSpecs'; import {MermaidAttrs, mermaidNodeName} from './const'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(MermaidSpecs, {}), }).buildDeps(); diff --git a/src/extensions/yfm/Monospace/Monospace.test.ts b/src/extensions/yfm/Monospace/Monospace.test.ts index 933d81ab..329961be 100644 --- a/src/extensions/yfm/Monospace/Monospace.test.ts +++ b/src/extensions/yfm/Monospace/Monospace.test.ts @@ -7,7 +7,11 @@ import {BaseNode, BaseSpecsPreset} from '../../base/specs'; import {MonospaceSpecs, monospaceMarkName} from './MonospaceSpecs'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(MonospaceSpecs), }).buildDeps(); diff --git a/src/extensions/yfm/Video/Video.test.ts b/src/extensions/yfm/Video/Video.test.ts index 4eacddf3..554d35e5 100644 --- a/src/extensions/yfm/Video/Video.test.ts +++ b/src/extensions/yfm/Video/Video.test.ts @@ -8,7 +8,11 @@ import {VideoSpecs} from './VideoSpecs'; import {VideoAttr, videoNodeName} from './VideoSpecs/const'; import {VideoService} from './VideoSpecs/md-video'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(VideoSpecs, {}), }).buildDeps(); diff --git a/src/extensions/yfm/YfmConfigs/YfmConfigsSpecs/index.ts b/src/extensions/yfm/YfmConfigs/YfmConfigsSpecs/index.ts new file mode 100644 index 00000000..774d2ea2 --- /dev/null +++ b/src/extensions/yfm/YfmConfigs/YfmConfigsSpecs/index.ts @@ -0,0 +1,26 @@ +import attrsPlugin, {AttrsOptions} from 'markdown-it-attrs'; // eslint-disable-line import/no-extraneous-dependencies + +import type {ExtensionAuto} from '../../../../core'; +import {noop} from '../../../../lodash'; + +const defaultAttrsOpts: AttrsOptions = { + allowedAttributes: ['id'], +}; + +export type YfmConfigsSpecsOptions = { + /** markdown-it-attrs options */ + attrs?: AttrsOptions; +}; + +export const YfmConfigsSpecs: ExtensionAuto = (builder, opts) => { + const attrsOpts = {...defaultAttrsOpts, ...opts.attrs}; + + builder.configureMd((md) => md.use(attrsPlugin, attrsOpts), {text: false}); + + // ignore yfm lint token + builder.addNode('__yfm_lint', () => ({ + spec: {}, + fromMd: {tokenSpec: {name: '__yfm_lint', type: 'node', ignore: true}}, + toMd: noop, + })); +}; diff --git a/src/extensions/yfm/YfmDist/index.ts b/src/extensions/yfm/YfmConfigs/index.ts similarity index 61% rename from src/extensions/yfm/YfmDist/index.ts rename to src/extensions/yfm/YfmConfigs/index.ts index eec9d205..5e5869e3 100644 --- a/src/extensions/yfm/YfmDist/index.ts +++ b/src/extensions/yfm/YfmConfigs/index.ts @@ -3,14 +3,16 @@ import {Plugin} from 'prosemirror-state'; import type {ExtensionAuto} from '../../../core'; -import {YfmDistSpecs} from './YfmDistSpecs'; +import {YfmConfigsSpecs, YfmConfigsSpecsOptions} from './YfmConfigsSpecs'; import '@diplodoc/transform/dist/css/yfm.css'; import './yfm.scss'; // eslint-disable-line import/order -export const YfmDist: ExtensionAuto = (builder) => { - // ignore yfm lint token - builder.use(YfmDistSpecs); +export type YfmConfigsOptions = YfmConfigsSpecsOptions & {}; + +export const YfmConfigs: ExtensionAuto = (builder, opts) => { + // apply md-it-attrs plugin and ignore yfm lint token + builder.use(YfmConfigsSpecs, opts); builder.addPlugin( () => diff --git a/src/extensions/yfm/YfmDist/yfm.scss b/src/extensions/yfm/YfmConfigs/yfm.scss similarity index 100% rename from src/extensions/yfm/YfmDist/yfm.scss rename to src/extensions/yfm/YfmConfigs/yfm.scss diff --git a/src/extensions/yfm/YfmCut/YfmCut.test.ts b/src/extensions/yfm/YfmCut/YfmCut.test.ts index 858e7a91..a73890c4 100644 --- a/src/extensions/yfm/YfmCut/YfmCut.test.ts +++ b/src/extensions/yfm/YfmCut/YfmCut.test.ts @@ -16,7 +16,11 @@ import { import {CutNode, YfmCutSpecs} from './YfmCutSpecs'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder .use(BaseSpecsPreset, {}) diff --git a/src/extensions/yfm/YfmDist/YfmDistSpecs/index.ts b/src/extensions/yfm/YfmDist/YfmDistSpecs/index.ts deleted file mode 100644 index b9cdc7c1..00000000 --- a/src/extensions/yfm/YfmDist/YfmDistSpecs/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -import type {ExtensionAuto} from '../../../../core'; -import {noop} from '../../../../lodash'; - -export const YfmDistSpecs: ExtensionAuto = (builder) => { - // ignore yfm lint token - builder.addNode('__yfm_lint', () => ({ - spec: {}, - fromMd: {tokenSpec: {name: '__yfm_lint', type: 'node', ignore: true}}, - toMd: noop, - })); -}; diff --git a/src/extensions/yfm/YfmFile/YfmFile.test.ts b/src/extensions/yfm/YfmFile/YfmFile.test.ts index 160285e9..3eb1bc4e 100644 --- a/src/extensions/yfm/YfmFile/YfmFile.test.ts +++ b/src/extensions/yfm/YfmFile/YfmFile.test.ts @@ -7,7 +7,11 @@ import {BaseNode, BaseSpecsPreset} from '../../base/specs'; import {YfmFileSpecs, yfmFileNodeName} from './YfmFileSpecs'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(YfmFileSpecs), }).buildDeps(); diff --git a/src/extensions/yfm/YfmHeading/YfmHeading.test.ts b/src/extensions/yfm/YfmHeading/YfmHeading.test.ts index 1ae30426..a8c02669 100644 --- a/src/extensions/yfm/YfmHeading/YfmHeading.test.ts +++ b/src/extensions/yfm/YfmHeading/YfmHeading.test.ts @@ -5,13 +5,21 @@ import {createMarkupChecker} from '../../../../tests/sameMarkup'; import {ExtensionsManager} from '../../../core'; import {BaseNode, BaseSpecsPreset} from '../../base/specs'; import {BoldSpecs, boldMarkName, headingNodeName} from '../../markdown/specs'; +import {YfmConfigsSpecs} from '../specs'; import {YfmHeadingAttr, YfmHeadingSpecs} from './YfmHeadingSpecs'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => - builder.use(BaseSpecsPreset, {}).use(YfmHeadingSpecs, {}).use(BoldSpecs), - options: {attrsOpts: {allowedAttributes: ['id']}}, + builder + .use(BaseSpecsPreset, {}) + .use(YfmConfigsSpecs, {attrs: {allowedAttributes: ['id']}}) + .use(YfmHeadingSpecs, {}) + .use(BoldSpecs), }).buildDeps(); const {doc, b, p, h, h1, h2, h3, h4, h5, h6} = builders< diff --git a/src/extensions/yfm/YfmNote/YfmNote.test.ts b/src/extensions/yfm/YfmNote/YfmNote.test.ts index c3d0ed75..86a87e09 100644 --- a/src/extensions/yfm/YfmNote/YfmNote.test.ts +++ b/src/extensions/yfm/YfmNote/YfmNote.test.ts @@ -17,7 +17,11 @@ import { import {YfmNoteSpecs} from './YfmNoteSpecs'; import {NoteAttrs, NoteNode} from './const'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder .use(BaseSpecsPreset, {}) diff --git a/src/extensions/yfm/YfmTable/YfmTable.test.ts b/src/extensions/yfm/YfmTable/YfmTable.test.ts index d5f215d3..9593a93c 100644 --- a/src/extensions/yfm/YfmTable/YfmTable.test.ts +++ b/src/extensions/yfm/YfmTable/YfmTable.test.ts @@ -12,7 +12,11 @@ import {BlockquoteSpecs, blockquoteNodeName} from '../../markdown/Blockquote/Blo import {YfmTableNode, YfmTableSpecs} from './YfmTableSpecs'; import {fixPastedTableBodies} from './paste'; -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(BlockquoteSpecs).use(YfmTableSpecs, {}), }).build(); diff --git a/src/extensions/yfm/YfmTabs/YfmTabs.test.ts b/src/extensions/yfm/YfmTabs/YfmTabs.test.ts index f844374d..6ecca558 100644 --- a/src/extensions/yfm/YfmTabs/YfmTabs.test.ts +++ b/src/extensions/yfm/YfmTabs/YfmTabs.test.ts @@ -18,7 +18,11 @@ afterEach(() => { jest.spyOn(global.Math, 'random').mockRestore(); }); -const {schema, parser, serializer} = new ExtensionsManager({ +const { + schema, + markupParser: parser, + serializer, +} = new ExtensionsManager({ extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(BlockquoteSpecs).use(YfmTabsSpecs, {}), }).buildDeps(); diff --git a/src/extensions/yfm/index.ts b/src/extensions/yfm/index.ts index 4065fa24..a0b7b7d0 100644 --- a/src/extensions/yfm/index.ts +++ b/src/extensions/yfm/index.ts @@ -5,8 +5,8 @@ import {Color} from './Color'; import {ImgSize, ImgSizeOptions} from './ImgSize'; import {Monospace} from './Monospace'; import {Video, VideoOptions} from './Video'; +import {YfmConfigs, YfmConfigsOptions} from './YfmConfigs'; import {YfmCut, YfmCutOptions} from './YfmCut'; -import {YfmDist} from './YfmDist'; import {YfmFile, YfmFileOptions} from './YfmFile'; import {YfmHeading, YfmHeadingOptions} from './YfmHeading'; import {YfmNote, YfmNoteOptions} from './YfmNote'; @@ -19,7 +19,7 @@ export * from './ImgSize'; export * from './Monospace'; export * from './Video'; export * from './YfmCut'; -export * from './YfmDist'; +export * from './YfmConfigs'; export * from './YfmFile'; export * from './YfmHeading'; export * from './YfmNote'; @@ -30,6 +30,7 @@ export type YfmPresetOptions = { checkbox?: CheckboxOptions; imgSize?: ImgSizeOptions; video?: VideoOptions; + yfmConfigs?: YfmConfigsOptions; yfmCut?: YfmCutOptions; yfmFile?: YfmFileOptions; yfmHeading?: YfmHeadingOptions; @@ -44,7 +45,7 @@ export const YfmPreset: ExtensionAuto = (builder, opts) => { .use(ImgSize, opts.imgSize ?? {}) .use(Monospace) .use(Video, opts.video ?? {}) - .use(YfmDist) + .use(YfmConfigs, opts.yfmConfigs ?? {}) .use(YfmCut, opts.yfmCut ?? {}) .use(YfmNote, opts.yfmNote ?? {}) .use(YfmFile, opts.yfmFile ?? {}) diff --git a/src/extensions/yfm/specs.ts b/src/extensions/yfm/specs.ts index 84f1b417..4cd875fb 100644 --- a/src/extensions/yfm/specs.ts +++ b/src/extensions/yfm/specs.ts @@ -5,8 +5,8 @@ import {ColorSpecs, ColorSpecsOptions} from './Color/ColorSpecs'; import {ImgSizeSpecs, ImgSizeSpecsOptions} from './ImgSize/ImgSizeSpecs'; import {MonospaceSpecs} from './Monospace/MonospaceSpecs'; import {VideoSpecs, VideoSpecsOptions} from './Video/VideoSpecs'; +import {YfmConfigsSpecs, YfmConfigsSpecsOptions} from './YfmConfigs/YfmConfigsSpecs'; import {YfmCutSpecs, YfmCutSpecsOptions} from './YfmCut/YfmCutSpecs'; -import {YfmDistSpecs} from './YfmDist/YfmDistSpecs'; import {YfmFileSpecs} from './YfmFile/YfmFileSpecs'; import {YfmHeadingSpecs, YfmHeadingSpecsOptions} from './YfmHeading/YfmHeadingSpecs'; import {YfmNoteSpecs, YfmNoteSpecsOptions} from './YfmNote/YfmNoteSpecs'; @@ -18,7 +18,7 @@ export * from './Color/ColorSpecs'; export * from './ImgSize/ImgSizeSpecs'; export * from './Monospace/MonospaceSpecs'; export * from './Video/VideoSpecs'; -export * from './YfmDist/YfmDistSpecs'; +export * from './YfmConfigs/YfmConfigsSpecs'; export * from './YfmCut/YfmCutSpecs'; export * from './YfmFile/YfmFileSpecs'; export * from './YfmHeading/YfmHeadingSpecs'; @@ -31,6 +31,7 @@ export type YfmSpecsPresetOptions = { color?: ColorSpecsOptions; video?: VideoSpecsOptions; imgSize?: ImgSizeSpecsOptions; + yfmConfigs?: YfmConfigsSpecsOptions; yfmCut?: YfmCutSpecsOptions; yfmNote?: YfmNoteSpecsOptions; yfmTable?: YfmTableSpecsOptions; @@ -45,7 +46,7 @@ export const YfmSpecsPreset: ExtensionAuto = (builder, op .use(ImgSizeSpecs, opts.imgSize ?? {}) .use(MonospaceSpecs) .use(VideoSpecs, opts.video ?? {}) - .use(YfmDistSpecs) + .use(YfmConfigsSpecs, opts.yfmConfigs ?? {}) .use(YfmCutSpecs, opts.yfmCut ?? {}) .use(YfmNoteSpecs, opts.yfmNote ?? {}) .use(YfmFileSpecs)