diff --git a/docs/readme.md b/docs/readme.md index d660598..2579ec2 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -418,7 +418,7 @@ content: s.markdown() **options**: markdown options - type: `MarkdownOptions` 👇👇👇 -- default: `{ gfm: true, removeComments: true, flattenImage: true }` +- default: `{ gfm: true, removeComments: true }` #### Types @@ -434,11 +434,6 @@ interface MarkdownOptions { * @default true */ removeComments?: boolean - /** - * Flatten image paragraph. - * @default true - */ - flattenImage?: boolean /** * Remark plugins. */ diff --git a/src/plugins/remark-flatten-image.ts b/src/plugins/remark-flatten-image.ts deleted file mode 100644 index 10ec1c3..0000000 --- a/src/plugins/remark-flatten-image.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { visit } from 'unist-util-visit' - -import type { Root } from 'mdast' -import type { Plugin } from 'unified' - -const flattenImage: Plugin<[], Root> = () => tree => { - // https://gitlab.com/staltz/mdast-flatten-image-paragraphs/-/blob/master/index.js - visit(tree, 'paragraph', node => { - if (node.children.length === 1 && node.children[0].type === 'image') { - Object.assign(node, node.children[0], { children: undefined }) - } - }) -} - -export default flattenImage diff --git a/src/shared/markdown.ts b/src/shared/markdown.ts index 69e95cb..79012f6 100644 --- a/src/shared/markdown.ts +++ b/src/shared/markdown.ts @@ -7,7 +7,6 @@ import { unified } from 'unified' import { z } from 'zod' import rehypeCopyLinkedFiles from '../plugins/rehype-copy-linked-files' -import remarkFlattenImage from '../plugins/remark-flatten-image' import remarkRemoveComments from '../plugins/remark-remove-comments' import type { PluggableList } from 'unified' @@ -23,11 +22,6 @@ export interface MarkdownOptions { * @default true */ removeComments?: boolean - /** - * Flatten image paragraph. - * @default true - */ - flattenImage?: boolean /** * Remark plugins. */ @@ -38,12 +32,11 @@ export interface MarkdownOptions { rehypePlugins?: PluggableList } -export const markdown = ({ gfm = true, removeComments = true, flattenImage = true, remarkPlugins, rehypePlugins }: MarkdownOptions = {}) => +export const markdown = ({ gfm = true, removeComments = true, remarkPlugins, rehypePlugins }: MarkdownOptions = {}) => z.string().transform(async (value, ctx) => { const file = unified().use(remarkParse) // parse markdown content to a syntax tree if (gfm) file.use(remarkGfm) // support gfm (autolink literals, footnotes, strikethrough, tables, tasklists). if (removeComments) file.use(remarkRemoveComments) // remove html comments - if (flattenImage) file.use(remarkFlattenImage) // flatten image paragraph if (remarkPlugins != null) file.use(remarkPlugins) // apply remark plugins file.use(remarkRehype, { allowDangerousHtml: true }).use(rehypeRaw) // turn markdown syntax tree to html syntax tree, with raw html support if (rehypePlugins != null) file.use(rehypePlugins) // apply rehype plugins