` tags. * * @param src source string * @param env environment sandbox */ renderInline(src: string, env?: any): string; } /** * Main parser/renderer class. * * ##### Usage * * ```javascript * // 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: * * ```javascript * var md = require('markdown-it')(); * var result = md.renderInline('__markdown-it__ rulezz!'); * ``` * * ##### Example * * ```javascript * // commonmark mode * var md = require('markdown-it')('commonmark'); * * // default mode * var md = require('markdown-it')(); * * // enable everything * var md = require('markdown-it')({ * html: true, * linkify: true, * typographer: true * }); * ``` * * ##### Syntax highlighting * * ```js * 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 `
`):
*
* ```javascript
* var hljs = require('highlight.js') // https://highlightjs.org/
*
* // Actual default values
* var md = require('markdown-it')({
* highlight: function (str, lang) {
* if (lang && hljs.getLanguage(lang)) {
* try {
* return '' +
* hljs.highlight(lang, str, true).value +
* '
';
* } catch (__) {}
* }
*
* return '' + md.utils.escapeHtml(str) + '
';
* }
* });
* ```
*/
declare const MarkdownIt: MarkdownItConstructor;
/**
* Options of @mdit-vue/plugin-component
*/
interface ComponentPluginOptions {
/**
* Extra tags to be treated as block tags.
*
* @default []
*/
blockTags?: string[];
/**
* Extra tags to be treated as inline tags.
*
* @default []
*/
inlineTags?: string[];
}
/**
* Takes a string or object with `content` property, extracts
* and parses front-matter from the string, then returns an object
* with `data`, `content` and other [useful properties](#returned-object).
*
* ```js
* var matter = require('gray-matter');
* console.log(matter('---\ntitle: Home\n---\nOther stuff'));
* //=> { data: { title: 'Home'}, content: 'Other stuff' }
* ```
* @param {Object|String} `input` String, or object with `content` string
* @param {Object} `options`
* @return {Object}
* @api public
*/
declare function matter<
I extends matter.Input,
O extends matter.GrayMatterOption
>(input: I | { content: I }, options?: O): matter.GrayMatterFile
declare namespace matter {
type Input = string | Buffer
interface GrayMatterOption<
I extends Input,
O extends GrayMatterOption
> {
parser?: () => void
eval?: boolean
excerpt?: boolean | ((input: I, options: O) => string)
excerpt_separator?: string
engines?: {
[index: string]:
| ((input: string) => object)
| { parse: (input: string) => object; stringify?: (data: object) => string }
}
language?: string
delimiters?: string | [string, string]
}
interface GrayMatterFile {
data: { [key: string]: any }
content: string
excerpt?: string
orig: Buffer | I
language: string
matter: string
stringify(lang: string): string
}
/**
* Stringify an object to YAML or the specified language, and
* append it to the given string. By default, only YAML and JSON
* can be stringified. See the [engines](#engines) section to learn
* how to stringify other languages.
*
* ```js
* console.log(matter.stringify('foo bar baz', {title: 'Home'}));
* // results in:
* // ---
* // title: Home
* // ---
* // foo bar baz
* ```
* @param {String|Object} `file` The content string to append to stringified front-matter, or a file object with `file.content` string.
* @param {Object} `data` Front matter to stringify.
* @param {Object} `options` [Options](#options) to pass to gray-matter and [js-yaml].
* @return {String} Returns a string created by wrapping stringified yaml with delimiters, and appending that to the given string.
*/
export function stringify>(
file: string | { content: string },
data: object,
options?: GrayMatterOption
): string
/**
* Synchronously read a file from the file system and parse
* front matter. Returns the same object as the [main function](#matter).
*
* ```js
* var file = matter.read('./content/blog-post.md');
* ```
* @param {String} `filepath` file path of the file to read.
* @param {Object} `options` [Options](#options) to pass to gray-matter.
* @return {Object} Returns [an object](#returned-object) with `data` and `content`
*/
export function read>(
fp: string,
options?: GrayMatterOption
): matter.GrayMatterFile
/**
* Returns true if the given `string` has front matter.
* @param {String} `string`
* @param {Object} `options`
* @return {Boolean} True if front matter exists.
*/
export function test>(
str: string,
options?: GrayMatterOption
): boolean
/**
* Detect the language to use, if one is defined after the
* first front-matter delimiter.
* @param {String} `string`
* @param {Object} `options`
* @return {Object} Object with `raw` (actual language string), and `name`, the language with whitespace trimmed
*/
export function language>(
str: string,
options?: GrayMatterOption
): { name: string; raw: string }
}
type GrayMatterOptions = matter.GrayMatterOption;
/**
* Options of @mdit-vue/plugin-frontmatter
*/
interface FrontmatterPluginOptions {
/**
* Options of gray-matter
*
* @see https://github.com/jonschlinkert/gray-matter#options
*/
grayMatterOptions?: GrayMatterOptions;
/**
* Render the excerpt or not
*
* @default true
*/
renderExcerpt?: boolean;
}
declare module '@mdit-vue/types' {
interface MarkdownItEnv {
/**
* The raw Markdown content without frontmatter
*/
content?: string;
/**
* The excerpt that extracted by `@mdit-vue/plugin-frontmatter`
*
* - Would be the rendered HTML when `renderExcerpt` is enabled
* - Would be the raw Markdown when `renderExcerpt` is disabled
*/
excerpt?: string;
/**
* The frontmatter that extracted by `@mdit-vue/plugin-frontmatter`
*/
frontmatter?: Record;
}
}
interface MarkdownItHeader {
/**
* The level of the header
*
* `1` to `6` for `` to ``
*/
level: number;
/**
* The title of the header
*/
title: string;
/**
* The slug of the header
*
* Typically the `id` attr of the header anchor
*/
slug: string;
/**
* Link of the header
*
* Typically using `#${slug}` as the anchor hash
*/
link: string;
/**
* The children of the header
*/
children: MarkdownItHeader[];
}
/**
* Options of @mdit-vue/plugin-headers
*/
interface HeadersPluginOptions {
/**
* A custom slugification function
*
* Should use the same slugify function with markdown-it-anchor
* to ensure the link is matched
*/
slugify?: (str: string) => string;
/**
* A function for formatting header title
*/
format?: (str: string) => string;
/**
* Heading level that going to be extracted
*
* Should be a subset of markdown-it-anchor's `level` option
* to ensure the slug is existed
*
* @default [2,3]
*/
level?: number[];
/**
* Should allow headers inside nested blocks or not
*
* If set to `true`, headers inside blockquote, list, etc. would also be extracted.
*
* @default false
*/
shouldAllowNested?: boolean;
}
declare module '@mdit-vue/types' {
interface MarkdownItEnv {
/**
* The headers that extracted by `@mdit-vue/plugin-headers`
*/
headers?: MarkdownItHeader[];
}
}
/**
* Options of @mdit-vue/plugin-sfc
*/
interface SfcPluginOptions {
/**
* Custom blocks to be extracted
*
* @default []
*/
customBlocks?: string[];
}
/**
* SFC block that extracted from markdown
*/
interface SfcBlock {
/**
* The type of the block
*/
type: string;
/**
* The content, including open-tag and close-tag
*/
content: string;
/**
* The content that stripped open-tag and close-tag off
*/
contentStripped: string;
/**
* The open-tag
*/
tagOpen: string;
/**
* The close-tag
*/
tagClose: string;
}
interface MarkdownSfcBlocks {
/**
* The `` block
*/
template: SfcBlock | null;
/**
* The common `