From a35b5ddc3e2513a44374340cd245b046aa084405 Mon Sep 17 00:00:00 2001 From: Zufu Liu Date: Sat, 2 Nov 2019 10:19:22 +1100 Subject: Feature [feature-requests:#1299] Treat custom tags from HTML5 as known tags. These contain "-" like "custom-tag". --- doc/ScintillaHistory.html | 4 ++++ lexers/LexHTML.cxx | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index e9ff2cf58..2c49c8c9f 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -571,6 +571,10 @@ Feature #1317.
  • + HTML lexer treats custom tags from HTML5 as known tags. These contain "-" like "custom-tag". + Feature #1299. +
  • +
  • HTML lexer fixes bug with some non-alphabetic characters in unknown tags. Feature #1320.
  • diff --git a/lexers/LexHTML.cxx b/lexers/LexHTML.cxx index 6b3748859..17c0846aa 100644 --- a/lexers/LexHTML.cxx +++ b/lexers/LexHTML.cxx @@ -266,6 +266,18 @@ void classifyAttribHTML(Sci_PositionU start, Sci_PositionU end, const WordList & styler.ColourTo(end, chAttr); } +// https://html.spec.whatwg.org/multipage/custom-elements.html#custom-elements-core-concepts +bool isHTMLCustomElement(const std::string &tag) { + // check valid HTML custom element name: starts with an ASCII lower alpha and contains hyphen. + if (tag.length() < 2 || !IsLowerCase(tag[0])) { + return false; + } + if (tag.find('-') == std::string::npos) { + return false; + } + return true; +} + int classifyTagHTML(Sci_PositionU start, Sci_PositionU end, const WordList &keywords, Accessor &styler, bool &tagDontFold, bool caseSensitive, bool isXml, bool allowScripts, @@ -288,6 +300,8 @@ int classifyTagHTML(Sci_PositionU start, Sci_PositionU end, chAttr = SCE_H_SGML_DEFAULT; } else if (!keywords || keywords.InList(tag.c_str())) { chAttr = SCE_H_TAG; + } else if (!isXml && isHTMLCustomElement(tag)) { + chAttr = SCE_H_TAG; } if (chAttr != SCE_H_TAGUNKNOWN) { styler.ColourTo(end, chAttr); -- cgit v1.2.3