![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
mdast is a markdown parser and stringifier for multipurpose analysis in JavaScript. Node and the browser. Lots of tests. 100% coverage.
It’s not just another markdown to HTML compiler. mdast can generate markdown too, which enables plug-ins (and you) to change your Readme.md, or lint the JavaScript in your markdown.
npm:
$ npm install mdast
$ component install wooorm/mdast
$ bower install mdast
Duo:
var mdast = require('wooorm/mdast');
UMD (globals/AMD/CommonJS) (uncompressed and compressed):
<script src="path/to/mdast.js"></script>
<script>
var ast = mdast.parse('*hello* __world__');
mdast.stringify(ast); // _hello_ **world**
</script>
See Nodes for information about returned objects.
var mdast = require('mdast');
Parse markdown with mdast.parse
:
var ast = mdast.parse('Some *emphasis*, **strongness**, and `code`.');
Yields:
{
"type": "root",
"children": [
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "Some ",
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 6
}
}
},
{
"type": "emphasis",
"children": [
{
"type": "text",
"value": "emphasis",
"position": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 15
}
}
}
],
"position": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 16
}
}
},
{
"type": "text",
"value": ", ",
"position": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 18
}
}
},
{
"type": "strong",
"children": [
{
"type": "text",
"value": "strongness",
"position": {
"start": {
"line": 1,
"column": 20
},
"end": {
"line": 1,
"column": 30
}
}
}
],
"position": {
"start": {
"line": 1,
"column": 18
},
"end": {
"line": 1,
"column": 32
}
}
},
{
"type": "text",
"value": ", and ",
"position": {
"start": {
"line": 1,
"column": 32
},
"end": {
"line": 1,
"column": 38
}
}
},
{
"type": "inlineCode",
"value": "code",
"position": {
"start": {
"line": 1,
"column": 38
},
"end": {
"line": 1,
"column": 44
}
}
},
{
"type": "text",
"value": ".",
"position": {
"start": {
"line": 1,
"column": 44
},
"end": {
"line": 1,
"column": 45
}
}
}
],
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 45
}
}
}
],
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 45
}
}
}
And passing that document into mdast.stringify
:
var doc = mdast.stringify(ast);
Yields:
Some _emphasis_, **strongness**, and `code`.
Parse a markdown document into an abstract syntax tree.
Signatures
ast = mdast.parse(value)
;ast = mdast.parse(value, options)
.Parameters
value
(string
) — Markdown document;options
(Object
) — Settings:
gfm
(boolean
, default: true
) — See Github Flavoured Markdown;yaml
(boolean
, default: true
) — See YAML;commonmark
(boolean
, default: false
) — See CommonMark;footnotes
(boolean
, default: false
) — See Footnotes;pedantic
(boolean
, default: false
) — See Pedantic;breaks
(boolean
, default: false
) — See Breaks.All options (including the options object itself) can be null
or undefined
to default to their default values.
Returns
Object
: see Nodes for the AST specification.
Stringify an abstract syntax tree into a markdown document.
Signatures
value = mdast.stringify(ast)
;value = mdast.stringify(ast, options)
.Parameters
ast
(Object
) — An AST as returned by mdast.parse()
;options
(Object
) — Settings:
setext
(boolean
, default: false
). See Setext Headings;closeAtx
(boolean
, default: false
). See Closed ATX Headings;looseTable
(boolean
, default: false
). See Loose Tables;spacedTable
(boolean
, default: true
). See Spaced Tables;referenceLinks
(boolean
, default: false
). See Reference Links;fence
("~"
or "`"
, default: "`"
). See Fence;fences
(boolean
, default: false
). See Fences;bullet
("-"
, "*"
, or "+"
, default: "-"
). See List Item Bullets;rule
("-"
, "*"
, or "_"
, default: "*"
). See Horizontal Rules;ruleRepetition
(number
, default: 3). See Horizontal Rules;ruleSpaces
(boolean
, default true
). See Horizontal Rules;strong
("_"
, or "*"
, default "*"
). See Emphasis Markers;emphasis
("_"
, or "*"
, default "_"
). See Emphasis Markers.All options (including the options object itself) can be null
or undefined
to default to their default values.
Returns
string
: a document formatted in markdown.
Modify an abstract syntax tree by applying use
d plugin
s to it.
Signatures
ast = mdast.run(ast)
;ast = mdast.run(ast, options)
.Parameters
ast
(Object
) — An AST as returned by mdast.parse()
;options
(Object
) — Settings, passed to plugins.Returns
Object
: the given AST.
Change the way mdast
works by using a plugin
.
Signatures
mdast = mdast.use(plugin)
;mdast = mdast.use(plugins)
.Parameters
Returns
Object
: an instance of MDAST: The returned object functions just like mdast (it also has use
, parse
, and stringify
methods), but caches the use
d plugins.
This provides the ability to chain use
calls to use multiple plugins, but ensures the functioning of the mdast module does not change for other dependants.
A plugin is a simple function which is invoked each time a document is mdast.parse()
d. A plugin should change the AST to add or remove nodes. attach
should change the mdast instance.
Signatures
plugin(ast, options, mdast)
;error = plugin(ast, options, mdast)
.Parameters
ast
(Object
) — An AST as returned by mdast.parse()
;options
(Object
) — Options passed to mdast.parse()
or mdast.run()
;mdast
(Object
) — Context on which mdast.parse()
or mdast.run()
was invoked.Returns
undefined
or Error
, which in the later case will be thrown.
To modify the parser (for an example, see test/mentions.js
), specify an attach
method on plugin
.
attach
is invoked when the plugin is first use
d.
Signatures
attach(mdast)
.Parameters
mdast
(Object
) — Context on which the plugin was use
d.Install:
$ npm install --global mdast
Use:
Usage: mdast [options] file
Speedy Markdown parser/stringifier for multipurpose analysis
Options:
-h, --help output usage information
-V, --version output the version number
-o, --output <path> specify output location
-s, --setting <settings> specify settings
-u, --use <plugins> use transform plugin(s)
-a, --ast output AST information
--settings output available settings
# Note that bash does not allow reading and writing
# to the same file through pipes
Usage:
# Pass `Readme.md` through mdast
$ mdast Readme.md -o Readme.md
# Pass stdin through mdast, with settings, to stdout
$ cat Readme.md | mdast --setting "setext, bullet: *" > Readme-new.md
# use a plugin
$ npm install mdast-toc
$ mdast --use mdast-toc -o Readme.md
On a MacBook Air, it parses ± 322Kb of markdown (in 214 documents) per second.
214 fixtures (total: 80.62Kb)
4 op/s » mdast.parse w/ `gfm: true`, and `yaml: true`
69 op/s » mdast.stringify w/ `gfm: true`, and `yaml: true`
4 op/s » mdast.parse w/ `gfm: false`, and `yaml: false`
70 op/s » mdast.stringify w/ `gfm: false`, and `yaml: false`
4 op/s » mdast.parse w/ `gfm: true`, `yaml: true`, and `commonmark: true`
72 op/s » mdast.stringify w/ `gfm: true`, `yaml: true`, and `commonmark: true`
This project was initially a fork of marked.
Copyright (c) 2011-2014, Christopher Jeffrey. (MIT License)
FAQs
Markdown Abstract Syntax Tree format
The npm package mdast receives a total of 40,675 weekly downloads. As such, mdast popularity was classified as popular.
We found that mdast demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.