UNPKG

monaco-editor

Version:
774 lines (772 loc) 412 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ define('vscode-nls/vscode-nls',["require", "exports"], function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function format(message, args) { var result; if (args.length === 0) { result = message; } else { result = message.replace(/\{(\d+)\}/g, function (match, rest) { var index = rest[0]; return typeof args[index] !== 'undefined' ? args[index] : match; }); } return result; } function localize(key, message) { var args = []; for (var _i = 2; _i < arguments.length; _i++) { args[_i - 2] = arguments[_i]; } return format(message, args); } function loadMessageBundle(file) { return localize; } exports.loadMessageBundle = loadMessageBundle; function config(opt) { return loadMessageBundle; } exports.config = config; }); define('vscode-nls', ['vscode-nls/vscode-nls'], function (main) { return main; }); (function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define('vscode-html-languageservice/htmlLanguageTypes',["require", "exports"], factory); } })(function (require, exports) { /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var TokenType; (function (TokenType) { TokenType[TokenType["StartCommentTag"] = 0] = "StartCommentTag"; TokenType[TokenType["Comment"] = 1] = "Comment"; TokenType[TokenType["EndCommentTag"] = 2] = "EndCommentTag"; TokenType[TokenType["StartTagOpen"] = 3] = "StartTagOpen"; TokenType[TokenType["StartTagClose"] = 4] = "StartTagClose"; TokenType[TokenType["StartTagSelfClose"] = 5] = "StartTagSelfClose"; TokenType[TokenType["StartTag"] = 6] = "StartTag"; TokenType[TokenType["EndTagOpen"] = 7] = "EndTagOpen"; TokenType[TokenType["EndTagClose"] = 8] = "EndTagClose"; TokenType[TokenType["EndTag"] = 9] = "EndTag"; TokenType[TokenType["DelimiterAssign"] = 10] = "DelimiterAssign"; TokenType[TokenType["AttributeName"] = 11] = "AttributeName"; TokenType[TokenType["AttributeValue"] = 12] = "AttributeValue"; TokenType[TokenType["StartDoctypeTag"] = 13] = "StartDoctypeTag"; TokenType[TokenType["Doctype"] = 14] = "Doctype"; TokenType[TokenType["EndDoctypeTag"] = 15] = "EndDoctypeTag"; TokenType[TokenType["Content"] = 16] = "Content"; TokenType[TokenType["Whitespace"] = 17] = "Whitespace"; TokenType[TokenType["Unknown"] = 18] = "Unknown"; TokenType[TokenType["Script"] = 19] = "Script"; TokenType[TokenType["Styles"] = 20] = "Styles"; TokenType[TokenType["EOS"] = 21] = "EOS"; })(TokenType = exports.TokenType || (exports.TokenType = {})); var ScannerState; (function (ScannerState) { ScannerState[ScannerState["WithinContent"] = 0] = "WithinContent"; ScannerState[ScannerState["AfterOpeningStartTag"] = 1] = "AfterOpeningStartTag"; ScannerState[ScannerState["AfterOpeningEndTag"] = 2] = "AfterOpeningEndTag"; ScannerState[ScannerState["WithinDoctype"] = 3] = "WithinDoctype"; ScannerState[ScannerState["WithinTag"] = 4] = "WithinTag"; ScannerState[ScannerState["WithinEndTag"] = 5] = "WithinEndTag"; ScannerState[ScannerState["WithinComment"] = 6] = "WithinComment"; ScannerState[ScannerState["WithinScriptContent"] = 7] = "WithinScriptContent"; ScannerState[ScannerState["WithinStyleContent"] = 8] = "WithinStyleContent"; ScannerState[ScannerState["AfterAttributeName"] = 9] = "AfterAttributeName"; ScannerState[ScannerState["BeforeAttributeValue"] = 10] = "BeforeAttributeValue"; })(ScannerState = exports.ScannerState || (exports.ScannerState = {})); }); //# sourceMappingURL=htmlLanguageTypes.js.map; (function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define('vscode-html-languageservice/parser/htmlScanner',["require", "exports", "vscode-nls", "../htmlLanguageTypes"], factory); } })(function (require, exports) { /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var nls = require("vscode-nls"); var htmlLanguageTypes_1 = require("../htmlLanguageTypes"); var localize = nls.loadMessageBundle(); var MultiLineStream = /** @class */ (function () { function MultiLineStream(source, position) { this.source = source; this.len = source.length; this.position = position; } MultiLineStream.prototype.eos = function () { return this.len <= this.position; }; MultiLineStream.prototype.getSource = function () { return this.source; }; MultiLineStream.prototype.pos = function () { return this.position; }; MultiLineStream.prototype.goBackTo = function (pos) { this.position = pos; }; MultiLineStream.prototype.goBack = function (n) { this.position -= n; }; MultiLineStream.prototype.advance = function (n) { this.position += n; }; MultiLineStream.prototype.goToEnd = function () { this.position = this.source.length; }; MultiLineStream.prototype.nextChar = function () { return this.source.charCodeAt(this.position++) || 0; }; MultiLineStream.prototype.peekChar = function (n) { if (n === void 0) { n = 0; } return this.source.charCodeAt(this.position + n) || 0; }; MultiLineStream.prototype.advanceIfChar = function (ch) { if (ch === this.source.charCodeAt(this.position)) { this.position++; return true; } return false; }; MultiLineStream.prototype.advanceIfChars = function (ch) { var i; if (this.position + ch.length > this.source.length) { return false; } for (i = 0; i < ch.length; i++) { if (this.source.charCodeAt(this.position + i) !== ch[i]) { return false; } } this.advance(i); return true; }; MultiLineStream.prototype.advanceIfRegExp = function (regex) { var str = this.source.substr(this.position); var match = str.match(regex); if (match) { this.position = this.position + match.index + match[0].length; return match[0]; } return ''; }; MultiLineStream.prototype.advanceUntilRegExp = function (regex) { var str = this.source.substr(this.position); var match = str.match(regex); if (match) { this.position = this.position + match.index; return match[0]; } else { this.goToEnd(); } return ''; }; MultiLineStream.prototype.advanceUntilChar = function (ch) { while (this.position < this.source.length) { if (this.source.charCodeAt(this.position) === ch) { return true; } this.advance(1); } return false; }; MultiLineStream.prototype.advanceUntilChars = function (ch) { while (this.position + ch.length <= this.source.length) { var i = 0; for (; i < ch.length && this.source.charCodeAt(this.position + i) === ch[i]; i++) { } if (i === ch.length) { return true; } this.advance(1); } this.goToEnd(); return false; }; MultiLineStream.prototype.skipWhitespace = function () { var n = this.advanceWhileChar(function (ch) { return ch === _WSP || ch === _TAB || ch === _NWL || ch === _LFD || ch === _CAR; }); return n > 0; }; MultiLineStream.prototype.advanceWhileChar = function (condition) { var posNow = this.position; while (this.position < this.len && condition(this.source.charCodeAt(this.position))) { this.position++; } return this.position - posNow; }; return MultiLineStream; }()); var _BNG = '!'.charCodeAt(0); var _MIN = '-'.charCodeAt(0); var _LAN = '<'.charCodeAt(0); var _RAN = '>'.charCodeAt(0); var _FSL = '/'.charCodeAt(0); var _EQS = '='.charCodeAt(0); var _DQO = '"'.charCodeAt(0); var _SQO = '\''.charCodeAt(0); var _NWL = '\n'.charCodeAt(0); var _CAR = '\r'.charCodeAt(0); var _LFD = '\f'.charCodeAt(0); var _WSP = ' '.charCodeAt(0); var _TAB = '\t'.charCodeAt(0); var htmlScriptContents = { 'text/x-handlebars-template': true }; function createScanner(input, initialOffset, initialState) { if (initialOffset === void 0) { initialOffset = 0; } if (initialState === void 0) { initialState = htmlLanguageTypes_1.ScannerState.WithinContent; } var stream = new MultiLineStream(input, initialOffset); var state = initialState; var tokenOffset = 0; var tokenType = htmlLanguageTypes_1.TokenType.Unknown; var tokenError; var hasSpaceAfterTag; var lastTag; var lastAttributeName; var lastTypeValue; function nextElementName() { return stream.advanceIfRegExp(/^[_:\w][_:\w-.\d]*/).toLowerCase(); } function nextAttributeName() { return stream.advanceIfRegExp(/^[^\s"'>/=\x00-\x0F\x7F\x80-\x9F]*/).toLowerCase(); } function finishToken(offset, type, errorMessage) { tokenType = type; tokenOffset = offset; tokenError = errorMessage; return type; } function scan() { var offset = stream.pos(); var oldState = state; var token = internalScan(); if (token !== htmlLanguageTypes_1.TokenType.EOS && offset === stream.pos()) { console.log('Scanner.scan has not advanced at offset ' + offset + ', state before: ' + oldState + ' after: ' + state); stream.advance(1); return finishToken(offset, htmlLanguageTypes_1.TokenType.Unknown); } return token; } function internalScan() { var offset = stream.pos(); if (stream.eos()) { return finishToken(offset, htmlLanguageTypes_1.TokenType.EOS); } var errorMessage; switch (state) { case htmlLanguageTypes_1.ScannerState.WithinComment: if (stream.advanceIfChars([_MIN, _MIN, _RAN])) { // --> state = htmlLanguageTypes_1.ScannerState.WithinContent; return finishToken(offset, htmlLanguageTypes_1.TokenType.EndCommentTag); } stream.advanceUntilChars([_MIN, _MIN, _RAN]); // --> return finishToken(offset, htmlLanguageTypes_1.TokenType.Comment); case htmlLanguageTypes_1.ScannerState.WithinDoctype: if (stream.advanceIfChar(_RAN)) { state = htmlLanguageTypes_1.ScannerState.WithinContent; return finishToken(offset, htmlLanguageTypes_1.TokenType.EndDoctypeTag); } stream.advanceUntilChar(_RAN); // > return finishToken(offset, htmlLanguageTypes_1.TokenType.Doctype); case htmlLanguageTypes_1.ScannerState.WithinContent: if (stream.advanceIfChar(_LAN)) { // < if (!stream.eos() && stream.peekChar() === _BNG) { // ! if (stream.advanceIfChars([_BNG, _MIN, _MIN])) { // <!-- state = htmlLanguageTypes_1.ScannerState.WithinComment; return finishToken(offset, htmlLanguageTypes_1.TokenType.StartCommentTag); } if (stream.advanceIfRegExp(/^!doctype/i)) { state = htmlLanguageTypes_1.ScannerState.WithinDoctype; return finishToken(offset, htmlLanguageTypes_1.TokenType.StartDoctypeTag); } } if (stream.advanceIfChar(_FSL)) { // / state = htmlLanguageTypes_1.ScannerState.AfterOpeningEndTag; return finishToken(offset, htmlLanguageTypes_1.TokenType.EndTagOpen); } state = htmlLanguageTypes_1.ScannerState.AfterOpeningStartTag; return finishToken(offset, htmlLanguageTypes_1.TokenType.StartTagOpen); } stream.advanceUntilChar(_LAN); return finishToken(offset, htmlLanguageTypes_1.TokenType.Content); case htmlLanguageTypes_1.ScannerState.AfterOpeningEndTag: var tagName = nextElementName(); if (tagName.length > 0) { state = htmlLanguageTypes_1.ScannerState.WithinEndTag; return finishToken(offset, htmlLanguageTypes_1.TokenType.EndTag); } if (stream.skipWhitespace()) { // white space is not valid here return finishToken(offset, htmlLanguageTypes_1.TokenType.Whitespace, localize('error.unexpectedWhitespace', 'Tag name must directly follow the open bracket.')); } state = htmlLanguageTypes_1.ScannerState.WithinEndTag; stream.advanceUntilChar(_RAN); if (offset < stream.pos()) { return finishToken(offset, htmlLanguageTypes_1.TokenType.Unknown, localize('error.endTagNameExpected', 'End tag name expected.')); } return internalScan(); case htmlLanguageTypes_1.ScannerState.WithinEndTag: if (stream.skipWhitespace()) { // white space is valid here return finishToken(offset, htmlLanguageTypes_1.TokenType.Whitespace); } if (stream.advanceIfChar(_RAN)) { // > state = htmlLanguageTypes_1.ScannerState.WithinContent; return finishToken(offset, htmlLanguageTypes_1.TokenType.EndTagClose); } errorMessage = localize('error.tagNameExpected', 'Closing bracket expected.'); break; case htmlLanguageTypes_1.ScannerState.AfterOpeningStartTag: lastTag = nextElementName(); lastTypeValue = void 0; lastAttributeName = void 0; if (lastTag.length > 0) { hasSpaceAfterTag = false; state = htmlLanguageTypes_1.ScannerState.WithinTag; return finishToken(offset, htmlLanguageTypes_1.TokenType.StartTag); } if (stream.skipWhitespace()) { // white space is not valid here return finishToken(offset, htmlLanguageTypes_1.TokenType.Whitespace, localize('error.unexpectedWhitespace', 'Tag name must directly follow the open bracket.')); } state = htmlLanguageTypes_1.ScannerState.WithinTag; stream.advanceUntilChar(_RAN); if (offset < stream.pos()) { return finishToken(offset, htmlLanguageTypes_1.TokenType.Unknown, localize('error.startTagNameExpected', 'Start tag name expected.')); } return internalScan(); case htmlLanguageTypes_1.ScannerState.WithinTag: if (stream.skipWhitespace()) { hasSpaceAfterTag = true; // remember that we have seen a whitespace return finishToken(offset, htmlLanguageTypes_1.TokenType.Whitespace); } if (hasSpaceAfterTag) { lastAttributeName = nextAttributeName(); if (lastAttributeName.length > 0) { state = htmlLanguageTypes_1.ScannerState.AfterAttributeName; hasSpaceAfterTag = false; return finishToken(offset, htmlLanguageTypes_1.TokenType.AttributeName); } } if (stream.advanceIfChars([_FSL, _RAN])) { // /> state = htmlLanguageTypes_1.ScannerState.WithinContent; return finishToken(offset, htmlLanguageTypes_1.TokenType.StartTagSelfClose); } if (stream.advanceIfChar(_RAN)) { // > if (lastTag === 'script') { if (lastTypeValue && htmlScriptContents[lastTypeValue]) { // stay in html state = htmlLanguageTypes_1.ScannerState.WithinContent; } else { state = htmlLanguageTypes_1.ScannerState.WithinScriptContent; } } else if (lastTag === 'style') { state = htmlLanguageTypes_1.ScannerState.WithinStyleContent; } else { state = htmlLanguageTypes_1.ScannerState.WithinContent; } return finishToken(offset, htmlLanguageTypes_1.TokenType.StartTagClose); } stream.advance(1); return finishToken(offset, htmlLanguageTypes_1.TokenType.Unknown, localize('error.unexpectedCharacterInTag', 'Unexpected character in tag.')); case htmlLanguageTypes_1.ScannerState.AfterAttributeName: if (stream.skipWhitespace()) { hasSpaceAfterTag = true; return finishToken(offset, htmlLanguageTypes_1.TokenType.Whitespace); } if (stream.advanceIfChar(_EQS)) { state = htmlLanguageTypes_1.ScannerState.BeforeAttributeValue; return finishToken(offset, htmlLanguageTypes_1.TokenType.DelimiterAssign); } state = htmlLanguageTypes_1.ScannerState.WithinTag; return internalScan(); // no advance yet - jump to WithinTag case htmlLanguageTypes_1.ScannerState.BeforeAttributeValue: if (stream.skipWhitespace()) { return finishToken(offset, htmlLanguageTypes_1.TokenType.Whitespace); } var attributeValue = stream.advanceIfRegExp(/^[^\s"'`=<>\/]+/); if (attributeValue.length > 0) { if (lastAttributeName === 'type') { lastTypeValue = attributeValue; } state = htmlLanguageTypes_1.ScannerState.WithinTag; hasSpaceAfterTag = false; return finishToken(offset, htmlLanguageTypes_1.TokenType.AttributeValue); } var ch = stream.peekChar(); if (ch === _SQO || ch === _DQO) { stream.advance(1); // consume quote if (stream.advanceUntilChar(ch)) { stream.advance(1); // consume quote } if (lastAttributeName === 'type') { lastTypeValue = stream.getSource().substring(offset + 1, stream.pos() - 1); } state = htmlLanguageTypes_1.ScannerState.WithinTag; hasSpaceAfterTag = false; return finishToken(offset, htmlLanguageTypes_1.TokenType.AttributeValue); } state = htmlLanguageTypes_1.ScannerState.WithinTag; hasSpaceAfterTag = false; return internalScan(); // no advance yet - jump to WithinTag case htmlLanguageTypes_1.ScannerState.WithinScriptContent: // see http://stackoverflow.com/questions/14574471/how-do-browsers-parse-a-script-tag-exactly var sciptState = 1; while (!stream.eos()) { var match = stream.advanceIfRegExp(/<!--|-->|<\/?script\s*\/?>?/i); if (match.length === 0) { stream.goToEnd(); return finishToken(offset, htmlLanguageTypes_1.TokenType.Script); } else if (match === '<!--') { if (sciptState === 1) { sciptState = 2; } } else if (match === '-->') { sciptState = 1; } else if (match[1] !== '/') { // <script if (sciptState === 2) { sciptState = 3; } } else { // </script if (sciptState === 3) { sciptState = 2; } else { stream.goBack(match.length); // to the beginning of the closing tag break; } } } state = htmlLanguageTypes_1.ScannerState.WithinContent; if (offset < stream.pos()) { return finishToken(offset, htmlLanguageTypes_1.TokenType.Script); } return internalScan(); // no advance yet - jump to content case htmlLanguageTypes_1.ScannerState.WithinStyleContent: stream.advanceUntilRegExp(/<\/style/i); state = htmlLanguageTypes_1.ScannerState.WithinContent; if (offset < stream.pos()) { return finishToken(offset, htmlLanguageTypes_1.TokenType.Styles); } return internalScan(); // no advance yet - jump to content } stream.advance(1); state = htmlLanguageTypes_1.ScannerState.WithinContent; return finishToken(offset, htmlLanguageTypes_1.TokenType.Unknown, errorMessage); } return { scan: scan, getTokenType: function () { return tokenType; }, getTokenOffset: function () { return tokenOffset; }, getTokenLength: function () { return stream.pos() - tokenOffset; }, getTokenEnd: function () { return stream.pos(); }, getTokenText: function () { return stream.getSource().substring(tokenOffset, stream.pos()); }, getScannerState: function () { return state; }, getTokenError: function () { return tokenError; } }; } exports.createScanner = createScanner; }); //# sourceMappingURL=htmlScanner.js.map; (function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define('vscode-html-languageservice/utils/arrays',["require", "exports"], factory); } })(function (require, exports) { /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); /** * Takes a sorted array and a function p. The array is sorted in such a way that all elements where p(x) is false * are located before all elements where p(x) is true. * @returns the least x for which p(x) is true or array.length if no element fullfills the given function. */ function findFirst(array, p) { var low = 0, high = array.length; if (high === 0) { return 0; // no children } while (low < high) { var mid = Math.floor((low + high) / 2); if (p(array[mid])) { high = mid; } else { low = mid + 1; } } return low; } exports.findFirst = findFirst; function binarySearch(array, key, comparator) { var low = 0, high = array.length - 1; while (low <= high) { var mid = ((low + high) / 2) | 0; var comp = comparator(array[mid], key); if (comp < 0) { low = mid + 1; } else if (comp > 0) { high = mid - 1; } else { return mid; } } return -(low + 1); } exports.binarySearch = binarySearch; }); //# sourceMappingURL=arrays.js.map; (function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define('vscode-html-languageservice/utils/strings',["require", "exports"], factory); } })(function (require, exports) { /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); function startsWith(haystack, needle) { if (haystack.length < needle.length) { return false; } for (var i = 0; i < needle.length; i++) { if (haystack[i] !== needle[i]) { return false; } } return true; } exports.startsWith = startsWith; /** * Determines if haystack ends with needle. */ function endsWith(haystack, needle) { var diff = haystack.length - needle.length; if (diff > 0) { return haystack.lastIndexOf(needle) === diff; } else if (diff === 0) { return haystack === needle; } else { return false; } } exports.endsWith = endsWith; /** * @returns the length of the common prefix of the two strings. */ function commonPrefixLength(a, b) { var i, len = Math.min(a.length, b.length); for (i = 0; i < len; i++) { if (a.charCodeAt(i) !== b.charCodeAt(i)) { return i; } } return len; } exports.commonPrefixLength = commonPrefixLength; function repeat(value, count) { var s = ''; while (count > 0) { if ((count & 1) === 1) { s += value; } value += value; count = count >>> 1; } return s; } exports.repeat = repeat; var _a = 'a'.charCodeAt(0); var _z = 'z'.charCodeAt(0); var _A = 'A'.charCodeAt(0); var _Z = 'Z'.charCodeAt(0); var _0 = '0'.charCodeAt(0); var _9 = '9'.charCodeAt(0); function isLetterOrDigit(text, index) { var c = text.charCodeAt(index); return (_a <= c && c <= _z) || (_A <= c && c <= _Z) || (_0 <= c && c <= _9); } exports.isLetterOrDigit = isLetterOrDigit; }); //# sourceMappingURL=strings.js.map; /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /*! BEGIN THIRD PARTY */ /*-------------------------------------------------------------------------------------------- * This file is based on or incorporates material from the projects listed below (Third Party IP). * The original copyright notice and the license under which Microsoft received such Third Party IP, * are set forth below. Such licenses and notices are provided for informational purposes only. * Microsoft licenses the Third Party IP to you under the licensing terms for the Microsoft product. * Microsoft reserves all other rights not expressly granted under this agreement, whether by implication, * estoppel or otherwise. *--------------------------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------------------------- * Copyright © 2015 W3C® (MIT, ERCIM, Keio, Beihang). This software or document includes includes material copied * from or derived from HTML 5.1 W3C Working Draft (http://www.w3.org/TR/2015/WD-html51-20151008/.)" *--------------------------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------------------------- * Ionic Main Site (https://github.com/driftyco/ionic-site). * Copyright Drifty Co. http://drifty.com/. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED * WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, * MERCHANTABLITY OR NON-INFRINGEMENT. * * See the Apache Version 2.0 License for specific language governing permissions * and limitations under the License. *--------------------------------------------------------------------------------------------*/ (function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define('vscode-html-languageservice/parser/htmlTags',["require", "exports", "../utils/strings", "../utils/arrays", "vscode-nls"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var strings = require("../utils/strings"); var arrays = require("../utils/arrays"); var nls = require("vscode-nls"); var localize = nls.loadMessageBundle(); exports.EMPTY_ELEMENTS = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr']; function isEmptyElement(e) { return !!e && arrays.binarySearch(exports.EMPTY_ELEMENTS, e.toLowerCase(), function (s1, s2) { return s1.localeCompare(s2); }) >= 0; } exports.isEmptyElement = isEmptyElement; var HTMLTagSpecification = /** @class */ (function () { function HTMLTagSpecification(label, attributes) { if (attributes === void 0) { attributes = []; } this.label = label; this.attributes = attributes; } return HTMLTagSpecification; }()); exports.HTMLTagSpecification = HTMLTagSpecification; // HTML tag information sourced from http://www.w3.org/TR/2015/WD-html51-20151008/ exports.HTML_TAGS = { // The root element html: new HTMLTagSpecification(localize('tags.html', 'The html element represents the root of an HTML document.'), ['manifest']), // Document metadata head: new HTMLTagSpecification(localize('tags.head', 'The head element represents a collection of metadata for the Document.')), title: new HTMLTagSpecification(localize('tags.title', 'The title element represents the document\'s title or name. Authors should use titles that identify their documents even when they are used out of context, for example in a user\'s history or bookmarks, or in search results. The document\'s title is often different from its first heading, since the first heading does not have to stand alone when taken out of context.')), base: new HTMLTagSpecification(localize('tags.base', 'The base element allows authors to specify the document base URL for the purposes of resolving relative URLs, and the name of the default browsing context for the purposes of following hyperlinks. The element does not represent any content beyond this information.'), ['href', 'target']), link: new HTMLTagSpecification(localize('tags.link', 'The link element allows authors to link their document to other resources.'), ['href', 'crossorigin:xo', 'rel', 'media', 'hreflang', 'type', 'sizes']), meta: new HTMLTagSpecification(localize('tags.meta', 'The meta element represents various kinds of metadata that cannot be expressed using the title, base, link, style, and script elements.'), ['name', 'http-equiv', 'content', 'charset']), style: new HTMLTagSpecification(localize('tags.style', 'The style element allows authors to embed style information in their documents. The style element is one of several inputs to the styling processing model. The element does not represent content for the user.'), ['media', 'nonce', 'type', 'scoped:v']), // Sections body: new HTMLTagSpecification(localize('tags.body', 'The body element represents the content of the document.'), ['onafterprint', 'onbeforeprint', 'onbeforeunload', 'onhashchange', 'onlanguagechange', 'onmessage', 'onoffline', 'ononline', 'onpagehide', 'onpageshow', 'onpopstate', 'onstorage', 'onunload']), article: new HTMLTagSpecification(localize('tags.article', 'The article element represents a complete, or self-contained, composition in a document, page, application, or site and that is, in principle, independently distributable or reusable, e.g. in syndication. This could be a forum post, a magazine or newspaper article, a blog entry, a user-submitted comment, an interactive widget or gadget, or any other independent item of content. Each article should be identified, typically by including a heading (h1–h6 element) as a child of the article element.')), section: new HTMLTagSpecification(localize('tags.section', 'The section element represents a generic section of a document or application. A section, in this context, is a thematic grouping of content. Each section should be identified, typically by including a heading ( h1- h6 element) as a child of the section element.')), nav: new HTMLTagSpecification(localize('tags.nav', 'The nav element represents a section of a page that links to other pages or to parts within the page: a section with navigation links.')), aside: new HTMLTagSpecification(localize('tags.aside', 'The aside element represents a section of a page that consists of content that is tangentially related to the content around the aside element, and which could be considered separate from that content. Such sections are often represented as sidebars in printed typography.')), h1: new HTMLTagSpecification(localize('tags.h1', 'The h1 element represents a section heading.')), h2: new HTMLTagSpecification(localize('tags.h2', 'The h2 element represents a section heading.')), h3: new HTMLTagSpecification(localize('tags.h3', 'The h3 element represents a section heading.')), h4: new HTMLTagSpecification(localize('tags.h4', 'The h4 element represents a section heading.')), h5: new HTMLTagSpecification(localize('tags.h5', 'The h5 element represents a section heading.')), h6: new HTMLTagSpecification(localize('tags.h6', 'The h6 element represents a section heading.')), header: new HTMLTagSpecification(localize('tags.header', 'The header element represents introductory content for its nearest ancestor sectioning content or sectioning root element. A header typically contains a group of introductory or navigational aids. When the nearest ancestor sectioning content or sectioning root element is the body element, then it applies to the whole page.')), footer: new HTMLTagSpecification(localize('tags.footer', 'The footer element represents a footer for its nearest ancestor sectioning content or sectioning root element. A footer typically contains information about its section such as who wrote it, links to related documents, copyright data, and the like.')), address: new HTMLTagSpecification(localize('tags.address', 'The address element represents the contact information for its nearest article or body element ancestor. If that is the body element, then the contact information applies to the document as a whole.')), // Grouping content p: new HTMLTagSpecification(localize('tags.p', 'The p element represents a paragraph.')), hr: new HTMLTagSpecification(localize('tags.hr', 'The hr element represents a paragraph-level thematic break, e.g. a scene change in a story, or a transition to another topic within a section of a reference book.')), pre: new HTMLTagSpecification(localize('tags.pre', 'The pre element represents a block of preformatted text, in which structure is represented by typographic conventions rather than by elements.')), blockquote: new HTMLTagSpecification(localize('tags.blockquote', 'The blockquote element represents content that is quoted from another source, optionally with a citation which must be within a footer or cite element, and optionally with in-line changes such as annotations and abbreviations.'), ['cite']), ol: new HTMLTagSpecification(localize('tags.ol', 'The ol element represents a list of items, where the items have been intentionally ordered, such that changing the order would change the meaning of the document.'), ['reversed:v', 'start', 'type:lt']), ul: new HTMLTagSpecification(localize('tags.ul', 'The ul element represents a list of items, where the order of the items is not important — that is, where changing the order would not materially change the meaning of the document.')), li: new HTMLTagSpecification(localize('tags.li', 'The li element represents a list item. If its parent element is an ol, ul, or menu element, then the element is an item of the parent element\'s list, as defined for those elements. Otherwise, the list item has no defined list-related relationship to any other li element.'), ['value']), dl: new HTMLTagSpecification(localize('tags.dl', 'The dl element represents an association list consisting of zero or more name-value groups (a description list). A name-value group consists of one or more names (dt elements) followed by one or more values (dd elements), ignoring any nodes other than dt and dd elements. Within a single dl element, there should not be more than one dt element for each name.')), dt: new HTMLTagSpecification(localize('tags.dt', 'The dt element represents the term, or name, part of a term-description group in a description list (dl element).')), dd: new HTMLTagSpecification(localize('tags.dd', 'The dd element represents the description, definition, or value, part of a term-description group in a description list (dl element).')), figure: new HTMLTagSpecification(localize('tags.figure', 'The figure element represents some flow content, optionally with a caption, that is self-contained (like a complete sentence) and is typically referenced as a single unit from the main flow of the document.')), figcaption: new HTMLTagSpecification(localize('tags.figcaption', 'The figcaption element represents a caption or legend for the rest of the contents of the figcaption element\'s parent figure element, if any.')), main: new HTMLTagSpecification(localize('tags.main', 'The main element represents the main content of the body of a document or application. The main content area consists of content that is directly related to or expands upon the central topic of a document or central functionality of an application.')), div: new HTMLTagSpecification(localize('tags.div', 'The div element has no special meaning at all. It represents its children. It can be used with the class, lang, and title attributes to mark up semantics common to a group of consecutive elements.')), // Text-level semantics a: new HTMLTagSpecification(localize('tags.a', 'If the a element has an href attribute, then it represents a hyperlink (a hypertext anchor) labeled by its contents.'), ['href', 'target', 'download', 'ping', 'rel', 'hreflang', 'type']), em: new HTMLTagSpecification(localize('tags.em', 'The em element represents stress emphasis of its contents.')), strong: new HTMLTagSpecification(localize('tags.strong', 'The strong element represents strong importance, seriousness, or urgency for its contents.')), small: new HTMLTagSpecification(localize('tags.small', 'The small element represents side comments such as small print.')), s: new HTMLTagSpecification(localize('tags.s', 'The s element represents contents that are no longer accurate or no longer relevant.')), cite: new HTMLTagSpecification(localize('tags.cite', 'The cite element represents a reference to a creative work. It must include the title of the work or the name of the author(person, people or organization) or an URL reference, or a reference in abbreviated form as per the conventions used for the addition of citation metadata.')), q: new HTMLTagSpecification(localize('tags.q', 'The q element represents some phrasing content quoted from another source.'), ['cite']), dfn: new HTMLTagSpecification(localize('tags.dfn', 'The dfn element represents the defining instance of a term. The paragraph, description list group, or section that is the nearest ancestor of the dfn element must also contain the definition(s) for the term given by the dfn element.')), abbr: new HTMLTagSpecification(localize('tags.abbr', 'The abbr element represents an abbreviation or acronym, optionally with its expansion. The title attribute may be used to provide an expansion of the abbreviation. The attribute, if specified, must contain an expansion of the abbreviation, and nothing else.')), ruby: new HTMLTagSpecification(localize('tags.ruby', 'The ruby element allows one or more spans of phrasing content to be marked with ruby annotations. Ruby annotations are short runs of text presented alongside base text, primarily used in East Asian typography as a guide for pronunciation or to include other annotations. In Japanese, this form of typography is also known as furigana. Ruby text can appear on either side, and sometimes both sides, of the base text, and it is possible to control its position using CSS. A more complete introduction to ruby can be found in the Use Cases & Exploratory Approaches for Ruby Markup document as well as in CSS Ruby Module Level 1. [RUBY-UC] [CSSRUBY]')), rb: new HTMLTagSpecification(localize('tags.rb', 'The rb element marks the base text component of a ruby annotation. When it is the child of a ruby element, it doesn\'t represent anything itself, but its parent ruby element uses it as part of determining what it represents.')), rt: new HTMLTagSpecification(localize('tags.rt', 'The rt element marks the ruby text component of a ruby annotation. When it is the child of a ruby element or of an rtc element that is itself the child of a ruby element, it doesn\'t represent anything itself, but its ancestor ruby element uses it as part of determining what it represents.')), // <rtc> is not yet supported by 2+ browsers //rtc: new HTMLTagSpecification( // localize('tags.rtc', 'The rtc element marks a ruby text container for ruby text components in a ruby annotation. When it is the child of a ruby element it doesn\'t represent anything itself, but its parent ruby element uses it as part of determining what it represents.')), rp: new HTMLTagSpecification(localize('tags.rp', 'The rp element is used to provide fallback text to be shown by user agents that don\'t support ruby annotations. One widespread convention is to provide parentheses around the ruby text component of a ruby annotation.')), // <data> is not yet supported by 2+ browsers //data: new HTMLTagSpecification( // localize('tags.data', 'The data element represents its contents, along with a machine-readable form of those contents in the value attribute.')), time: new HTMLTagSpecification(localize('tags.time', 'The time element represents its contents, along with a machine-readable form of those contents in the datetime attribute. The kind of content is limited to various kinds of dates, times, time-zone offsets, and durations, as described below.'), ['datetime']), code: new HTMLTagSpecification(localize('tags.code', 'The code element represents a fragment of computer code. This could be an XML element name, a file name, a computer program, or any other string that a computer would recognize.')), var: new HTMLTagSpecification(localize('tags.var', 'The var element represents a variable. This could be an actual variable in a mathematical expression or programming context, an identifier representing a constant, a symbol identifying a physical quantity, a function parameter, or just be a term used as a placeholder in prose.')), samp: new HTMLTagSpecification(localize('tags.samp', 'The samp element represents sample or quoted output from another program or computing system.')), kbd: new HTMLTagSpecification(localize('tags.kbd', 'The kbd element represents user input (typically keyboard input, although it may also be used to represent other input, such as voice commands).')), sub: new HTMLTagSpecification(localize('tags.sub', 'The sub element represents a subscript.')), sup: new HTMLTagSpecification(localize('tags.sup', 'The sup element represents a superscript.')), i: new HTMLTagSpecification(localize('tags.i', 'The i element represents a span of text in an alternate voice or mood, or otherwise offset from the normal prose in a manner indicating a different quality of text, such as a taxonomic designation, a technical term, an idiomatic phrase from another language, transliteration, a thought, or a ship name in Western texts.')), b: new HTMLTagSpecification(localize('tags.b', 'The b element represents a span of text to which attention is being drawn for utilitarian purposes without conveying any extra importance and with no implication of an alternate voice or mood, such as key words in a document abstract, product names in a review, actionable words in interactive text-driven software, or an article lede.')), u: new HTMLTagSpecification(localize('tags.u', 'The u element represents a span of text with an unarticul