diff --git a/composables/language/html.ts b/composables/language/html.ts new file mode 100644 index 0000000..6c1476c --- /dev/null +++ b/composables/language/html.ts @@ -0,0 +1,32 @@ +import type * as Htmlparser2 from 'htmlparser2' +import type { LanguageOption, Parser } from '../language' + +// @unocss-include + +const htmlparser2: Parser = { + id: 'htmlparser2', + label: 'htmlparser2', + icon: 'i-vscode-icons:file-type-html', + editorLanguage: 'html', + options: { + configurable: true, + defaultValue: 'return {}', + editorLanguage: 'javascript', + defaultValueType: 'javascript', + }, + // @ts-expect-error + init: () => import('https://cdn.jsdelivr.net/npm/htmlparser2@9.1.0/+esm'), + version: () => + fetch('https://cdn.jsdelivr.net/npm/htmlparser2/package.json') + .then((r) => r.json()) + .then((raw) => `htmlparser2@${raw.version}`), + parse(code, options) { + return this.parseDocument(code, options) + }, +} + +export const html: LanguageOption = { + label: 'HTML', + icon: 'i-vscode-icons:file-type-html', + parsers: [htmlparser2], +} diff --git a/composables/language/index.ts b/composables/language/index.ts index 95f0876..55acc20 100644 --- a/composables/language/index.ts +++ b/composables/language/index.ts @@ -2,6 +2,7 @@ import { javascript } from './javascript' import { vue } from './vue' import { svelte } from './svelte' import { json } from './json' +import { html } from './html' import type { JsonNode, Range } from '#imports' export interface Parser { @@ -38,6 +39,7 @@ export const LANGUAGES = { vue, svelte, json, + html, } export type Language = keyof typeof LANGUAGES diff --git a/package.json b/package.json index f487c00..ec108f0 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "bumpp": "^9.4.0", "eslint": "^8.57.0", "floating-vue": "5.2.2", + "htmlparser2": "^9.1.0", "nuxt": "3.10.3", "nuxt-monaco-editor": "^1.2.7", "onigasm": "^2.2.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9ebdb69..fc65cfe 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -73,6 +73,9 @@ devDependencies: floating-vue: specifier: 5.2.2 version: 5.2.2(vue@3.4.20) + htmlparser2: + specifier: ^9.1.0 + version: 9.1.0 nuxt: specifier: 3.10.3 version: 3.10.3(eslint@8.57.0)(typescript@5.4.2)(vite@5.1.4)(vue-tsc@1.8.27) @@ -5475,6 +5478,15 @@ packages: engines: {node: '>=8'} dev: true + /htmlparser2@9.1.0: + resolution: {integrity: sha512-5zfg6mHUoaer/97TxnGpxmbR7zJtPwIYFMZ/H5ucTlPZhKvtum05yiPK3Mgai3a0DyVxv7qYqoweaEd2nrYQzQ==} + dependencies: + domelementtype: 2.3.0 + domhandler: 5.0.3 + domutils: 3.1.0 + entities: 4.5.0 + dev: true + /http-cache-semantics@4.1.1: resolution: {integrity: sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==} dev: true