Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh(scala) fix triple quoted string #2987

Merged
merged 3 commits into from Feb 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGES.md
Expand Up @@ -6,7 +6,8 @@ New Languages:

Language grammar improvements:

- env(perl) Much improved regex detection (#2960) [Josh Goebel][]
- enh(scala) fix triple quoted strings (#2987) [Josh Goebel][]
- enh(perl) Much improved regex detection (#2960) [Josh Goebel][]
- enh(swift) Improved highlighting for operator and precedencegroup declarations. (#2938) [Steven Van Impe][]
- fix(xml) Support single-character namespaces. (#2957) [Jan Pilzer][]
- enh(ruby) Support for character literals (#2950) [Vaibhav Chanana][]
Expand Down
15 changes: 8 additions & 7 deletions src/languages/scala.js
Expand Up @@ -29,23 +29,24 @@ export default function(hljs) {
const STRING = {
className: 'string',
variants: [
{
begin: '"""',
end: '"""'
},
{
begin: '"',
end: '"',
illegal: '\\n',
contains: [ hljs.BACKSLASH_ESCAPE ]
},
{
begin: '"""',
end: '"""',
relevance: 10
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically the main change I see here is that you removed the relevance, and that you changed the order. Can you please explain what do those changes do? Next time I might just contribute it myself :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well if " matches first that breaks everything, so we have to match """ first... and the relevance is a much longer explication... find the thread on huge relevance and read it for a start for more thoughts... 10 is just too high for something that is shared by several languages now, so I removed the huge relevance bump.

The sequencing is what fixes the issue.

},
{
begin: '[a-z]+"',
end: '"',
illegal: '\\n',
contains: [ hljs.BACKSLASH_ESCAPE,
SUBST ]
contains: [
hljs.BACKSLASH_ESCAPE,
SUBST
]
},
{
className: 'string',
Expand Down
1 change: 1 addition & 0 deletions test/markup/scala/strings.expect.txt
@@ -0,0 +1 @@
<span class="hljs-keyword">val</span> s = <span class="hljs-string">&quot;&quot;&quot; this is a string &quot;this is still a string&quot; another quote: &quot; after the quote &quot;&quot;&quot;</span>
1 change: 1 addition & 0 deletions test/markup/scala/strings.txt
@@ -0,0 +1 @@
val s = """ this is a string "this is still a string" another quote: " after the quote """