完成世界书、骰子、apiconfig页面处理

This commit is contained in:
2026-04-30 01:35:10 +08:00
parent a3e3711b2b
commit ba9b925c32
4602 changed files with 785225 additions and 23 deletions

View File

@@ -0,0 +1,30 @@
/**
* @typedef {import('hast').Root} Root
*
* @typedef {typeof import('./index.js').fromHtmlIsomorphic} FromHtmlIsomorphic
*/
import {fromDom} from 'hast-util-from-dom'
const parser = new DOMParser()
/** @type {FromHtmlIsomorphic} */
export function fromHtmlIsomorphic(value, options) {
const node = options?.fragment
? parseFragment(value)
: parser.parseFromString(value, 'text/html')
return /** @type {Root} */ (fromDom(node))
}
/**
* Parse as a fragment.
*
* @param {string} value
* @returns {DocumentFragment}
*/
function parseFragment(value) {
const template = document.createElement('template')
template.innerHTML = value
return template.content
}

View File

@@ -0,0 +1,14 @@
/**
* Turn HTML into a syntax tree, using browser APIs when available, so it has
* a smaller bundle size there.
*
* @param {string} value
* Serialized HTML to parse.
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns {Root}
* Tree.
*/
export function fromHtmlIsomorphic(value: string, options?: Options | null | undefined): Root;
export type Root = import('hast').Root;
export type Options = Pick<import('hast-util-from-html').Options, 'fragment'>;