Skip to content

Class: Parser

Defined in: parser/parser.ts:68

Extended by

Constructors

Constructor

ts
new Parser(): Parser;

Returns

Parser

Properties

block

ts
block: ParserBlock<Parser>;

Defined in: parser/parser.ts:77

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


core

ts
core: Core<Parser>;

Defined in: parser/parser.ts:82

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:120

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:72

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


linkify

ts
linkify: LinkifyIt;

Defined in: parser/parser.ts:89

linkify-it instance. Used by linkify rule.


ts
normalizeLink: (url) => string;

Defined in: parser/parser.ts:109

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:114

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

Parameters

url

string

Returns

string


options

ts
options: Required<ParserOptions>;

Defined in: parser/parser.ts:122


ts
validateLink: (url) => boolean;

Defined in: parser/parser.ts:103

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

Methods

parse()

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

Defined in: parser/parser.ts:138

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:155

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[]

Released under the MIT License.