- Notifications
You must be signed in to change notification settings - Fork21
HTML language support for the CodeMirror code editor
License
codemirror/lang-html
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
[WEBSITE |ISSUES |FORUM |CHANGELOG ]
This package implements HTML language support for theCodeMirror code editor.
Theproject page has more information, anumber ofexamples and thedocumentation.
This code is released under anMIT license.
We aim to be an inclusive, welcoming community. To make that explicit,we have acode ofconduct that appliesto communication around the project.
import{EditorView,basicSetup}from"codemirror"import{html}from"@codemirror/lang-html"constview=newEditorView({parent:document.body,doc:`<!doctype html>\n<title>HTML</title>`,extensions:[basicSetup,html()]})
html(config?: Object = {}) → LanguageSupportLanguage support for HTML, including
htmlCompletionand JavaScript andCSS support extensions.configmatchClosingTags?:booleanBy default, the syntax tree will highlight mismatched closingtags. Set this to
falseto turn that off (for example when youexpect to only be parsing a fragment of HTML text, not a fulldocument).selfClosingTags?:booleanBy default, the parser does not allow arbitrary self-closing tags.Set this to
trueto turn on support for/>self-closing tagsyntax.autoCloseTags?:booleanDetermines whether
autoCloseTagsis included in the support extensions. Defaults to true.extraTags?:Record<string,TagSpec>Add additional tags that can be completed.
extraGlobalAttributes?:Record<string, readonly string[] |null>Add additional completable attributes to all tags.
nestedLanguages?: {tag: string, attrs?: fn(attrs: Object<string>) → boolean, parser: Parser}[]Register additional languages to parse the content of specifictags. If given,
attrsshould be a function that, given anobject representing the tag's attributes, returnstrueif thislanguage applies.nestedAttributes?: {name: string, tagName?: string, parser: Parser}[]Register additional languages to parse attribute values with.
htmlLanguage:LRLanguageA language provider based on theLezer HTMLparser, extended with theJavaScript and CSS parsers to parse the content of
<script>and<style>tags.htmlCompletionSource(context: CompletionContext) → CompletionResult |nullHTML tag completion. Opens and closes tags and attributes in acontext-aware way.
interfaceTagSpecType used to specify tags to complete.
attrs?:Record<string, readonly string[] |null>Define tag-specific attributes. Property names are attributenames, and property values can be null to indicate free-formattributes, or a list of strings for suggested attribute values.
globalAttrs?:booleanWhen set to false, don't complete global attributes on this tag.
children?: readonly string[]Can be used to specify a list of child tags that are validinside this tag. The default is to allow any tag.
htmlCompletionSourceWith(config: Object) → fn(context: CompletionContext) → CompletionResult |nullCreate a completion source for HTML extended with additional tagsor attributes.
autoCloseTags:ExtensionExtension that will automatically insert close tags when a
>or/is typed.
About
HTML language support for the CodeMirror code editor
Resources
License
Uh oh!
There was an error while loading.Please reload this page.