12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- const PostHTML = require('posthtml');
- const parser = require('./parser');
- const renderer = require('./renderer');
- class PostHTMLProcessingResult {
- constructor(tree) {
- this.tree = tree;
- }
- get html() {
- return this.toString();
- }
- toString() {
- return renderer(this.tree, this.tree.options);
- }
- render() {
- return this.toString();
- }
- }
- class Processor {
-
- constructor(plugins) {
- const posthtml = this.posthtml = PostHTML(plugins);
- this.version = posthtml.version;
- this.name = posthtml.name;
- this.plugins = posthtml.plugins;
- }
-
- use(...plugins) {
- this.posthtml.use.apply(this, ...plugins);
- return this;
- }
-
- process(ast, options = null) {
- const opts = Object.assign({ parser }, options);
- return this.posthtml.process(ast, opts).then(({ tree }) => new PostHTMLProcessingResult(tree));
- }
- }
- Processor.parser = parser;
- Processor.render = renderer;
- module.exports = plugins => new Processor(plugins);
- module.exports.parser = parser;
- module.exports.renderer = renderer;
- module.exports.Processor = Processor;
- module.exports.Result = PostHTMLProcessingResult;
|