@codemirror/lang-angular
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -0,1 +1,11 @@ | ||
## 0.1.2 (2023-06-23) | ||
### Bug fixes | ||
HTML support extensions now work in Angular mode. | ||
### New features | ||
`angular` now allows a base HTML configuration to be passed in. | ||
## 0.1.1 (2023-06-05) | ||
@@ -2,0 +12,0 @@ |
@@ -10,4 +10,11 @@ import { LRLanguage, LanguageSupport } from '@codemirror/language'; | ||
*/ | ||
declare function angular(): LanguageSupport; | ||
declare function angular(config?: { | ||
/** | ||
Provide an HTML language configuration to use as a base. _Must_ | ||
be the result of calling `html()` from `@codemirror/lang-html`, | ||
not just any `LanguageSupport` object. | ||
*/ | ||
base?: LanguageSupport; | ||
}): LanguageSupport; | ||
export { angular, angularLanguage }; |
import { LRLanguage, LanguageSupport } from '@codemirror/language'; | ||
import { htmlLanguage } from '@codemirror/lang-html'; | ||
import { html } from '@codemirror/lang-html'; | ||
import { javascriptLanguage } from '@codemirror/lang-javascript'; | ||
@@ -102,15 +102,10 @@ import { styleTags, tags } from '@lezer/highlight'; | ||
const textMixed = { parser: textParser }, attrMixed = { parser: attrParser }; | ||
const baseHTML = /*@__PURE__*/html(); | ||
function mkAngular(language) { | ||
return language.configure({ wrap: parseMixed(mixAngular) }, "angular"); | ||
} | ||
/** | ||
A language provider for Angular Templates. | ||
*/ | ||
const angularLanguage = /*@__PURE__*/LRLanguage.define({ | ||
name: "angular", | ||
parser: /*@__PURE__*/htmlLanguage.parser.configure({ | ||
wrap: /*@__PURE__*/parseMixed(mixAngular) | ||
}), | ||
languageData: { | ||
closeBrackets: { brackets: ["[", "{", '"'] }, | ||
indentOnInput: /^\s*[\}\]]$/ | ||
} | ||
}); | ||
const angularLanguage = /*@__PURE__*/mkAngular(baseHTML.language); | ||
function mixAngular(node, input) { | ||
@@ -128,6 +123,15 @@ switch (node.name) { | ||
*/ | ||
function angular() { | ||
return new LanguageSupport(angularLanguage); | ||
function angular(config = {}) { | ||
let base = baseHTML; | ||
if (config.base) { | ||
if (config.base.language.name != "html" || !(config.base.language instanceof LRLanguage)) | ||
throw new RangeError("The base option must be the result of calling html(...)"); | ||
base = config.base; | ||
} | ||
return new LanguageSupport(base.language == baseHTML.language ? angularLanguage : mkAngular(base.language), [base.support, base.language.data.of({ | ||
closeBrackets: { brackets: ["[", "{", '"'] }, | ||
indentOnInput: /^\s*[\}\]]$/ | ||
})]); | ||
} | ||
export { angular, angularLanguage }; |
{ | ||
"name": "@codemirror/lang-angular", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Angular Template language support for the CodeMirror code editor", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -26,6 +26,15 @@ <!-- NOTE: README.md is generated from src/README.md --> | ||
<dt id="user-content-angular"> | ||
<code><strong><a href="#user-content-angular">angular</a></strong>() → <a href="https://codemirror.net/docs/ref#language.LanguageSupport">LanguageSupport</a></code></dt> | ||
<code><strong><a href="#user-content-angular">angular</a></strong>(<a id="user-content-angular^config" href="#user-content-angular^config">config</a>⁠?: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a> = {}) → <a href="https://codemirror.net/docs/ref#language.LanguageSupport">LanguageSupport</a></code></dt> | ||
<dd><p>Angular Template language support.</p> | ||
</dd> | ||
<dl><dt id="user-content-angular^config"> | ||
<code><strong><a href="#user-content-angular^config">config</a></strong></code></dt> | ||
<dd><dl><dt id="user-content-angular^config.base"> | ||
<code><strong><a href="#user-content-angular^config.base">base</a></strong>⁠?: <a href="https://codemirror.net/docs/ref#language.LanguageSupport">LanguageSupport</a></code></dt> | ||
<dd><p>Provide an HTML language configuration to use as a base. <em>Must</em> | ||
be the result of calling <code>html()</code> from <code>@codemirror/lang-html</code>, | ||
not just any <code>LanguageSupport</code> object.</p> | ||
</dd></dl></dd></dl></dd> | ||
<dt id="user-content-angularlanguage"> | ||
@@ -32,0 +41,0 @@ <code><strong><a href="#user-content-angularlanguage">angularLanguage</a></strong>: <a href="https://codemirror.net/docs/ref#language.LRLanguage">LRLanguage</a></code></dt> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21725
298
45