Skip to content

Commit 514e7b3

Browse files
committed
copy
1 parent 0e5024f commit 514e7b3

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

README.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,6 @@ specific function (or method) call:
1414

1515
This function may be a noop like the Python's `typing.cast()`. Perhaps it could do something useful, e.g. trimming whitespaces or logging.
1616

17-
```python
18-
def html(s: str):
19-
return s.trim()
20-
```
21-
22-
```python
23-
def sql(s: str):
24-
logging.info(s)
25-
return s
26-
```
27-
2817
If the string is the template (f-string), the internal f-expressions will be syntax highlighted too.
2918

3019
## Sample
@@ -34,7 +23,25 @@ If the string is the template (f-string), the internal f-expressions will be syn
3423
This sample shows the well-typed server-side Dialog component with
3524
bootsrap styling, htmx magic, and text escaping.
3625

37-
## Note
26+
## Configuration
27+
28+
The trigger functions names may be configured to suit your project.
29+
Navigate to **Highlight f-strings** settings in VSCode or edit the settings.json:
30+
31+
```jsonc
32+
"python-fstring-dsl.grammar.triggers": {
33+
"html": "html|template\\.render", // html or template.render
34+
"css": "css_\\d", // css_0, css_1, etc
35+
"sql": false // disable the sql
36+
// js is not defined, use the default
37+
}
38+
```
39+
40+
The values are regexps. They are inlined inside the larger regexps so don't use capturing groups.
41+
42+
The changes are not applied automatically. Run _(Ctrl-Shift-P)_ **Highlight f-string: Generate grammar** command to apply changes. This action will regenerate the internal grammar file of extension and reload VSCode.
43+
44+
## More
3845

3946
- The syntax matching is naive. It will work only for the simple common cases. If something don't color the way it should, the best workaround will be the template simplification.
4047

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@
9191
"default": {
9292
"sql": "sql",
9393
"html": "html|hitml\\.m|hitml\\.markup|hitml\\.document|ht\\.m|ht\\.markup|ht\\.document",
94-
"css": "css|hitml\\.css|ht\\.css",
95-
"js": "js|hitml\\.js|ht\\.js"
94+
"css": "css|hitml\\.style|hitml\\.stylesheet|ht\\.style|ht\\.stylesheet",
95+
"js": "js|hitml\\.handler|hitml\\.script|ht\\.handler|ht\\.script"
9696
},
97-
"markdownDescription": "Function names (regex) to trigger the syntax highlight.\nOnly `html`, `sql`, `css`, `js` are supported.\n\nE.g.: `{\"html\":\"html|template[.]render\", \"css\":\"minify_css\", \"sql\":false}`\n\nRun **Highlight f-string: Generate grammar** command to apply changes."
97+
"markdownDescription": "Function names (regex) to trigger the syntax highlight.\nOnly `html`, `sql`, `css`, `js` are supported.\n\nE.g.: `{\"html\":\"html|template\\.render\", \"css\":\"minify_css\", \"sql\":false}`\n\nRun **Highlight f-string: Generate grammar** command to apply changes."
9898
}
9999
}
100100
}

src/gen_grammar.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ export const DEF_SPECS: Spec[] = [
1717
},
1818
{
1919
lang: "css",
20-
trigger: "css|hitml\\.css|ht\\.css",
20+
trigger: "css|hitml\\.style|hitml\\.stylesheet|ht\\.style|ht\\.stylesheet",
2121
source: "source.css",
2222
},
2323
{
2424
lang: "js",
25-
trigger: "js|hitml\\.js|ht\\.js",
25+
trigger: "js|hitml\\.handler|hitml\\.script|ht\\.handler|ht\\.script",
2626
source: "source.js",
2727
},
2828
];

syntaxes/embed-in-python.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
]
162162
},
163163
{
164-
"begin": "(?x)\n (?<!def\\s+)\n \\b\n (css|hitml\\.css|ht\\.css)\n \\s*\n (\\()",
164+
"begin": "(?x)\n (?<!def\\s+)\n \\b\n (css|hitml\\.style|hitml\\.stylesheet|ht\\.style|ht\\.stylesheet)\n \\s*\n (\\()",
165165
"end": "(?x)\n (\\))\n ",
166166
"name": "meta.function-call.python",
167167
"contentName": "meta.function-call.arguments.python",
@@ -239,7 +239,7 @@
239239
]
240240
},
241241
{
242-
"begin": "(?x)\n (?<!def\\s+)\n \\b\n (js|hitml\\.js|ht\\.js)\n \\s*\n (\\()",
242+
"begin": "(?x)\n (?<!def\\s+)\n \\b\n (js|hitml\\.handler|hitml\\.script|ht\\.handler|ht\\.script)\n \\s*\n (\\()",
243243
"end": "(?x)\n (\\))\n ",
244244
"name": "meta.function-call.python",
245245
"contentName": "meta.function-call.arguments.python",

0 commit comments

Comments
 (0)