Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
mdast-util-gfm-autolink-literal
Advanced tools
mdast extension to parse and serialize GFM autolink literals
The mdast-util-gfm-autolink-literal npm package is a utility to support GitHub Flavored Markdown (GFM) autolink literals in mdast syntax trees. It helps parse and serialize autolink literals like URLs and email addresses directly in Markdown documents, making them clickable links without additional markup.
Parsing GFM Autolink Literals
This code sample demonstrates how to set up a processor using Unified with the remark-parse and remark-gfm plugins, enhanced by mdast-util-gfm-autolink-literal to automatically parse URLs written in plain text as autolink literals in the Markdown document.
import { unified } from 'unified';
import markdown from 'remark-parse';
import gfm from 'remark-gfm';
import gfmAutolinkLiteral from 'mdast-util-gfm-autolink-literal';
const processor = unified()
.use(markdown)
.use(gfm)
.use(gfmAutolinkLiteral);
const tree = processor.parse('See https://example.com for more info.');
console.log(tree);
This package is a plugin for remark that supports all GFM features, including autolinks, tables, strikethrough, and task lists. It is broader in scope compared to mdast-util-gfm-autolink-literal, which specifically focuses on autolink literals.
Similar to mdast-util-gfm-autolink-literal, this package is a micromark extension to parse and serialize GFM autolink literals. It serves a similar purpose but is used in the micromark ecosystem, which is the underlying system for remark.
Extension for mdast-util-from-markdown
and/or
mdast-util-to-markdown
to support GitHub flavored markdown
autolink literals in mdast.
When parsing (from-markdown
), must be combined with
micromark-extension-gfm-autolink-literal
.
Use mdast-util-gfm
if you want all of GFM.
Use this otherwise.
This package is ESM only:
Node 12+ is needed to use it and it must be import
ed instead of require
d.
npm:
npm install mdast-util-gfm-autolink-literal
Say our module, example.js
, looks as follows:
import {fromMarkdown} from 'mdast-util-from-markdown'
import {toMarkdown} from 'mdast-util-to-markdown'
import {gfmAutolinkLiteral} from 'micromark-extension-gfm-autolink-literal'
import {gfmAutolinkLiteralFromMarkdown, gfmAutolinkLiteralToMarkdown} from 'mdast-util-gfm-autolink-literal'
const doc = 'www.example.com, https://example.com, and contact@example.com.'
const tree = fromMarkdown(doc, {
extensions: [gfmAutolinkLiteral],
mdastExtensions: [gfmAutolinkLiteralFromMarkdown]
})
console.log(tree)
const out = toMarkdown(tree, {extensions: [gfmAutolinkLiteralToMarkdown]})
console.log(out)
Now, running node example
yields:
{
type: 'root',
children: [
{
type: 'paragraph',
children: [
{
type: 'link',
title: null,
url: 'http://www.example.com',
children: [{type: 'text', value: 'www.example.com'}]
},
{type: 'text', value: ', '},
{
type: 'link',
title: null,
url: 'https://example.com',
children: [{type: 'text', value: 'https://example.com'}]
},
{type: 'text', value: ', and '},
{
type: 'link',
title: null,
url: 'mailto:contact@example.com',
children: [{type: 'text', value: 'contact@example.com'}]
},
{type: 'text', value: '.'}
]
}
]
}
[www.example.com](http://www.example.com), <https://example.com>, and <contact@example.com>.
gfmAutolinkLiteralFromMarkdown
gfmAutolinkLiteralToMarkdown
Support literal autolinks.
The exports are extensions, respectively
for mdast-util-from-markdown
and
mdast-util-to-markdown
.
remarkjs/remark
— markdown processor powered by pluginsremarkjs/remark-gfm
— remark plugin to support GFMmicromark/micromark
— the smallest commonmark-compliant markdown parser that existsmicromark/micromark-extension-gfm-autolink-literal
— micromark extension to parse GFM autolink literalssyntax-tree/mdast-util-from-markdown
— mdast parser using micromark
to create mdast from markdownsyntax-tree/mdast-util-to-markdown
— mdast serializer to create markdown from mdastSee contributing.md
in syntax-tree/.github
for ways to get
started.
See support.md
for ways to get help.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
FAQs
mdast extension to parse and serialize GFM autolink literals
The npm package mdast-util-gfm-autolink-literal receives a total of 3,023,093 weekly downloads. As such, mdast-util-gfm-autolink-literal popularity was classified as popular.
We found that mdast-util-gfm-autolink-literal demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.