Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Pug: Improved filter tokenization (#3258)
Co-authored-by: Jason Kurian <JaKXz@users.noreply.github.com>
  • Loading branch information
RunDevelopment and JaKXz committed Dec 7, 2021
1 parent 2334b4b commit 0390e64
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 69 deletions.
9 changes: 7 additions & 2 deletions components/prism-pug.js
Expand Up @@ -33,7 +33,8 @@
'filter-name': {
pattern: /^:[\w-]+/,
alias: 'variable'
}
},
'text': /\S[\s\S]*/,
}
},

Expand Down Expand Up @@ -172,7 +173,11 @@
pattern: /^:[\w-]+/,
alias: 'variable'
},
rest: Prism.languages[filter.language]
'text': {
pattern: /\S[\s\S]*/,
alias: [filter.language, 'language-' + filter.language],
inside: Prism.languages[filter.language]
}
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion components/prism-pug.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions tests/languages/coffeescript+pug/coffeescript_inclusion.test
Expand Up @@ -6,14 +6,16 @@
[
["filter-coffee", [
["filter-name", ":coffee"],
["string", [
"\"",
["interpolation", "#{foo}"],
"\""
["text", [
["string", [
"\"",
["interpolation", "#{foo}"],
"\""
]]
]]
]]
]

----------------------------------------------------

Checks for coffee filter (CoffeeScript) in Jade.
Checks for coffee filter (CoffeeScript) in pug.
29 changes: 15 additions & 14 deletions tests/languages/ejs+pug/ejs_inclusion.test
Expand Up @@ -6,19 +6,20 @@
[
["filter-ejs", [
["filter-name", ":ejs"],
["language-javascript", [
["operator", "<"],
["operator", "%"],
["keyword", "var"],
" foo ",
["operator", "="],
["string", "''"],
["punctuation", ","],
" bar ",
["operator", "="],
["boolean", "false"],
["punctuation", ";"]
]],
["delimiter", "%>"]
["text", [
["delimiter", "<%"],
["language-javascript", [
["keyword", "var"],
" foo ",
["operator", "="],
["string", "''"],
["punctuation", ","],
" bar ",
["operator", "="],
["boolean", "false"],
["punctuation", ";"]
]],
["delimiter", "%>"]
]]
]]
]
6 changes: 4 additions & 2 deletions tests/languages/handlebars+pug/handlebars_inclusion.test
Expand Up @@ -6,10 +6,12 @@
[
["filter-handlebars", [
["filter-name", ":handlebars"],
["comment", "{{!comment}}"]
["text", [
["comment", "{{!comment}}"]
]]
]]
]

----------------------------------------------------

Checks for handlebars filter in Jade.
Checks for handlebars filter in pug.
16 changes: 9 additions & 7 deletions tests/languages/less+pug/less_inclusion.test
Expand Up @@ -6,15 +6,17 @@
[
["filter-less", [
["filter-name", ":less"],
["variable", [
"@foo",
["punctuation", ":"]
]],
" #123",
["punctuation", ";"]
["text", [
["variable", [
"@foo",
["punctuation", ":"]
]],
" #123",
["punctuation", ";"]
]]
]]
]

----------------------------------------------------

Checks for less filter in Jade.
Checks for less filter in pug.
36 changes: 19 additions & 17 deletions tests/languages/livescript+pug/livescript_inclusion.test
Expand Up @@ -6,23 +6,25 @@
[
["filter-livescript", [
["filter-name", ":livescript"],
["interpolated-string", [
["string", "\""],
["variable", "#foo"],
["string", " "],
["interpolation", [
["interpolation-punctuation", "#{"],
["keyword", "if"],
["regex", "/test/"],
["operator", "=="],
["string", "'test'"],
["keyword", "then"],
["number", "3"],
["keyword", "else"],
["number", "4"],
["interpolation-punctuation", "}"]
]],
["string", "\""]
["text", [
["interpolated-string", [
["string", "\""],
["variable", "#foo"],
["string", " "],
["interpolation", [
["interpolation-punctuation", "#{"],
["keyword", "if"],
["regex", "/test/"],
["operator", "=="],
["string", "'test'"],
["keyword", "then"],
["number", "3"],
["keyword", "else"],
["number", "4"],
["interpolation-punctuation", "}"]
]],
["string", "\""]
]]
]]
]]
]
10 changes: 6 additions & 4 deletions tests/languages/markdown+pug/markdown_inclusion.test
Expand Up @@ -6,13 +6,15 @@
[
["filter-markdown", [
["filter-name", ":markdown"],
["title", [
["punctuation", "#"],
" title"
["text", [
["title", [
["punctuation", "#"],
" title"
]]
]]
]]
]

----------------------------------------------------

Checks for markdown filter in Jade.
Checks for markdown filter in pug.
2 changes: 1 addition & 1 deletion tests/languages/pug/filter_feature.test
Expand Up @@ -6,6 +6,6 @@
[
["filter", [
["filter-name", ":language"],
"\r\n\tcode"
["text", "code"]
]]
]
10 changes: 6 additions & 4 deletions tests/languages/scss+pug/scss_inclusion.test
Expand Up @@ -6,12 +6,14 @@
[
["filter-sass", [
["filter-name", ":sass"],
["keyword", "@extend"],
" .foo",
["punctuation", ";"]
["text", [
["keyword", "@extend"],
" .foo",
["punctuation", ";"]
]]
]]
]

----------------------------------------------------

Checks for sass filter (Scss) in Jade.
Checks for sass filter (Scss) in pug.
14 changes: 8 additions & 6 deletions tests/languages/stylus+pug/stylus_inclusion.test
Expand Up @@ -6,15 +6,17 @@
[
["filter-stylus", [
["filter-name", ":stylus"],
["variable-declaration", [
["variable", "font-size"],
["operator", "="],
["number", "14"],
["unit", "px"]
["text", [
["variable-declaration", [
["variable", "font-size"],
["operator", "="],
["number", "14"],
["unit", "px"]
]]
]]
]]
]

----------------------------------------------------

Checks for stylus filter in Jade.
Checks for stylus filter in pug.
12 changes: 6 additions & 6 deletions tests/languages/twig+pug/twig_inclusion.test
Expand Up @@ -6,14 +6,14 @@
[
["filter-atpl", [
["filter-name", ":atpl"],

["punctuation", "{"],
["punctuation", "{"],
["number", "42"],
["delimiter", "}}"]
["text", [
["delimiter", "{{"],
["number", "42"],
["delimiter", "}}"]
]]
]]
]

----------------------------------------------------

Checks for atpl filter (Twig) in Jade.
Checks for atpl filter (Twig) in pug.

0 comments on commit 0390e64

Please sign in to comment.