hexo-filter-auto-spacing
hexo-filter-auto-spacing copied to clipboard
pangu.js supports NodeJS
pangu.js
added support for NodeJS and pangunode has been deprecated.
A possible usage:
const pangu = require('pangu');
data.title = pangu.spacing(data.title);
data.content = pangu.spacing(data.content);
Related PR: #8 #9
There are four approaches:
- https://github.com/hexojs/hexo-filter-auto-spacing/pull/8 uses remark (to parse markdown).
- https://github.com/hexojs/hexo-filter-auto-spacing/pull/9 uses cheerio
- https://github.com/hexojs/hexo-filter-auto-spacing/pull/12 uses regex
- https://github.com/hexojs/hexo-filter-auto-spacing/pull/13 uses html-dom-parser
Using this test post, currently cheerio yields the best result.
@curbengh I think we might bring up a unit test first.
Using jsdom allows pangu to get exactly the same behavior in Node.js as in the browser
const { JSDOM } = require('jsdom');
const dom = new JSDOM();
const { window } = dom;
const { document, Node, DocumentFragment, XPathResult } = window;
global.document = document;
global.Node = Node;
global.DocumentFragment = DocumentFragment;
global.XPathResult = XPathResult;
const pangu = require('pangu/src/browser/pangu');
hexo.extend.filter.register('after_post_render', data => {
document.body.innerHTML = data.content;
pangu.spacingPageBody();
data.content = document.body.innerHTML;
data.title = pangu.spacing(data.title);
}, 8);
Its disadvantage is that it takes more time and memory than other methods