forked from Doist/typist
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add support for literal autolinks (GFM based) (Doist#303)
- Loading branch information
Showing
6 changed files
with
60 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters