[gtksourceview] javascript.lang: Fix script not ending when inside template literal
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] javascript.lang: Fix script not ending when inside template literal
- Date: Wed, 13 Nov 2019 17:59:08 +0000 (UTC)
commit ef02f71bbcd385059255408f3688068bef2bab40
Author: Jeffery To <jeffery to gmail com>
Date: Wed Nov 13 22:22:43 2019 +0800
javascript.lang: Fix script not ending when inside template literal
Previously, if an HTML file had code like:
<script>var a = `</script>
then the JavaScript highlighting would continue beyond the closing
</script> tag.
This fixes the template literal context so that highlighting correctly
ends in this case.
data/language-specs/javascript-literals.lang | 2 ++
tests/syntax-highlighting/file.html | 4 ++++
2 files changed, 6 insertions(+)
---
diff --git a/data/language-specs/javascript-literals.lang b/data/language-specs/javascript-literals.lang
index cdc4bd52..818d176a 100644
--- a/data/language-specs/javascript-literals.lang
+++ b/data/language-specs/javascript-literals.lang
@@ -536,6 +536,8 @@
</include>
</context> <!-- /_template-head -->
+ <context ref="js:embedded-lang-hooks"/>
+
<context id="_template-substitution-tails" style-ref="js:template-literal">
<start>(?<=})</start>
<end>(?=`|\$\{)</end>
diff --git a/tests/syntax-highlighting/file.html b/tests/syntax-highlighting/file.html
index 2f499b6d..e4c1fcbd 100644
--- a/tests/syntax-highlighting/file.html
+++ b/tests/syntax-highlighting/file.html
@@ -15,6 +15,10 @@
alert('Hi there!');
}, false);
</script>
+ <script>a = "double-quoted string</script>
+ <script>a = 'single-quoted string</script>
+ <script>a = /regular expression</script>
+ <script>a = `template literal</script>
</head>
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF"
vlink="#800080" alink="#FF0000">
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]