MCPcopy Create free account
hub / github.com/editablejs/editable / toMdast

Function toMdast

packages/deserializer/src/markdown.ts:192–236  ·  view source on GitHub ↗
(value: Value, plugins: MarkdownDeserializerPlugin[] = [])

Source from the content-addressed store, hash-verified

190 },
191
192 toMdast(value: Value, plugins: MarkdownDeserializerPlugin[] = []) {
193 const disable = defaultDisable.concat()
194 const extensions: Extension[] = [
195 {
196 disable: {
197 null: disable,
198 },
199 },
200 ]
201
202 const setExtensionsOrDisable = (ext: MarkdownDeserializerExtension) => {
203 if (Array.isArray(ext)) {
204 for (const e of ext) {
205 setExtensionsOrDisable(e)
206 }
207 } else if (typeof ext === 'string') {
208 const index = disable.indexOf(ext)
209 if (index > -1) disable.splice(index, 1)
210 } else {
211 extensions.push(ext)
212 }
213 }
214
215 const mdastExtensions: MarkdownDeserializerMdastExtension[] = []
216
217 const setMdastExtensions = (ext: MarkdownDeserializerMdastExtension) => {
218 if (Array.isArray(ext)) {
219 for (const e of ext) {
220 setMdastExtensions(e)
221 }
222 } else if (!mdastExtensions.some(e => e === ext)) {
223 mdastExtensions.push(ext)
224 }
225 }
226
227 for (const plugin of this._plugins.concat(plugins)) {
228 if (plugin.extensions) setExtensionsOrDisable(plugin.extensions)
229 if (plugin.mdastExtensions) setMdastExtensions(plugin.mdastExtensions)
230 }
231
232 return fromMarkdown(value, {
233 extensions,
234 mdastExtensions,
235 })
236 },
237
238 toMdastWithEditor(editor: Editor, value: Value) {
239 const plugins = MARKDOWN_DESERIALIZER_PLUGINS.get(editor) ?? []

Callers

nothing calls this directly

Calls 2

setExtensionsOrDisableFunction · 0.85
setMdastExtensionsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…