@types/markdown-it
- Version 14.1.2
- Published
- 73 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
Namespaces
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 Helpers
interface Helpers {}
method parseLinkDestination
parseLinkDestination: ( str: string, start: number, max: number) => ParseLinkDestinationResult;
method parseLinkLabel
parseLinkLabel: ( state: StateInline, start: number, disableNested?: boolean) => number;
method parseLinkTitle
parseLinkTitle: ( str: string, start: number, max: number, prev_state?: ParseLinkTitleResult) => ParseLinkTitleResult;
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: Core;
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: MarkdownIt.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;
[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: MarkdownIt.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
interface ParseLinkDestinationResult
interface ParseLinkDestinationResult {}
interface ParseLinkTitleResult
interface ParseLinkTitleResult {}
property can_continue
can_continue: boolean;
if
true
, this link can be continued on the next line
property marker
marker: number;
expected closing marker character code
property ok
ok: boolean;
if
true
, this is a valid link title
property pos
pos: number;
if
ok
, it's the position of the first character after the closing marker
property str
str: string;
if
ok
, it's the unescaped title
interface Utils
interface Utils {}
property lib
lib: { mdurl: typeof mdurl; ucmicro: any;};
method arrayReplaceAt
arrayReplaceAt: <T>(src: T[], pos: number, newElements: T[]) => T[];
Remove element from array and put another array at those position. Useful for some operations with tokens
method assign
assign: (obj: any, ...from: any[]) => any;
Merge objects
method escapeHtml
escapeHtml: (str: string) => string;
method escapeRE
escapeRE: (str: string) => string;
method fromCodePoint
fromCodePoint: (c: number) => string;
method has
has: (obj: any, key: keyof any) => boolean;
method isMdAsciiPunct
isMdAsciiPunct: (code: number) => boolean;
Markdown ASCII punctuation characters.
!, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @, [, , ], ^, _, `, {, |, }, or ~
Don't confuse with unicode punctuation !!! It lacks some chars in ascii range.
See Also
http://spec.commonmark.org/0.15/#ascii-punctuation-character
method isPunctChar
isPunctChar: (ch: string) => boolean;
Currently without astral characters support.
method isSpace
isSpace: (code: number) => boolean;
method isString
isString: (obj: any) => obj is string;
method isValidEntityCode
isValidEntityCode: (c: number) => boolean;
method isWhiteSpace
isWhiteSpace: (code: number) => boolean;
Zs (unicode class) || [\t\f\v\r\n]
method normalizeReference
normalizeReference: (str: string) => string;
Helper to unify [reference labels].
method unescapeAll
unescapeAll: (str: string) => string;
method unescapeMd
unescapeMd: (str: string) => string;
Type Aliases
type Core
type Core = Core_;
type ParserBlock
type ParserBlock = ParserBlock_;
type ParserInline
type ParserInline = ParserInline_;
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.
type Renderer
type Renderer = Renderer_;
type Ruler
type Ruler<T> = Ruler_<T>;
type StateBlock
type StateBlock = StateBlock_;
type StateCore
type StateCore = StateCore_;
type StateInline
type StateInline = StateInline_;
type Token
type Token = Token_;
Namespaces
namespace ParserBlock
namespace ParserBlock {}
type RuleBlock
type RuleBlock = ( state: StateBlock, startLine: number, endLine: number, silent: boolean) => boolean;
namespace ParserInline
namespace ParserInline {}
type RuleInline
type RuleInline = (state: StateInline, silent: boolean) => boolean;
type RuleInline2
type RuleInline2 = (state: StateInline) => boolean;
namespace Renderer
namespace Renderer {}
interface RenderRuleRecord
interface RenderRuleRecord {}
property code_block
code_block?: RenderRule | undefined;
property code_inline
code_inline?: RenderRule | undefined;
property fence
fence?: RenderRule | undefined;
property hardbreak
hardbreak?: RenderRule | undefined;
property html_block
html_block?: RenderRule | undefined;
property html_inline
html_inline?: RenderRule | undefined;
property image
image?: RenderRule | undefined;
property softbreak
softbreak?: RenderRule | undefined;
property text
text?: RenderRule | undefined;
index signature
[type: string]: RenderRule | undefined;
type RenderRule
type RenderRule = ( tokens: Token[], idx: number, options: Options, env: any, self: Renderer) => string;
namespace Ruler
namespace Ruler {}
interface RuleOptions
interface RuleOptions {}
property alt
alt: string[];
array with names of "alternate" chains.
namespace StateBlock
namespace StateBlock {}
type ParentType
type ParentType = 'blockquote' | 'list' | 'root' | 'paragraph' | 'reference';
namespace StateInline
namespace StateInline {}
interface Delimiter
interface Delimiter {}
interface Scanned
interface Scanned {}
interface TokenMeta
interface TokenMeta {}
property delimiters
delimiters: Delimiter[];
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[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](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 3843 ms. - Missing or incorrect documentation? Open an issue for this package.