posthtml-typograf
Version:
PostHTML plugin for typograf
25 lines (19 loc) • 635 B
JavaScript
import parser from "posthtml-parser";
import render from "posthtml-render";
import Typograf from "typograf";
const DEFAULT_OPTIONS = {
htmlEntity: { type: "name" },
locale: ["ru", "en-US"],
};
export function getPosthtmlTypograf(disabledRules = [], options = {}) {
return (tree) => parser(typografy(render(tree), disabledRules, options));
}
export function typografy(html, disabledRules = [], options = {}) {
const typograf = new Typograf({ ...DEFAULT_OPTIONS, ...options });
disabledRules.forEach((rule) => typograf.disableRule(rule));
return typograf.execute(html);
}
export default {
getPosthtmlTypograf,
typografy,
};