[gtksourceview] html.lang: Enhance headings (<h1>-<h6>) highlighting
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] html.lang: Enhance headings (<h1>-<h6>) highlighting
- Date: Mon, 26 Nov 2018 23:21:22 +0000 (UTC)
commit d28407118c392a1fd58e0b7367858db1d19c0b67
Author: Jeffery To <jeffery to gmail com>
Date: Mon Oct 15 03:32:16 2018 +0800
html.lang: Enhance headings (<h1>-<h6>) highlighting
* Allow headings to span multiple lines
* Highlight tags inside headings, as they can contain "phrasing
content", i.e. <b>, <span>, etc.
* Add highlighting for <h6>
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements
data/language-specs/html.lang | 161 ++++++++++++++++++++++++++----------
tests/syntax-highlighting/file.html | 3 +
2 files changed, 119 insertions(+), 45 deletions(-)
---
diff --git a/data/language-specs/html.lang b/data/language-specs/html.lang
index af1ffeaf..ceda5d74 100644
--- a/data/language-specs/html.lang
+++ b/data/language-specs/html.lang
@@ -6,6 +6,7 @@
Copyright (C) 2005-2007 - Marco Barisione <barisione gmail com>
Copyright (C) 2005-2007 - Emanuele Aina
Copyright (C) 2014 - Sébastien Wilmet <swilmet gnome org>
+ Copyright (C) 2018 - Jeffery To <jeffery to gmail com>
GtkSourceView is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -42,6 +43,7 @@
<style id="h3" name="Heading level 3" map-to="def:heading3"/>
<style id="h4" name="Heading level 4" map-to="def:heading4"/>
<style id="h5" name="Heading level 5" map-to="def:heading5"/>
+ <style id="h6" name="Heading level 6" map-to="def:heading6"/>
</styles>
<default-regex-options case-sensitive="false"/>
@@ -70,6 +72,22 @@
<end></end>
</context>
+ <context id="heading-tag" once-only="true">
+ <start>\%{def:always-match}</start>
+ <end>></end>
+ <include>
+ <context sub-pattern="0" where="end" style-ref="tag"/>
+ <context ref="generic-tag"/>
+ </include>
+ </context>
+
+ <define-regex id="h1-close"></h1\s*></define-regex>
+ <define-regex id="h2-close"></h2\s*></define-regex>
+ <define-regex id="h3-close"></h3\s*></define-regex>
+ <define-regex id="h4-close"></h4\s*></define-regex>
+ <define-regex id="h5-close"></h5\s*></define-regex>
+ <define-regex id="h6-close"></h6\s*></define-regex>
+
<context id="headings">
<include>
<context id="title" style-inside="true" style-ref="title" end-at-line-end="true">
@@ -81,89 +99,142 @@
<context ref="embedded-lang-hook"/>
</include>
</context>
- <context id="h1" end-at-line-end="true">
- <start><h1</start>
+
+ <context id="h1" class="no-spell-check">
+ <start><h1\%]</start>
+ <include>
+ <context sub-pattern="0" where="start" style-ref="tag"/>
+ <context ref="heading-tag"/>
+
+ <context style-ref="h1" class-disabled="no-spell-check">
+ <start>(?!\%{h1-close})</start>
+ <include>
+ <context end-parent="true">
+ <match>(?=\%{h1-close})</match>
+ </context>
+ <context ref="embedded-lang-hook"/>
+ <context ref="tag"/>
+ </include>
+ </context>
+
+ <context style-ref="tag" end-parent="true">
+ <match>\%{h1-close}</match>
+ </context>
+ </include>
+ </context>
+
+ <context id="h2" class="no-spell-check">
+ <start><h2\%]</start>
<include>
<context sub-pattern="0" where="start" style-ref="tag"/>
- <context ref="generic-tag"/>
- <context id="h1-inside" style-inside="true" style-ref="h1" end-at-line-end="true"
end-parent="true">
- <start>></start>
- <end></h1\s*></end>
+ <context ref="heading-tag"/>
+
+ <context style-ref="h2" class-disabled="no-spell-check">
+ <start>(?!\%{h2-close})</start>
<include>
- <context sub-pattern="0" where="start" style-ref="tag"/>
- <context sub-pattern="0" where="end" style-ref="tag"/>
+ <context end-parent="true">
+ <match>(?=\%{h2-close})</match>
+ </context>
<context ref="embedded-lang-hook"/>
- <!-- We cannot match any further here, because matching to tag will override our end-match
-->
+ <context ref="tag"/>
</include>
</context>
+
+ <context style-ref="tag" end-parent="true">
+ <match>\%{h2-close}</match>
+ </context>
</include>
</context>
- <context id="h2" end-at-line-end="true">
- <start><h2</start>
+
+ <context id="h3" class="no-spell-check">
+ <start><h3\%]</start>
<include>
<context sub-pattern="0" where="start" style-ref="tag"/>
- <context ref="generic-tag"/>
- <context id="h2-inside" style-inside="true" style-ref="h2" end-at-line-end="true"
end-parent="true">
- <start>></start>
- <end></h2\s*></end>
+ <context ref="heading-tag"/>
+
+ <context style-ref="h3" class-disabled="no-spell-check">
+ <start>(?!\%{h3-close})</start>
<include>
- <context sub-pattern="0" where="start" style-ref="tag"/>
- <context sub-pattern="0" where="end" style-ref="tag"/>
+ <context end-parent="true">
+ <match>(?=\%{h3-close})</match>
+ </context>
<context ref="embedded-lang-hook"/>
- <!-- We cannot match any further here, because matching to tag will override our end-match
-->
+ <context ref="tag"/>
</include>
</context>
+
+ <context style-ref="tag" end-parent="true">
+ <match>\%{h3-close}</match>
+ </context>
</include>
</context>
- <context id="h3" end-at-line-end="true">
- <start><h3</start>
+
+ <context id="h4" class="no-spell-check">
+ <start><h4\%]</start>
<include>
<context sub-pattern="0" where="start" style-ref="tag"/>
- <context ref="generic-tag"/>
- <context id="h3-inside" style-inside="true" style-ref="h3" end-at-line-end="true"
end-parent="true">
- <start>></start>
- <end></h3\s*></end>
+ <context ref="heading-tag"/>
+
+ <context style-ref="h4" class-disabled="no-spell-check">
+ <start>(?!\%{h4-close})</start>
<include>
- <context sub-pattern="0" where="start" style-ref="tag"/>
- <context sub-pattern="0" where="end" style-ref="tag"/>
+ <context end-parent="true">
+ <match>(?=\%{h4-close})</match>
+ </context>
<context ref="embedded-lang-hook"/>
- <!-- We cannot match any further here, because matching to tag will override our end-match
-->
+ <context ref="tag"/>
</include>
</context>
+
+ <context style-ref="tag" end-parent="true">
+ <match>\%{h4-close}</match>
+ </context>
</include>
</context>
- <context id="h4" end-at-line-end="true">
- <start><h4</start>
+
+ <context id="h5" class="no-spell-check">
+ <start><h5\%]</start>
<include>
<context sub-pattern="0" where="start" style-ref="tag"/>
- <context ref="generic-tag"/>
- <context id="h4-inside" style-inside="true" style-ref="h4" end-at-line-end="true"
end-parent="true">
- <start>></start>
- <end></h4\s*></end>
+ <context ref="heading-tag"/>
+
+ <context style-ref="h5" class-disabled="no-spell-check">
+ <start>(?!\%{h5-close})</start>
<include>
- <context sub-pattern="0" where="start" style-ref="tag"/>
- <context sub-pattern="0" where="end" style-ref="tag"/>
+ <context end-parent="true">
+ <match>(?=\%{h5-close})</match>
+ </context>
<context ref="embedded-lang-hook"/>
- <!-- We cannot match any further here, because matching to tag will override our end-match
-->
+ <context ref="tag"/>
</include>
</context>
+
+ <context style-ref="tag" end-parent="true">
+ <match>\%{h5-close}</match>
+ </context>
</include>
</context>
- <context id="h5" end-at-line-end="true">
- <start><h5</start>
+
+ <context id="h6" class="no-spell-check">
+ <start><h6\%]</start>
<include>
<context sub-pattern="0" where="start" style-ref="tag"/>
- <context ref="generic-tag"/>
- <context id="h5-inside" style-inside="true" style-ref="h5" end-at-line-end="true"
end-parent="true">
- <start>></start>
- <end></h5\s*></end>
+ <context ref="heading-tag"/>
+
+ <context style-ref="h6" class-disabled="no-spell-check">
+ <start>(?!\%{h6-close})</start>
<include>
- <context sub-pattern="0" where="start" style-ref="tag"/>
- <context sub-pattern="0" where="end" style-ref="tag"/>
+ <context end-parent="true">
+ <match>(?=\%{h6-close})</match>
+ </context>
<context ref="embedded-lang-hook"/>
- <!-- We cannot match any further here, because matching to tag will override our end-match
-->
+ <context ref="tag"/>
</include>
</context>
+
+ <context style-ref="tag" end-parent="true">
+ <match>\%{h6-close}</match>
+ </context>
</include>
</context>
</include>
diff --git a/tests/syntax-highlighting/file.html b/tests/syntax-highlighting/file.html
index 5a6d10fd..699360d1 100644
--- a/tests/syntax-highlighting/file.html
+++ b/tests/syntax-highlighting/file.html
@@ -12,6 +12,9 @@
</head>
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF"
vlink="#800080" alink="#FF0000">
+ <h1>
+ <span>Hi there!</span>
+ </h1>
Hi there!
</body>
</html>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]