Skip to content

Commit

Permalink
feat: remove built-in platten-listitem
Browse files Browse the repository at this point in the history
  • Loading branch information
zce committed Nov 19, 2023
1 parent 1cb86ee commit 5baa81a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 25 deletions.
15 changes: 0 additions & 15 deletions src/plugins/remark-flatten-listitem.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/plugins/remark-remove-comments.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SKIP, visit } from 'unist-util-visit'
import { visit } from 'unist-util-visit'

import type { Root } from 'mdast'
import type { Plugin } from 'unified'
Expand All @@ -8,7 +8,7 @@ const removeComments: Plugin<[], Root> = () => tree => {
visit(tree, ['html', 'jsx'], (node: any, index, parent: any) => {
if (node.value.match(/<!--([\s\S]*?)-->/g)) {
parent.children.splice(index, 1)
return [SKIP, index] // https://unifiedjs.com/learn/recipe/remove-node/
return ['skip', index] // https://unifiedjs.com/learn/recipe/remove-node/
}
})
}
Expand Down
9 changes: 1 addition & 8 deletions src/shared/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { z } from 'zod'

import rehypeCopyLinkedFiles from '../plugins/rehype-copy-linked-files'
import remarkFlattenImage from '../plugins/remark-flatten-image'
import remarkFlattenListItem from '../plugins/remark-flatten-listitem'
import remarkRemoveComments from '../plugins/remark-remove-comments'

import type { PluggableList } from 'unified'
Expand All @@ -29,11 +28,6 @@ export interface MarkdownOptions {
* @default true
*/
flattenImage?: boolean
/**
* Flatten list item paragraph.
* @default true
*/
flattenListItem?: boolean
/**
* Remark plugins.
*/
Expand All @@ -44,13 +38,12 @@ export interface MarkdownOptions {
rehypePlugins?: PluggableList
}

export const markdown = ({ gfm = true, removeComments = true, flattenImage = true, flattenListItem = true, remarkPlugins, rehypePlugins }: MarkdownOptions = {}) =>
export const markdown = ({ gfm = true, removeComments = true, flattenImage = 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 (flattenListItem) file.use(remarkFlattenListItem) // flatten list item 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
Expand Down

0 comments on commit 5baa81a

Please sign in to comment.