Research
Recent Trends in Malicious Packages Targeting Discord
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
mdast-util-gfm-table
Advanced tools
Package description
The mdast-util-gfm-table package is a utility to support GitHub Flavored Markdown (GFM) tables in mdast, which is a syntax tree format for Markdown. It allows users to parse and serialize tables in Markdown files following the GFM specification.
Parsing GFM tables
This feature allows you to parse GFM tables from a Markdown string and convert them into an mdast syntax tree. The code sample demonstrates how to use the package in combination with 'mdast-util-from-markdown' to parse a simple table.
import { fromMarkdown } from 'mdast-util-from-markdown';
import { gfmTable } from 'mdast-util-gfm-table';
const markdown = '| Header 1 | Header 2 |\n| -------- | -------- |\n| Cell 1 | Cell 2 |';
const mdastTree = fromMarkdown(markdown, {
extensions: [gfmTable]
});
console.log(mdastTree);
Serializing GFM tables
This feature allows you to serialize an mdast syntax tree containing a GFM table back into a Markdown string. The code sample shows how to use the package with 'mdast-util-to-markdown' to serialize a simple mdast table structure.
import { toMarkdown } from 'mdast-util-to-markdown';
import { gfmTable } from 'mdast-util-gfm-table';
const mdastTree = {
type: 'table',
align: ['left', 'right'],
children: [
{
type: 'tableRow',
children: [
{type: 'tableCell', children: [{type: 'text', value: 'Header 1'}]},
{type: 'tableCell', children: [{type: 'text', value: 'Header 2'}]}
]
},
{
type: 'tableRow',
children: [
{type: 'tableCell', children: [{type: 'text', value: 'Cell 1'}]},
{type: 'tableCell', children: [{type: 'text', value: 'Cell 2'}]}
]
}
]
};
const markdown = toMarkdown(mdastTree, {
extensions: [gfmTable]
});
console.log(markdown);
remark-gfm is a plugin for remark, a Markdown processor powered by plugins part of the unified collective. It adds support for GFM features, including tables. It is similar to mdast-util-gfm-table but is designed to work within the remark ecosystem.
markdown-it is a Markdown parser with GFM table support built-in. It is a full parser, not just a utility for tables, and it is designed to be fast and highly extensible with plugins.
turndown-plugin-gfm is a plugin for Turndown, an HTML to Markdown converter. It adds GFM features, including tables, to the conversion process. It is similar in that it deals with tables in Markdown, but it is for converting from HTML rather than parsing and serializing Markdown directly.
Readme
Extension for mdast-util-from-markdown
and/or
mdast-util-to-markdown
to support GitHub flavored markdown
tables in mdast.
When parsing (from-markdown
), must be combined with
micromark-extension-gfm-table
.
You probably shouldn’t use this package directly, but instead use
remark-gfm
with remark.
npm:
npm install mdast-util-gfm-table
Say we have the following file, example.md
:
| a | b | c | d |
| - | :- | -: | :-: |
| e | f |
| g | h | i | j | k |
And our script, example.js
, looks as follows:
var fs = require('fs')
var fromMarkdown = require('mdast-util-from-markdown')
var toMarkdown = require('mdast-util-to-markdown')
var syntax = require('micromark-extension-gfm-table')
var table = require('mdast-util-gfm-table')
var doc = fs.readFileSync('example.md')
var tree = fromMarkdown(doc, {
extensions: [syntax],
mdastExtensions: [table.fromMarkdown]
})
console.log(tree)
var out = toMarkdown(tree, {extensions: [table.toMarkdown()]})
console.log(out)
Now, running node example
yields (positional info removed for the sake of
brevity):
{
type: 'root',
children: [
{
type: 'table',
align: [null, 'left', 'right', 'center'],
children: [
{
type: 'tableRow',
children: [
{type: 'tableCell', children: [{type: 'text', value: 'a'}]},
{type: 'tableCell', children: [{type: 'text', value: 'b'}]},
{type: 'tableCell', children: [{type: 'text', value: 'c'}]},
{type: 'tableCell', children: [{type: 'text', value: 'd'}]}
]
},
{
type: 'tableRow',
children: [
{type: 'tableCell', children: [{type: 'text', value: 'e'}]},
{type: 'tableCell', children: [{type: 'text', value: 'f'}]}
]
},
{
type: 'tableRow',
children: [
{type: 'tableCell', children: [{type: 'text', value: 'g'}]},
{type: 'tableCell', children: [{type: 'text', value: 'h'}]},
{type: 'tableCell', children: [{type: 'text', value: 'i'}]},
{type: 'tableCell', children: [{type: 'text', value: 'j'}]},
{type: 'tableCell', children: [{type: 'text', value: 'k'}]}
]
}
]
}
]
}
| a | b | c | d | |
| - | :- | -: | :-: | - |
| e | f | | | |
| g | h | i | j | k |
table.fromMarkdown
table.toMarkdown(options?)
Note: the separate extensions are also available at
mdast-util-gfm-table/from-markdown
andmdast-util-gfm-table/to-markdown
.
Support tables.
The exports of fromMarkdown
is an extension for
mdast-util-from-markdown
.
The export of toMarkdown
is a function that can be called with options and
returns an extension for mdast-util-to-markdown
.
options
options.tableCellPadding
Create tables with a space between cell delimiters (|
) and content (boolean
,
default: true
).
options.tablePipeAlign
Align the delimiters (|
) between table cells so that they all align nicely and
form a grid (boolean
, default: true
).
options.stringLength
Function passed to markdown-table
to detect the length of a
table cell (Function
, default: s => s.length
).
Used to pad tables.
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-table
— micromark extension to parse GFM tablessyntax-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 tables
We found that mdast-util-gfm-table 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.
Research
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
Security News
Socket CEO Feross Aboukhadijeh joins a16z partners to discuss how modern, sophisticated supply chain attacks require AI-driven defenses and explore the challenges and solutions in leveraging AI for threat detection early in the development life cycle.
Security News
NIST's new AI Risk Management Framework aims to enhance the security and reliability of generative AI systems and address the unique challenges of malicious AI exploits.