remark-attr
This plugin adds support for custom attributes to Markdown syntax.For security reasons, this plugin uses html-element-attributes. The use of JavaScript attributes (
onload
for example) is not allowed by default.Default Syntax
Images :Links :
Autolink :
Header (Atx) :
This is a title
{style="color:red;"}or
This is a title {style="color:yellow;"}
If option enableAtxHeaderInline is set totrue
(default value).
Header :
This is a title
{style="color: pink;"}Emphasis :
Strong :
Delete :
Code :
fprintf
{language=c} function to format the output to a file.
Footnote (using remark-footnotes) :
rehype
At the moment it aims is to be used with rehypeproduces:
Installation
npm install remark-attrDependencies:
Usage:
Here a test :
{ height=100 }
`
unified() .use(remarkParse) .use(remarkAttr) .use(remark2rehype) .use(stringify) .process( testFile, (err, file) => {
console.log(String(file))
} )
Output :
Here a test :
~API
remarkAttr([options])
Parse attributes of markdown elements.remarkAttr.SUPPORTED_ELEMENTS
The list of currently supported elements.['link', 'atxHeading', 'strong', 'emphasis', 'deletion', 'code', 'setextHeading']
['link', 'atxHeading', 'strong', 'emphasis', 'deletion', 'code', 'setextHeading', 'fencedCode', 'reference', 'footnoteCall', 'autoLink']
Options
options.allowDangerousDOMEventHandlers
Whether to allow the use of on-*
attributes. They are depreciated and disabled by default for security reasons. Its a boolean (default: false
).
If allowed, DOM event handlers will be added to the global scope.options.elements
The list of elements witch the attributes should be parsed.
It's a list of string, a sub-list of SUPPORTED_ELEMENTS
.
If you are confident enough you can add the name of a tokenizer that isn't officialy supported but remember that it will not have been tested.options.extend
An object that extends the list of attributes supported for some elements.Example :
extend: {heading: ['original', 'quality', 'format', 'toc']}
With this configuration, if the scope permits it, 4 mores attributes will be supported for atxHeading elements.
options.scope
A string with the value global
or specific
or extented
or none
or every
.-
none
will disable the plugin.
- global
will activate only the global attributes.
- specific
will activate global and specific attributes.
- extended
will add personalized tags for some elements.
- permissive
or every
will allow every attributes (except dangerous one) on every elements supported.options.enableAtxHeaderInline
Whether to allow atx headers with attributes on the same line.This is a title {style="color:yellow;"}
How does it works ?
This plugin extend the syntax of remark-parseremark-parse by replacing old tokenizers by new one. The new tokenizers functions re-use the old tokenizers and md-attr-parsermd-attr-parser to parse the extended syntax.So
option.SUPPORTED_ELEMENTS
are the names of the tokenizers and neither arbitrary names nor HTML tag names.
Here is the related documentationdoc.