Skip to content

Commit

Permalink
feat: add htmlparser2
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Mar 13, 2024
1 parent b4ee628 commit 588d99d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
32 changes: 32 additions & 0 deletions composables/language/html.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type * as Htmlparser2 from 'htmlparser2'
import type { LanguageOption, Parser } from '../language'

// @unocss-include

const htmlparser2: Parser<typeof Htmlparser2, Htmlparser2.Options> = {
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],
}
2 changes: 2 additions & 0 deletions composables/language/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<C = unknown, O = unknown> {
Expand Down Expand Up @@ -38,6 +39,7 @@ export const LANGUAGES = {
vue,
svelte,
json,
html,
}
export type Language = keyof typeof LANGUAGES

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 588d99d

Please sign in to comment.