Skip to content

Commit

Permalink
Add support for the "selfClosing" dialect. (#3)
Browse files Browse the repository at this point in the history
Upgrade @lezer/html to 1.1.0 and add support for the newly introduced
"selfClosing" dialect.

FEATURE: Add a `selfClosingTags` option to `html` that enables `/>` syntax.
  • Loading branch information
bmeurer authored Nov 16, 2022
1 parent 223851b commit e2fe9d3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@codemirror/lang-javascript": "^6.0.0",
"@codemirror/language": "^6.0.0",
"@codemirror/state": "^6.0.0",
"@lezer/html": "^1.0.1",
"@lezer/html": "^1.1.0",
"@lezer/common": "^1.0.0",
"@codemirror/view": "^6.2.2"
},
Expand Down
5 changes: 5 additions & 0 deletions src/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ export function html(config: {
/// expect to only be parsing a fragment of HTML text, not a full
/// document).
matchClosingTags?: boolean,
// By default, the parser does not allow arbitrary self-closing tags.
// Set this to `true` to turn on support for `/>` self-closing tag
// syntax.
selfClosingTags?: boolean,
/// Determines whether [`autoCloseTags`](#lang-html.autoCloseTags)
/// is included in the support extensions. Defaults to true.
autoCloseTags?: boolean,
Expand All @@ -94,6 +98,7 @@ export function html(config: {
} = {}) {
let lang = htmlLanguage
if (config.matchClosingTags === false) lang = lang.configure({dialect: "noMatch"})
if (config.selfClosingTags === true) lang = lang.configure({dialect: "selfClosing"})
return new LanguageSupport(lang, [
htmlLanguage.data.of({autocomplete: htmlCompletionSourceWith(config)}),
config.autoCloseTags !== false ? autoCloseTags: [],
Expand Down

0 comments on commit e2fe9d3

Please sign in to comment.