diff --git a/package.json b/package.json index c9fd162..ccb8038 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ }, "dependencies": { "debug": "^4.3.1", + "doctype": "^2.0.4", "github-slugger": "^1.3.0", "hast-util-find-and-replace": "^3.2.0", "hast-util-is-element": "^1.1.0", @@ -66,7 +67,6 @@ "mdast-util-to-string": "^2.0.0", "meow": "^9.0.0", "refractor": "^3.3.0", - "rehype-document": "^5.1.0", "rehype-format": "^3.1.0", "rehype-katex": "^4.0.0", "rehype-raw": "^5.0.0", @@ -108,14 +108,14 @@ "common-tags": "^1.8.0", "eslint": "^7.18.0", "husky": "^4.3.8", - "jest": "^26.6.3", + "jest": "^27.0.1", "lint-staged": "^10.5.3", "prettier": "^2.2.1", "prettier-plugin-organize-imports": "^1.1.1", "pretty-quick": "^3.1.0", "release-it": "^14.2.2", "shx": "^0.3.3", - "ts-jest": "^26.5.4", + "ts-jest": "^27.0.1", "typescript": "^4.2.3" } } diff --git a/src/index.ts b/src/index.ts index 9481727..5469adb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,8 @@ -import doc from 'rehype-document'; import rehypeFormat from 'rehype-format'; import rehypeStringify from 'rehype-stringify'; import unified, { Processor } from 'unified'; import { hast as hastClearHtmlLang } from './plugins/clear-html-lang'; +import { mdast as doc } from './plugins/document'; import { hast as hastMath } from './plugins/math'; import { hast as hastMetadata, MetadataVFile } from './plugins/metadata'; import { replace as handleReplace, ReplaceRule } from './plugins/replace'; @@ -79,7 +79,7 @@ export function VFM({ } if (!partial) { - processor.use(doc, { language, css: style, title }); + processor.use(doc, { language, css: style, title, responsive: true }); if (!language) { processor.use(hastClearHtmlLang); } diff --git a/src/plugins/document.ts b/src/plugins/document.ts new file mode 100644 index 0000000..6e762d0 --- /dev/null +++ b/src/plugins/document.ts @@ -0,0 +1,157 @@ +/** + * derived from `rehype-document`. + * original: Copyright (c) 2016 Titus Wormer + * modified: 2021 and later is Akabeko + * @license MIT + * @see https://github.com/rehypejs/rehype-document + */ + +import doctype from 'doctype'; +import { Properties } from 'hast'; +import h from 'hastscript'; +import { Node } from 'unist'; +import { VFile } from 'vfile'; + +/** Options. */ +export type DocOptions = { + /** Text of . */ + language?: string; + /** + * Version of HTML. + * @see https://github.com/wooorm/doctype + */ + doctype?: string; + /** Whether to insert a `meta[viewport]`. */ + responsive?: boolean; + /** Text of `...`. */ + title?: string; + /** Array of ``. */ + meta?: Properties | Properties[]; + /** Array of ``. */ + link?: Properties | Properties[]; + /** Array of `` */ + style?: string | string[]; + /** Array of ``. */ + css?: string | string[]; + /** Array of ``. */ + script?: string | string[]; + /** Array of `` to end of `` + { + const scripts = castArray(options.script); + for (const script of scripts) { + contents.push({ type: 'text', value: '\n' }, h('script', script)); + } + } + + // `