Skip to content

Class: Parser ​

Defined in: parser/parser.ts:69

Extended by ​

Constructors ​

Constructor ​

ts
new Parser(): Parser;

Returns ​

Parser

Properties ​

block ​

ts
block: ParserBlock<Parser>;

Defined in: parser/parser.ts:78

Instance of ParserBlock. You may need it to add new rules when writing plugins.


core ​

ts
core: Core<Parser>;

Defined in: parser/parser.ts:83

Instance of Core chain executor. You may need it to add new rules when writing plugins.


helpers ​

ts
helpers: object;

Defined in: parser/parser.ts:127

Link components parser functions, useful to write plugins. See details here.

parseLinkDestination() ​

ts
parseLinkDestination: (str, start, max) => ParseLinkDestinationResult;
Parameters ​
str ​

string

start ​

number

max ​

number

Returns ​

ParseLinkDestinationResult

parseLinkLabel() ​

ts
parseLinkLabel: (state, start, disableNested) => number;
Parameters ​
state ​

StateInline

start ​

number

disableNested ​

boolean = false

Returns ​

number

parseLinkTitle() ​

ts
parseLinkTitle: (str, start, max, prev_state?) => ParseLinkTitleResult;
Parameters ​
str ​

string

start ​

number

max ​

number

prev_state? ​

ParseLinkTitleResult

Returns ​

ParseLinkTitleResult


inline ​

ts
inline: ParserInline<Parser>;

Defined in: parser/parser.ts:73

Instance of ParserInline. You may need it to add new rules when writing plugins.


linkify ​

ts
linkify: LinkifyIt;

Defined in: parser/parser.ts:90

linkify-it instance. Used by linkify rule. Unset in markdown-exit/core until you assign one.


options ​

ts
options: Required<ParserOptions>;

Defined in: parser/parser.ts:129

Methods ​

ts
normalizeLink(url): string;

Defined in: parser/parser.ts:112

Function used to encode link url to a machine-readable format, which includes url-encoding, punycode, etc.

Parameters ​

url ​

string

Returns ​

string


normalizeLinkText() ​

ts
normalizeLinkText(url): string;

Defined in: parser/parser.ts:119

Function used to decode link url to a human-readable format`

Parameters ​

url ​

string

Returns ​

string


parse() ​

ts
parse(src, env): Token[];

Defined in: parser/parser.ts:145

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.

Parameters ​

src ​

string

source string

env ​

MarkdownExitEnv = {}

environment sandbox

Returns ​

Token[]


parseInline() ​

ts
parseInline(src, env): Token[];

Defined in: parser/parser.ts:162

The same as parse but skip all block rules. It returns the block tokens list with the single inline element, containing parsed inline tokens in children property. Also updates env object.

Parameters ​

src ​

string

source string

env ​

MarkdownExitEnv = {}

environment sandbox

Returns ​

Token[]


ts
validateLink(url): boolean;

Defined in: parser/parser.ts:104

Link validation function. CommonMark allows too much in links. By default we disable javascript:, vbscript:, file: schemas, and almost all data:... schemas except some embedded image types.

You can change this behaviour:

javascript
// enable everything
md.validateLink = () => true

Parameters ​

url ​

string

Returns ​

boolean

Released under the MIT License.