Skip to content

Commit 27f65ed

Browse files
committed
copy
1 parent d23e0b8 commit 27f65ed

File tree

2 files changed

+37
-22
lines changed

2 files changed

+37
-22
lines changed

README.md

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,59 @@
11
# vscode-python-fstring-dsl
2+
23
Syntax highlighting for HTML, SQL, JS, CSS in Python f-strings
34

45
## Usage
5-
To trigger the syntax highlight you must wrap your
6-
DSL-string in a specific function (or method) call: `html(...),` `sql(...)`, `js(...)`, `css(...)`. This function may be noop like the Python's `typing.cast()` or do something useful, i.e. trimming whitespaces.
6+
7+
The syntax highlighting is triggered by wrapping the DSL-string in a
8+
specific function (or method) call:
9+
10+
- `html(...)`
11+
- `sql(...)`
12+
- `js(...)`
13+
- `css(...)`
14+
15+
<!-- like the Python's `typing.cast()` -->
16+
17+
This function may be noop. Or it could do something useful, e.g. trimming whitespaces or logging.
718

819
```python
920
def html(s: str):
21+
return s.trim()
22+
```
23+
24+
```python
25+
def sql(s: str):
26+
logging.info(s)
1027
return s
1128
```
1229

13-
If the string is template (f-string), the internal f-expressions will be syntax highlighted too.
30+
If the string is the template (f-string), the internal f-expressions will be syntax highlighted too.
1431

1532
## Sample
33+
1634
![sample.png](https://raw.githubusercontent.com/jkmnt/vscode-python-fstring-dsl/sample.png)
1735

1836
This sample shows the well-typed server-side Dialog component with
19-
bootsrap styling, htmx magic and text escaping.
20-
37+
bootsrap styling, htmx magic, and text escaping.
2138

2239
## Note
2340

24-
- 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 solution is to simplify the template.
41+
- 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.
2542

26-
- This extension deals with the highlighting only, so no Intellisence, hovers, etc.
43+
- This extension deals with the highlighting only, so no Intellisence, hovers, etc.
2744

2845
- f-strings are not very useful with CSS and JS. These languages are brace-heavy - too many braces to be escaped.
2946

30-
- To underline the embedded areas as in the sample above, add following to the VSCode settings.json:
31-
```json
32-
"editor.tokenColorCustomizations": {
33-
"textMateRules": [
34-
{
35-
"scope": "meta.embedded.inline.f-expression",
36-
"settings": {
37-
"fontStyle": "underline",
38-
},
39-
},
40-
]
41-
},
42-
```
47+
- Add these lines to the VSCode settings.json to underline the embedded scopes as in the sample above:
48+
```json
49+
"editor.tokenColorCustomizations": {
50+
"textMateRules": [
51+
{
52+
"scope": "meta.embedded.inline.f-expression",
53+
"settings": {
54+
"fontStyle": "underline",
55+
},
56+
},
57+
]
58+
},
59+
```

sample.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# stubs
22

3-
43
def html(s: str):
54
return s
65

@@ -17,7 +16,6 @@ class SafeStr(str):
1716
pass
1817

1918

20-
# actual sample
2119

2220

2321
def Dialog(*, post_url: str, title: str, body: SafeStr, cancel_text: str | None = None, ok_text: str | None = None):

0 commit comments

Comments
 (0)