@types/markdown-it
- Version 12.2.3
- Published
- 38.6 kB
- 2 dependencies
- MIT license
Install
npm i @types/markdown-it
yarn add @types/markdown-it
pnpm add @types/markdown-it
Overview
TypeScript definitions for markdown-it
Index
Variables
Interfaces
Type Aliases
Variables
variable MarkdownIt
const MarkdownIt: MarkdownItConstructor;
Main parser/renderer class.
##### Usage
// node.js, "classic" way:var MarkdownIt = require('markdown-it'),md = new MarkdownIt();var result = md.render('# markdown-it rulezz!');// node.js, the same, but with sugar:var md = require('markdown-it')();var result = md.render('# markdown-it rulezz!');// browser without AMD, added to "window" on script load// Note, there are no dash.var md = window.markdownit();var result = md.render('# markdown-it rulezz!');Single line rendering, without paragraph wrap:
var md = require('markdown-it')();var result = md.renderInline('__markdown-it__ rulezz!');##### Example
// commonmark modevar md = require('markdown-it')('commonmark');// default modevar md = require('markdown-it')();// enable everythingvar md = require('markdown-it')({html: true,linkify: true,typographer: true});##### Syntax highlighting
var hljs = require('highlight.js') // https://highlightjs.org/var md = require('markdown-it')({highlight: function (str, lang) {if (lang && hljs.getLanguage(lang)) {try {return hljs.highlight(lang, str, true).value;} catch (__) {}}return ''; // use external default escaping}});Or with full wrapper override (if you need assign class to
<pre>
):var hljs = require('highlight.js') // https://highlightjs.org/// Actual default valuesvar md = require('markdown-it')({highlight: function (str, lang) {if (lang && hljs.getLanguage(lang)) {try {return '<pre class="hljs"><code>' +hljs.highlight(lang, str, true).value +'</code></pre>';} catch (__) {}}return '<pre class="hljs"><code>' + md.utils.escapeHtml(str) + '</code></pre>';}});
Interfaces
interface MarkdownIt
interface MarkdownIt {}
property block
readonly block: ParserBlock;
Instance of [[ParserBlock]]. You may need it to add new rules when writing plugins. For simple rules control use [[MarkdownIt.disable]] and [[MarkdownIt.enable]].
property core
readonly core: ParserCore;
Instance of [[Core]] chain executor. You may need it to add new rules when writing plugins. For simple rules control use [[MarkdownIt.disable]] and [[MarkdownIt.enable]].
property helpers
readonly helpers: typeof helpers;
property inline
readonly inline: ParserInline;
Instance of [[ParserInline]]. You may need it to add new rules when writing plugins. For simple rules control use [[MarkdownIt.disable]] and [[MarkdownIt.enable]].
property linkify
readonly linkify: LinkifyIt.LinkifyIt;
[linkify-it](https://github.com/markdown-it/linkify-it) instance. Used by [linkify](https://github.com/markdown-it/markdown-it/blob/master/lib/rules_core/linkify.js) rule.
property options
readonly options: MarkdownIt.Options;
property renderer
readonly renderer: Renderer;
Instance of [[Renderer]]. Use it to modify output look. Or to add rendering rules for new token types, generated by plugins.
##### Example
var md = require('markdown-it')();function myToken(tokens, idx, options, env, self) {//...return result;};md.renderer.rules['my_token'] = myTokenSee [[Renderer]] docs and [source code](https://github.com/markdown-it/markdown-it/blob/master/lib/renderer.js).
property utils
readonly utils: typeof utils;
method configure
configure: (presets: MarkdownIt.PresetName) => this;
*chainable*, *internal*
Batch load of all options and compenent settings. This is internal method, and you probably will not need it. But if you with - see available presets and data structure [here](https://github.com/markdown-it/markdown-it/tree/master/lib/presets)
We strongly recommend to use presets instead of direct config loads. That will give better compatibility with next versions.
method disable
disable: (list: string | string[], ignoreInvalid?: boolean) => this;
*chainable*
The same as [[MarkdownIt.enable]], but turn specified rules off.
Parameter list
rule name or list of rule names to disable.
Parameter ignoreInvalid
set
true
to ignore errors when rule not found.
method enable
enable: (list: string | string[], ignoreInvalid?: boolean) => this;
*chainable*
Enable list or rules. It will automatically find appropriate components, containing rules with given names. If rule not found, and
ignoreInvalid
not set - throws exception.##### Example
var md = require('markdown-it')().enable(['sub', 'sup']).disable('smartquotes');Parameter list
rule name or list of rule names to enable
Parameter ignoreInvalid
set
true
to ignore errors when rule not found.
method normalizeLink
normalizeLink: (url: string) => string;
Function used to encode link url to a machine-readable format, which includes url-encoding, punycode, etc.
method normalizeLinkText
normalizeLinkText: (url: string) => string;
Function used to decode link url to a human-readable format`
method parse
parse: (src: string, env: any) => Token[];
*internal*
Parse input string and returns list of block tokens (special token type "inline" will contain list of inline tokens). You should not call this method directly, until you write custom renderer (for example, to produce AST).
env
is used to pass data between "distributed" rules and return additional metadata like reference info, needed for the renderer. It also can be used to inject data in specific cases. Usually, you will be ok to pass{}
, and then pass updated object to renderer.Parameter src
source string
Parameter env
environment sandbox
method parseInline
parseInline: (src: string, env: any) => Token[];
*internal*
The same as [[MarkdownIt.parse]] but skip all block rules. It returns the block tokens list with the single
inline
element, containing parsed inline tokens inchildren
property. Also updatesenv
object.Parameter src
source string
Parameter env
environment sandbox
method render
render: (src: string, env?: any) => string;
Render markdown string into html. It does all magic for you :).
env
can be used to inject additional metadata ({}
by default). But you will not need it with high probability. See also comment in [[MarkdownIt.parse]].Parameter src
source string
Parameter env
environment sandbox
method renderInline
renderInline: (src: string, env?: any) => string;
Similar to [[MarkdownIt.render]] but for single paragraph content. Result will NOT be wrapped into
<p>
tags.Parameter src
source string
Parameter env
environment sandbox
method set
set: (options: MarkdownIt.Options) => this;
*chainable*
Set parser options (in the same format as in constructor). Probably, you will never need it, but you can change options after constructor call.
##### Example
var md = require('markdown-it')().set({ html: true, breaks: true }).set({ typographer: true });__Note:__ To achieve the best possible performance, don't modify a
markdown-it
instance options on the fly. If you need multiple configurations it's best to create multiple instances and initialize each with separate config.
method use
use: { (plugin: MarkdownIt.PluginSimple): this; <T = any>(plugin: MarkdownIt.PluginWithOptions<T>, options?: T): this; (plugin: MarkdownIt.PluginWithParams, ...params: any[]): this;};
*chainable*
Load specified plugin with given params into current parser instance. It's just a sugar to call
plugin(md, params)
with curring.##### Example
var iterator = require('markdown-it-for-inline');var md = require('markdown-it')().use(iterator, 'foo_replace', 'text', function (tokens, idx) {tokens[idx].content = tokens[idx].content.replace(/foo/g, 'bar');});
method validateLink
validateLink: (url: string) => boolean;
Link validation function. CommonMark allows too much in links. By default we disable
javascript:
,vbscript:
,file:
schemas, and almost alldata:...
schemas except some embedded image types.You can change this behaviour:
var md = require('markdown-it')();// enable everythingmd.validateLink = function () { return true; }
interface Options
interface Options {}
property breaks
breaks?: boolean | undefined;
Set
true
to convert\n
in paragraphs into<br>
. false
property highlight
highlight?: | ((str: string, lang: string, attrs: string) => string) | null | undefined;
Highlighter function for fenced code blocks. Highlighter
function (str, lang, attrs)
should return escaped HTML. It can also return empty string if the source was not changed and should be escaped externally. If result starts with <pre... internal wrapper is skipped. null
property html
html?: boolean | undefined;
Set
true
to enable HTML tags in source. Be careful! That's not safe! You may need external sanitizer to protect output from XSS. It's better to extend features via plugins, instead of enabling HTML. false
property langPrefix
langPrefix?: string | undefined;
CSS language class prefix for fenced blocks. Can be useful for external highlighters. 'language-'
property linkify
linkify?: boolean | undefined;
Set
true
to autoconvert URL-like text to links. false
property quotes
quotes?: string | string[];
Double + single quotes replacement pairs, when typographer enabled and smartquotes on. For example, you can use
'«»„“'
for Russian,'„“‚‘'
for German, and['«\xA0', '\xA0»', '‹\xA0', '\xA0›']
for French (including nbsp). '“”‘’'
property typographer
typographer?: boolean | undefined;
Set
true
to enable [some language-neutral replacement](https://github.com/markdown-it/markdown-it/blob/master/lib/rules_core/replacements.js) + quotes beautification (smartquotes). false
property xhtmlOut
xhtmlOut?: boolean | undefined;
Set
true
to add '/' when closing single tags (<br />
). This is needed only for full CommonMark compatibility. In real world you will need HTML output. false
Type Aliases
type PluginSimple
type PluginSimple = (md: MarkdownIt) => void;
type PluginWithOptions
type PluginWithOptions<T = any> = (md: MarkdownIt, options?: T) => void;
type PluginWithParams
type PluginWithParams = (md: MarkdownIt, ...params: any[]) => void;
type PresetName
type PresetName = 'default' | 'zero' | 'commonmark';
MarkdownIt provides named presets as a convenience to quickly enable/disable active syntax rules and options for common use cases.
- ["commonmark"](https://github.com/markdown-it/markdown-it/blob/master/lib/presets/commonmark.js) - configures parser to strict [CommonMark](http://commonmark.org/) mode. - [default](https://github.com/markdown-it/markdown-it/blob/master/lib/presets/default.js) - similar to GFM, used when no preset name given. Enables all available rules, but still without html, typographer & autolinker. - ["zero"](https://github.com/markdown-it/markdown-it/blob/master/lib/presets/zero.js) - all rules disabled. Useful to quickly setup your config via
.enable()
. For example, when you need onlybold
anditalic
markup and nothing else.
Package Files (2)
Dependencies (2)
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/markdown-it
.
- Markdown[](https://www.jsdocs.io/package/@types/markdown-it)
- HTML<a href="https://www.jsdocs.io/package/@types/markdown-it"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 1567 ms. - Missing or incorrect documentation? Open an issue for this package.