From da310beb5d3fd128183ef24fc80980679cd0bb3d Mon Sep 17 00:00:00 2001 From: jerrywcy Date: Sat, 26 Aug 2023 21:47:04 +0800 Subject: [PATCH] feat: remove autolink --- src/serializers/html/html.test.ts | 4 +-- src/serializers/html/html.ts | 7 ---- .../html/plugins/remark-autolink-literal.ts | 36 ------------------- 3 files changed, 2 insertions(+), 45 deletions(-) delete mode 100644 src/serializers/html/plugins/remark-autolink-literal.ts diff --git a/src/serializers/html/html.test.ts b/src/serializers/html/html.test.ts index f838db01..9698b17f 100644 --- a/src/serializers/html/html.test.ts +++ b/src/serializers/html/html.test.ts @@ -494,13 +494,13 @@ Answer: [Doist Frontend](channel://190200)`), test('links HTML output is correct', () => { expect(htmlSerializer.serialize(MARKDOWN_INPUT_LINKS)).toBe( - '

My favorite search engine is Duck Duck Go.
My favorite search engine is Duck Duck Go.
My favorite search engine is https://duckduckgo.com.

', + '

My favorite search engine is Duck Duck Go.
My favorite search engine is Duck Duck Go.
My favorite search engine is https://duckduckgo.com.

', ) }) test('styled links HTML output is correct', () => { expect(htmlSerializer.serialize(MARKDOWN_INPUT_STYLED_LINKS)).toBe( - '

I love supporting the EFF.
I love supporting the https://eff.org.
This is the Markdown Guide.
This is the https://www.markdownguide.org.
See the section on code.

', + '

I love supporting the EFF.
I love supporting the https://eff.org.
This is the Markdown Guide.
This is the https://www.markdownguide.org.
See the section on code.

', ) }) }) diff --git a/src/serializers/html/html.ts b/src/serializers/html/html.ts index fb049c04..f5e11229 100644 --- a/src/serializers/html/html.ts +++ b/src/serializers/html/html.ts @@ -12,7 +12,6 @@ import { rehypeCodeBlock } from './plugins/rehype-code-block' import { rehypeImage } from './plugins/rehype-image' import { rehypeSuggestions } from './plugins/rehype-suggestions' import { rehypeTaskList } from './plugins/rehype-task-list' -import { remarkAutolinkLiteral } from './plugins/remark-autolink-literal' import { remarkDisableConstructs } from './plugins/remark-disable-constructs' import { remarkStrikethrough } from './plugins/remark-strikethrough' @@ -107,12 +106,6 @@ function createHTMLSerializer(schema: Schema): HTMLSerializerReturnType { unifiedProcessor.use(remarkStrikethrough) } - // Configure the unified processor to use a custom plugin to add support for the autolink - // literals extension from the GitHub Flavored Markdown (GFM) specification - if (schema.marks.link) { - unifiedProcessor.use(remarkAutolinkLiteral) - } - // Configure the unified processor with an official plugin to convert Markdown into HTML to // support rehype (a tool that transforms HTML with plugins), followed by another official // plugin to minify whitespace between tags (prevents line feeds from appearing as blank) diff --git a/src/serializers/html/plugins/remark-autolink-literal.ts b/src/serializers/html/plugins/remark-autolink-literal.ts deleted file mode 100644 index ec2202cb..00000000 --- a/src/serializers/html/plugins/remark-autolink-literal.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { - gfmAutolinkLiteralFromMarkdown, - gfmAutolinkLiteralToMarkdown, -} from 'mdast-util-gfm-autolink-literal' -import { gfmAutolinkLiteral } from 'micromark-extension-gfm-autolink-literal' - -import type { Processor } from 'unified' - -/** - * A remark plugin to add support for the autolink literals extension extension from the GitHub - * Flavored Markdown (GFM) specification. - * - * This is an standalone plugin which makes use of both the `mdast-util-gfm-autolink-literal` and - * `micromark-extension-gfm-autolink-literal` packages, and the implementation is inspired by the - * third-party `remark-gfm` plugin. - * - * The reason why we don't use `remark-gfm` directly is because we don't want to support all other - * GFM features (footnotes, tables, tagfilter, and tasklists). - * - * @param options Configuration options for the plugin. - */ -function remarkAutolinkLiteral(this: Processor) { - const data = this.data() - - function add(field: string, value: unknown) { - const list = (data[field] ? data[field] : (data[field] = [])) as unknown[] - - list.push(value) - } - - add('micromarkExtensions', gfmAutolinkLiteral) - add('fromMarkdownExtensions', gfmAutolinkLiteralFromMarkdown()) - add('toMarkdownExtensions', gfmAutolinkLiteralToMarkdown()) -} - -export { remarkAutolinkLiteral }