[gtksourceview/gtksourceview-4-6] html.lang: Add embedded-lang-hook-content



commit 8fe859d2eb98e124673d0caff9facec1bcd62e5a
Author: Jeffery To <jeffery to gmail com>
Date:   Thu Feb 13 17:58:38 2020 +0800

    html.lang: Add embedded-lang-hook-content
    
    There are cases when the embedding language should highlight HTML
    content but not inside HTML tags or attributes, e.g. Markdown and
    Mediawiki formatting.
    
    This adds an embedded-lang-hook-content context for these languages to
    replace, to add highlighting in container contexts where the embedding
    language's highlighting would not normally be applied.
    
    Fixes #108.
    
    (Note that Markdown's rules on when styling is recognized inside HTML
    tags are a bit complicated. Technically, Markdown syntax should not be
    recognized inside h1-6 and title tags, but since this change does not
    address Markdown highlighting inside HTML tags in general, it makes more
    sense to continue highlighting Markdown syntax inside these tags.)

 data/language-specs/html.lang      | 22 ++++++++++++++++++++--
 data/language-specs/markdown.lang  |  2 +-
 data/language-specs/mediawiki.lang |  2 +-
 tests/syntax-highlighting/file.md  |  2 ++
 4 files changed, 24 insertions(+), 4 deletions(-)
---
diff --git a/data/language-specs/html.lang b/data/language-specs/html.lang
index 191fe00a..effd373b 100644
--- a/data/language-specs/html.lang
+++ b/data/language-specs/html.lang
@@ -64,14 +64,25 @@
     </context>
 
     <!-- This is a placeholder context intended to be <replace>d
-         in languages like php that need to embedd contexts inside
-         html tags and attributes.
+         in languages like PHP that need to embed contexts inside
+         HTML tags and attributes.
     -->
     <context id="embedded-lang-hook">
       <start>\%{def:never-match}</start>
       <end></end>
     </context>
 
+    <!-- Certain HTML tags (e.g. h1) require container contexts that
+         exclude highlighting from embedding languages. Languages can
+         replace this context when they need to highlight all content,
+         but not inside HTML tags and attributes.
+    -->
+
+    <context id="embedded-lang-hook-content">
+      <start>\%{def:never-match}</start>
+      <end></end>
+    </context>
+
     <context id="heading-tag" once-only="true">
       <start>\%{def:always-match}</start>
       <end>&gt;</end>
@@ -103,6 +114,7 @@
                 <context sub-pattern="0" where="start" style-ref="tag"/>
                 <context sub-pattern="0" where="end" style-ref="tag"/>
                 <context ref="embedded-lang-hook"/>
+                <context ref="embedded-lang-hook-content"/>
               </include>
             </context>
           </include>
@@ -121,6 +133,7 @@
                   <match>(?=\%{h1-close})</match>
                 </context>
                 <context ref="embedded-lang-hook"/>
+                <context ref="embedded-lang-hook-content"/>
                 <context ref="tag"/>
               </include>
             </context>
@@ -144,6 +157,7 @@
                   <match>(?=\%{h2-close})</match>
                 </context>
                 <context ref="embedded-lang-hook"/>
+                <context ref="embedded-lang-hook-content"/>
                 <context ref="tag"/>
               </include>
             </context>
@@ -167,6 +181,7 @@
                   <match>(?=\%{h3-close})</match>
                 </context>
                 <context ref="embedded-lang-hook"/>
+                <context ref="embedded-lang-hook-content"/>
                 <context ref="tag"/>
               </include>
             </context>
@@ -190,6 +205,7 @@
                   <match>(?=\%{h4-close})</match>
                 </context>
                 <context ref="embedded-lang-hook"/>
+                <context ref="embedded-lang-hook-content"/>
                 <context ref="tag"/>
               </include>
             </context>
@@ -213,6 +229,7 @@
                   <match>(?=\%{h5-close})</match>
                 </context>
                 <context ref="embedded-lang-hook"/>
+                <context ref="embedded-lang-hook-content"/>
                 <context ref="tag"/>
               </include>
             </context>
@@ -236,6 +253,7 @@
                   <match>(?=\%{h6-close})</match>
                 </context>
                 <context ref="embedded-lang-hook"/>
+                <context ref="embedded-lang-hook-content"/>
                 <context ref="tag"/>
               </include>
             </context>
diff --git a/data/language-specs/markdown.lang b/data/language-specs/markdown.lang
index 0a538c55..3a238e3e 100644
--- a/data/language-specs/markdown.lang
+++ b/data/language-specs/markdown.lang
@@ -395,7 +395,7 @@
       </include>
     </context>
 
-    <replace id="html:embedded-lang-hook" ref="markdown-syntax"/>
+    <replace id="html:embedded-lang-hook-content" ref="markdown-syntax"/>
 
     <context id="markdown">
       <include>
diff --git a/data/language-specs/mediawiki.lang b/data/language-specs/mediawiki.lang
index 18dd2df1..8b8e4b9f 100644
--- a/data/language-specs/mediawiki.lang
+++ b/data/language-specs/mediawiki.lang
@@ -314,7 +314,7 @@
       </include>
     </context>
 
-    <replace id="html:embedded-lang-hook" ref="mediawiki-syntax"/>
+    <replace id="html:embedded-lang-hook-content" ref="mediawiki-syntax"/>
 
     <context id="mediawiki">
       <include>
diff --git a/tests/syntax-highlighting/file.md b/tests/syntax-highlighting/file.md
index a5c3a8a1..7c39d0f2 100644
--- a/tests/syntax-highlighting/file.md
+++ b/tests/syntax-highlighting/file.md
@@ -36,3 +36,5 @@ An [example](http://example.com).
 
 Inline <abbr title="Hypertext Markup Language">HTML</abbr> is supported.
 
+<h1 class="a_long_classname">Formatting inside block-level elements _should_ be **ignored**.</h1>
+


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]