diff options
Diffstat (limited to 'node_modules/posthtml')
| -rw-r--r-- | node_modules/posthtml/lib/api.js | 145 | ||||
| -rw-r--r-- | node_modules/posthtml/lib/index.js | 323 | ||||
| -rw-r--r-- | node_modules/posthtml/license | 21 | ||||
| -rw-r--r-- | node_modules/posthtml/package.json | 65 | ||||
| -rw-r--r-- | node_modules/posthtml/readme.md | 366 | ||||
| -rw-r--r-- | node_modules/posthtml/types/posthtml.d.ts | 108 |
6 files changed, 1028 insertions, 0 deletions
diff --git a/node_modules/posthtml/lib/api.js b/node_modules/posthtml/lib/api.js new file mode 100644 index 0000000..e929cfb --- /dev/null +++ b/node_modules/posthtml/lib/api.js @@ -0,0 +1,145 @@ +'use strict' + +/** + * # API + * + * @author Ivan Voischev (@voischev), + * Anton Winogradov (@awinogradov), + * Alexej Yaroshevich (@zxqfox), + * Vasiliy (@Yeti-or) + * + * @namespace tree + */ +function Api () { + this.walk = walk + this.match = match +} + +/** + * Walks the tree and passes all nodes via a callback + * + * @memberof tree + * + * @param {Function} cb Callback + * @return {Function} Callback(node) + * + *@example + * ```js + * export const walk = (tree) => { + * tree.walk((node) => { + * let classes = node.attrs && node.attrs.class.split(' ') || [] + * + * if (classes.includes(className)) return cb(node) + * return node + * }) + * } + * ``` + */ +function walk (cb) { + return traverse(this, cb) +} + +/** + * Matches an expression to search for nodes in the tree + * + * @memberof tree + * + * @param {String|RegExp|Object|Array} expression - Matcher(s) to search + * @param {Function} cb Callback + * + * @return {Function} Callback(node) + * + * @example + * ```js + * export const match = (tree) => { + * // Single matcher + * tree.match({ tag: 'custom-tag' }, (node) => { + * let tag = node.tag + * + * Object.assign(node, { tag: 'div', attrs: {class: tag} }) + * + * return node + * }) + * // Multiple matchers + * tree.match([{ tag: 'b' }, { tag: 'strong' }], (node) => { + * let style = 'font-weight: bold;' + * + * node.tag = 'span' + * + * node.attrs + * ? ( node.attrs.style + * ? ( node.attrs.style += style ) + * : node.attrs.style = style + * ) + * : node.attrs = { style: style } + * + * return node + * }) + * } + * ``` + */ +function match (expression, cb) { + return Array.isArray(expression) + ? traverse(this, node => { + for (let i = 0; i < expression.length; i++) { + if (compare(expression[i], node)) return cb(node) + } + + return node + }) + : traverse(this, node => { + if (compare(expression, node)) return cb(node) + + return node + }) +} + +module.exports = Api +module.exports.match = match +module.exports.walk = walk + +/** @private */ +function traverse (tree, cb) { + if (Array.isArray(tree)) { + for (let i = 0; i < tree.length; i++) { + tree[i] = traverse(cb(tree[i]), cb) + } + } else if ( + tree && + typeof tree === 'object' && + Object.prototype.hasOwnProperty.call(tree, 'content') + ) traverse(tree.content, cb) + + return tree +} + +/** @private */ +function compare (expected, actual) { + if (expected instanceof RegExp) { + if (typeof actual === 'object') return false + if (typeof actual === 'string') return expected.test(actual) + } + + if (typeof expected !== typeof actual) return false + if (typeof expected !== 'object' || expected === null) { + return expected === actual + } + + if (Array.isArray(expected)) { + return expected.every(exp => [].some.call(actual, act => compare(exp, act))) + } + + return Object.keys(expected).every(key => { + const ao = actual[key] + const eo = expected[key] + + if (typeof eo === 'object' && eo !== null && ao !== null) { + return compare(eo, ao) + } + if (typeof eo === 'boolean') { + return eo !== (ao == null) + } + + return ao === eo + }) +} diff --git a/node_modules/posthtml/lib/index.js b/node_modules/posthtml/lib/index.js new file mode 100644 index 0000000..542c347 --- /dev/null +++ b/node_modules/posthtml/lib/index.js @@ -0,0 +1,323 @@ +const pkg = require('../package.json') +const Api = require('./api.js') + +let { parser } = require('posthtml-parser') +let { render } = require('posthtml-render') + +/** + * @author Ivan Voischev (@voischev), + * Ivan Demidov (@scrum) + * + * @requires api + * @requires posthtml-parser + * @requires posthtml-render + * + * @constructor PostHTML + * @param {Array} plugins - An array of PostHTML plugins + */ +class PostHTML { + constructor (plugins) { + /** + * PostHTML Instance + * + * @prop plugins + * @prop options + */ + this.version = pkg.version + this.name = pkg.name + this.plugins = typeof plugins === 'function' ? [plugins] : plugins || [] + this.source = '' + + /** + * Tree messages to store and pass metadata between plugins + * + * @memberof tree + * @type {Array} messages + * + * @example + * ```js + * export default function plugin (options = {}) { + * return function (tree) { + * tree.messages.push({ + * type: 'dependency', + * file: 'path/to/dependency.html', + * from: tree.options.from + * }) + * + * return tree + * } + * } + * ``` + */ + this.messages = [] + + /** + * Tree method parsing string inside plugins. + * + * @memberof tree + * @type {Function} parser + * + * @example + * ```js + * export default function plugin (options = {}) { + * return function (tree) { + * tree.match({ tag: 'include' }, function(node) { + * node.tag = false; + * node.content = tree.parser(fs.readFileSync(node.attr.src)) + * return node + * }) + * + * return tree + * } + * } + * ``` + */ + this.parser = parser + + /** + * Tree method rendering tree to string inside plugins. + * + * @memberof tree + * @type {Function} render + * + * @example + * ```js + * export default function plugin (options = {}) { + * return function (tree) { + * var outherTree = ['\n', {tag: 'div', content: ['1']}, '\n\t', {tag: 'div', content: ['2']}, '\n']; + * var htmlWitchoutSpaceless = tree.render(outherTree).replace(/[\n|\t]/g, ''); + * return tree.parser(htmlWitchoutSpaceless) + * } + * } + * ``` + */ + this.render = render + + // extend api methods + Api.call(this) + } + + /** + * @this posthtml + * @param {Function} plugin - A PostHTML plugin + * @returns {Constructor} - this(PostHTML) + * + * **Usage** + * ```js + * ph.use((tree) => { tag: 'div', content: tree }) + * .process('<html>..</html>', {}) + * .then((result) => result)) + * ``` + */ + use (...args) { + this.plugins.push(...args) + + return this + } + + /** + * @param {String} html - Input (HTML) + * @param {?Object} options - PostHTML Options + * @returns {Object<{html: String, tree: PostHTMLTree}>} - Sync Mode + * @returns {Promise<{html: String, tree: PostHTMLTree}>} - Async Mode (default) + * + * **Usage** + * + * **Sync** + * ```js + * ph.process('<html>..</html>', { sync: true }).html + * ``` + * + * **Async** + * ```js + * ph.process('<html>..</html>', {}).then((result) => result)) + * ``` + */ + process (tree, options = {}) { + /** + * ## PostHTML Options + * + * @type {Object} + * @prop {?Boolean} options.sync - enables sync mode, plugins will run synchronously, throws an error when used with async plugins + * @prop {?Function} options.parser - use custom parser, replaces default (posthtml-parser) + * @prop {?Function} options.render - use custom render, replaces default (posthtml-render) + * @prop {?Boolean} options.skipParse - disable parsing + * @prop {?Array} options.directives - Adds processing of custom [directives](https://github.com/posthtml/posthtml-parser#directives). + */ + this.options = options + this.source = tree + + if (options.parser) parser = this.parser = options.parser + if (options.render) render = this.render = options.render + + tree = options.skipParse + ? tree || [] + : parser(tree, options) + + tree = [].concat(tree) + + // sync mode + if (options.sync === true) { + this.plugins.forEach((plugin, index) => { + _treeExtendApi(tree, this) + + let result + + if (plugin.length === 2 || isPromise(result = plugin(tree))) { + throw new Error( + `Can’t process contents in sync mode because of async plugin: ${plugin.name}` + ) + } + + // clearing the tree of options + if (index !== this.plugins.length - 1 && !options.skipParse) { + tree = [].concat(tree) + } + + // return the previous tree unless result is fulfilled + tree = result || tree + }) + + return lazyResult(render, tree) + } + + // async mode + let i = 0 + + const next = (result, cb) => { + _treeExtendApi(result, this) + + // all plugins called + if (this.plugins.length <= i) { + cb(null, result) + return + } + + // little helper to go to the next iteration + function _next (res) { + if (res && !options.skipParse) { + res = [].concat(res) + } + + return next(res || result, cb) + } + + // call next + const plugin = this.plugins[i++] + + if (plugin.length === 2) { + plugin(result, (err, res) => { + if (err) return cb(err) + _next(res) + }) + return + } + + // sync and promised plugins + let err = null + + const res = tryCatch(() => plugin(result), e => { + err = e + return e + }) + + if (err) { + cb(err) + return + } + + if (isPromise(res)) { + res.then(_next).catch(cb) + return + } + + _next(res) + } + + return new Promise((resolve, reject) => { + next(tree, (err, tree) => { + if (err) reject(err) + else resolve(lazyResult(render, tree)) + }) + }) + } +} + +/** + * @exports posthtml + * + * @param {Array} plugins + * @return {Function} posthtml + * + * **Usage** + * ```js + * import posthtml from 'posthtml' + * import plugin from 'posthtml-plugin' + * + * const ph = posthtml([ plugin() ]) + * ``` + */ +module.exports = plugins => new PostHTML(plugins) + +/** + * Extension of options tree + * + * @private + * + * @param {Array} tree + * @param {Object} PostHTML + * @returns {?*} + */ +function _treeExtendApi (t, _t) { + if (typeof t === 'object') { + t = Object.assign(t, _t) + } +} + +/** + * Checks if parameter is a Promise (or thenable) object. + * + * @private + * + * @param {*} promise - Target `{}` to test + * @returns {Boolean} + */ +function isPromise (promise) { + return !!promise && typeof promise.then === 'function' +} + +/** + * Simple try/catch helper, if exists, returns result + * + * @private + * + * @param {Function} tryFn - try block + * @param {Function} catchFn - catch block + * @returns {?*} + */ +function tryCatch (tryFn, catchFn) { + try { + return tryFn() + } catch (err) { + catchFn(err) + } +} + +/** + * Wraps the PostHTMLTree within an object using a getter to render HTML on demand. + * + * @private + * + * @param {Function} render + * @param {Array} tree + * @returns {Object<{html: String, tree: Array}>} + */ +function lazyResult (render, tree) { + return { + get html () { + return render(tree, tree.options) + }, + tree, + messages: tree.messages + } +} diff --git a/node_modules/posthtml/license b/node_modules/posthtml/license new file mode 100644 index 0000000..03700b2 --- /dev/null +++ b/node_modules/posthtml/license @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2015 PostHTML + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/node_modules/posthtml/package.json b/node_modules/posthtml/package.json new file mode 100644 index 0000000..56a0c2a --- /dev/null +++ b/node_modules/posthtml/package.json @@ -0,0 +1,65 @@ +{ + "name": "posthtml", + "version": "0.16.7", + "description": "HTML/XML processor", + "keywords": [ + "html", + "xml", + "postproccessor", + "parser", + "transform", + "transformations", + "manipulation", + "preprocessor", + "processor" + ], + "main": "lib", + "types": "types/posthtml.d.ts", + "files": [ + "types", + "lib" + ], + "engines": { + "node": ">=12.0.0" + }, + "dependencies": { + "posthtml-parser": "^0.11.0", + "posthtml-render": "^3.0.0" + }, + "devDependencies": { + "@commitlint/cli": "^16.2.1", + "@commitlint/config-angular": "^16.2.1", + "c8": "^7.7.3", + "chai": "^4.3.4", + "chai-as-promised": "^7.1.1", + "chai-subset": "^1.6.0", + "conventional-changelog-cli": "^2.1.1", + "husky": "^7.0.1", + "jsdoc-to-markdown": "^7.0.1", + "lint-staged": "^12.3.4", + "mocha": "^9.0.3", + "standard": "^16.0.2" + }, + "scripts": { + "prepare": "husky install", + "version": "conventional-changelog -i changelog.md -s -r 0 && git add changelog.md", + "test": "c8 mocha", + "docs:api": "jsdoc2md lib/api.js > docs/api.md", + "docs:core": "jsdoc2md lib/index.js > docs/core.md" + }, + "author": "Ivan Voischev <voischev.ivan@ya.ru>", + "contributors": [ + { + "name": "Ivan Voischev", + "email": "voischev.ivan@ya.ru" + }, + { + "name": "Ivan Demidov", + "email": "scrum@list.ru" + } + ], + "homepage": "https://github.com/posthtml/posthtml", + "repository": "https://github.com/posthtml/posthtml.git", + "bugs": "https://github.com/posthtml/posthtml/issues", + "license": "MIT" +} diff --git a/node_modules/posthtml/readme.md b/node_modules/posthtml/readme.md new file mode 100644 index 0000000..1f582f1 --- /dev/null +++ b/node_modules/posthtml/readme.md @@ -0,0 +1,366 @@ +# PostHTML <img align="right" width="220" height="200" title="PostHTML" src="http://posthtml.github.io/posthtml/logo.svg"> + +PostHTML is a tool for transforming HTML/XML with JS plugins. PostHTML itself is very small. It includes only a HTML parser, a HTML node tree API and a node tree stringifier. + +All HTML transformations are made by plugins. And these plugins are just small plain JS functions, which receive a HTML node tree, transform it, and return a modified tree. + +For more detailed information about PostHTML in general take a look at the [docs](https://github.com/posthtml/posthtml/tree/master/docs). + +### Dependencies + +| Name | Description | +|:----:|:-----------:| +|[posthtml-parser](https://github.com/posthtml/posthtml-parser)| Parser HTML/XML to PostHTMLTree | +|[posthtml-render](https://github.com/posthtml/posthtml-render)| Render PostHTMLTree to HTML/XML | + +## Create to your project + +```bash +npm init posthtml +``` + +## Install + +```bash +npm i -D posthtml +``` + +## Usage + +### API + +**Sync** + +```js +import posthtml from 'posthtml' + +const html = ` + <component> + <title>Super Title</title> + <text>Awesome Text</text> + </component> +` + +const result = posthtml() + .use(require('posthtml-custom-elements')()) + .process(html, { sync: true }) + .html + +console.log(result) +``` + +```html +<div class="component"> + <div class="title">Super Title</div> + <div class="text">Awesome Text</div> +</div> +``` + +> :warning: Async Plugins can't be used in sync mode and will throw an Error. It's recommended to use PostHTML asynchronously whenever possible. + +**Async** + +```js +import posthtml from 'posthtml' + +const html = ` + <html> + <body> + <p class="wow">OMG</p> + </body> + </html> +` + +posthtml( + [ + require('posthtml-to-svg-tags')(), + require('posthtml-extend-attrs')({ + attrsTree: { + '.wow' : { + id: 'wow_id', + fill: '#4A83B4', + 'fill-rule': 'evenodd', + 'font-family': 'Verdana' + } + } + }) + ]) + .process(html/*, options */) + .then((result) => console.log(result.html)) +``` + +```html +<svg xmlns="http://www.w3.org/2000/svg"> + <text + class="wow" + id="wow_id" + fill="#4A83B4" + fill-rule="evenodd" font-family="Verdana"> + OMG + </text> +</svg> +``` + +**Directives** + +```js +import posthtml from 'posthtml' + +const php = ` + <component> + <title><?php echo $title; ?></title> + <text><?php echo $article; ?></text> + </component> +` + +const result = posthtml() + .use(require('posthtml-custom-elements')()) + .process(html, { + directives: [ + { name: '?php', start: '<', end: '>' } + ] + }) + .html + +console.log(result) +``` + +```html +<div class="component"> + <div class="title"><?php echo $title; ?></div> + <div class="text"><?php echo $article; ?></div> +</div> +``` + +### [CLI](https://npmjs.com/package/posthtml-cli) + +```bash +npm i posthtml-cli +``` + +```json +"scripts": { + "posthtml": "posthtml -o output.html -i input.html -c config.json" +} +``` + +```bash +npm run posthtml +``` + +### [Gulp](https://gulpjs.com) + +```bash +npm i -D gulp-posthtml +``` + +```js +import tap from 'gulp-tap' +import posthtml from 'gulp-posthtml' +import { task, src, dest } from 'gulp' + +task('html', () => { + let path + + const plugins = [ require('posthtml-include')({ root: `${path}` }) ] + const options = {} + + src('src/**/*.html') + .pipe(tap((file) => path = file.path)) + .pipe(posthtml(plugins, options)) + .pipe(dest('build/')) +}) +``` + +Check [project-stub](https://github.com/posthtml/project-stub) for an example with Gulp + +### [Grunt](https://gruntjs.com) + +```bash +npm i -D grunt-posthtml +``` + +```js +posthtml: { + options: { + use: [ + require('posthtml-doctype')({ doctype: 'HTML 5' }), + require('posthtml-include')({ root: './', encoding: 'utf-8' }) + ] + }, + build: { + files: [ + { + dot: true, + cwd: 'html/', + src: ['*.html'], + dest: 'tmp/', + expand: true, + } + ] + } +} +``` + +### [Webpack](https://webpack.js.org) + +```bash +npm i -D html-loader posthtml-loader +``` + +#### v1.x + +**webpack.config.js** + +```js +const config = { + module: { + loaders: [ + { + test: /\.html$/, + loader: 'html!posthtml' + } + ] + }, + posthtml: (ctx) => ({ + parser: require('posthtml-pug'), + plugins: [ + require('posthtml-bem')() + ] + }) +} + +export default config +``` + +#### v2.x + +**webpack.config.js** + +```js +import { LoaderOptionsPlugin } from 'webpack' + +const config = { + module: { + rules: [ + { + test: /\.html$/, + use: [ + { + loader: 'html-loader', + options: { minimize: true } + }, + { + loader: 'posthtml-loader' + } + ] + } + ] + }, + plugins: [ + new LoaderOptionsPlugin({ + options: { + posthtml(ctx) { + return { + parser: require('posthtml-pug'), + plugins: [ + require('posthtml-bem')() + ] + } + } + } + }) + ] +} + +export default config +``` + +### [Rollup](https://rollupjs.org/) + +```bash +$ npm i rollup-plugin-posthtml -D +# or +$ npm i rollup-plugin-posthtml-template -D +``` + +```js +import { join } from 'path'; + +import posthtml from 'rollup-plugin-posthtml-template'; +// or +// import posthtml from 'rollup-plugin-posthtml'; + +import sugarml from 'posthtml-sugarml'; // npm i posthtml-sugarml -D +import include from 'posthtml-include'; // npm i posthtml-include -D + +export default { + entry: join(__dirname, 'main.js'), + dest: join(__dirname, 'bundle.js'), + format: 'iife', + plugins: [ + posthtml({ + parser: sugarml(), + plugins: [include()], + template: true // only rollup-plugin-posthtml-template + }) + ] +}; +``` + +## Parser + +```js +import pug from 'posthtml-pug' + +posthtml().process(html, { parser: pug(options) }).then((result) => result.html) +``` + +| Name |Description| +|:-----|:----------| +|[posthtml-pug](https://github.com/posthtml/posthtml-pug)|Pug Parser| +|[sugarml](https://github.com/posthtml/sugarml)|SugarML Parser| + + +## Plugins + +In case you want to develop your own plugin, we recommend using [posthtml-plugin-starter][plugin] to get started. + +- [posthtml-plugins](http://maltsev.github.io/posthtml-plugins) +- [awesome-posthtml](https://github.com/posthtml/awesome-posthtml) + +[plugin]: https://github.com/posthtml/posthtml-plugin-starter + +## Maintainers + +<table> + <tbody> + <tr> + <td align="center"> + <img width="150 height="150" + src="https://avatars0.githubusercontent.com/u/2789192?s=460&v=4"> + <br /> + <a href="https://github.com/scrum">Ivan Demidov</a> + </td> + <td align="center"> + <img width="150 height="150" + src="https://avatars.githubusercontent.com/u/1510217?v=3&s=150"> + <br /> + <a href="https://github.com/voischev">Ivan Voischev</a> + </td> + </tr> + <tbody> +</table> + +## Contributors + +<a href="https://github.com/posthtml/posthtml/graphs/contributors"><img src="https://opencollective.com/posthtml/contributors.svg?width=890&button=false" /></a> + +## Backers + +Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/posthtml#backer)] + +<a href="https://opencollective.com/posthtml#backers" target="_blank"><img src="https://opencollective.com/posthtml/backers.svg?width=885&button=false"></a> + +[chat]: https://badges.gitter.im/posthtml/PostHTML.svg +[chat-url]: https://gitter.im/posthtml/posthtml?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge" diff --git a/node_modules/posthtml/types/posthtml.d.ts b/node_modules/posthtml/types/posthtml.d.ts new file mode 100644 index 0000000..0088dd2 --- /dev/null +++ b/node_modules/posthtml/types/posthtml.d.ts @@ -0,0 +1,108 @@ +type Maybe<T> = void | T; +type MaybeArray<T> = T | T[]; + +declare namespace PostHTML { + type StringMatcher = string | RegExp; + type AttrMatcher = Record<string, StringMatcher>; + type ContentMatcher = + | StringMatcher[] + | { + tag?: StringMatcher; + attrs?: AttrMatcher; + content?: ContentMatcher[]; + }; + + export type Matcher< + TTag extends StringMatcher, + TAttrs extends Maybe<AttrMatcher> + > = + | StringMatcher + | { + tag?: TTag; + attrs?: TAttrs; + content?: ContentMatcher[]; + }; + + export type Expression< + TTag extends StringMatcher, + TAttrs extends Maybe<AttrMatcher> + > = MaybeArray<Matcher<TTag, TAttrs>>; + + export type NodeCallback< + TTag extends Maybe<string> = Maybe<string>, + TAttrs extends Maybe<NodeAttributes> = Maybe<NodeAttributes> + > = (node: Node<TTag, TAttrs>) => MaybeArray<Node | RawNode>; + + export type NodeAttributes = Record<string, Maybe<string>>; + + interface NodeAPI { + walk: (cb: NodeCallback) => Node; + match: < + TTag extends StringMatcher, + TAttrs extends Maybe<AttrMatcher>, + TTagResult extends Maybe<string> = TTag extends string + ? TTag + : TTag extends void + ? Maybe<string> + : string, + TAttrResult extends Maybe<NodeAttributes> = TAttrs extends void + ? Maybe<NodeAttributes> + : { + [P in keyof TAttrs]: string; + } & + NodeAttributes + >( + expression: Expression<TTag, TAttrs>, + cb: NodeCallback<TTagResult, TAttrResult> + ) => Node<TTagResult, TAttrResult>[]; + } + + export interface RawNode< + TTag extends Maybe<string> = Maybe<string>, + TAttrs extends Maybe<NodeAttributes> = Maybe<NodeAttributes> + > { + tag: TTag; + attrs: TAttrs; + content?: Array<string | RawNode>; + } + + export interface Node< + TTag extends Maybe<string> = Maybe<string>, + TAttrs extends Maybe<NodeAttributes> = Maybe<NodeAttributes> + > extends NodeAPI, RawNode<TTag, TAttrs> { + content?: Array<string | Node>; + options?: Options; + } + + export interface Options { + sync?: boolean; + parser?: Function; + render?: Function; + skipParse?: boolean; + } + + export type Plugin<TThis> = ( + tree: Node + ) => void | Node | RawNode | ThisType<TThis>; + + export interface Result<TMessage> { + html: string; + tree: Node; + messages: TMessage[]; + } + + export interface PostHTML<TThis, TMessage> { + version: string; + name: ""; + plugins: Plugin<TThis>[]; + messages: TMessage[]; + use<TThis>(plugins: MaybeArray<Plugin<TThis>>): this; + process(html: string, options?: Options): Promise<Result<TMessage>>; + } +} + +declare function PostHTML<TThis, TMessage>( + plugins?: PostHTML.Plugin<TThis>[] +): PostHTML.PostHTML<TThis, TMessage>; + +export = PostHTML; |
