python-fragments 0.28__tar.gz → 0.29__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- python_fragments-0.29/LICENSE +21 -0
- python_fragments-0.29/PKG-INFO +88 -0
- {python_fragments-0.28 → python_fragments-0.29}/README.md +11 -1
- {python_fragments-0.28 → python_fragments-0.29}/fragments/ast_nodes.py +22 -1
- {python_fragments-0.28 → python_fragments-0.29}/fragments/grammar.py +11 -0
- {python_fragments-0.28 → python_fragments-0.29}/pyproject.toml +2 -2
- python_fragments-0.29/python_fragments.egg-info/PKG-INFO +88 -0
- {python_fragments-0.28 → python_fragments-0.29}/python_fragments.egg-info/SOURCES.txt +1 -0
- {python_fragments-0.28 → python_fragments-0.29}/tests/test_grammar.py +42 -0
- python_fragments-0.28/PKG-INFO +0 -55
- python_fragments-0.28/python_fragments.egg-info/PKG-INFO +0 -55
- {python_fragments-0.28 → python_fragments-0.29}/fragments/__init__.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/cli.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/html/__init__.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/html/elements.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/loader.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/__init__.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/based_proxy.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/client_message_handlers/__init__.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/client_message_handlers/code_actions.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/client_message_handlers/completion.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/client_message_handlers/definition.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/client_message_handlers/diagnostics.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/client_message_handlers/document_highlight.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/client_message_handlers/document_symbols.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/client_message_handlers/folding_range.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/client_message_handlers/hover.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/client_message_handlers/inlay_hints.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/client_message_handlers/lifecycle.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/client_message_handlers/references.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/client_message_handlers/rename.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/client_message_handlers/semantic_tokens.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/client_message_handlers/signature_help.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/file_state.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/message_queue.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/pyright_notification_handlers/__init__.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/pyright_notification_handlers/capability.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/pyright_notification_handlers/configuration.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/pyright_notification_handlers/diagnostics.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/types.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/source.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/transpiler.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/fragments/types.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/python_fragments.egg-info/dependency_links.txt +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/python_fragments.egg-info/entry_points.txt +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/python_fragments.egg-info/requires.txt +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/python_fragments.egg-info/top_level.txt +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/setup.cfg +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/tests/test_html_elements.py +0 -0
- {python_fragments-0.28 → python_fragments-0.29}/tests/test_source_map.py +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 The Running Algorithm
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: python-fragments
|
|
3
|
+
Version: 0.29
|
|
4
|
+
Summary: Modern HTML template rendering in Python
|
|
5
|
+
Author-email: The Running Algorithm <services@therunningalgorithm.info>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 The Running Algorithm
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Requires-Python: >=3.12
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Provides-Extra: lsp
|
|
32
|
+
Requires-Dist: basedpyright>=1.39.0; extra == "lsp"
|
|
33
|
+
Requires-Dist: lsprotocol>=2025.0.0; extra == "lsp"
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: pytest>=8.4.1; extra == "dev"
|
|
36
|
+
Dynamic: license-file
|
|
37
|
+
|
|
38
|
+
# Python Fragments
|
|
39
|
+
|
|
40
|
+
> **This package is in early development and not yet stable. The API may change without notice between releases.**
|
|
41
|
+
|
|
42
|
+
Modern HTML template rendering in Python — no build step, no template files, and native HTML awareness out of the box.
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from fragments import loader # isort: skip
|
|
46
|
+
|
|
47
|
+
from fastapi import FastAPI
|
|
48
|
+
from fastapi.responses import HTMLResponse
|
|
49
|
+
from components import Layout, PostCard
|
|
50
|
+
|
|
51
|
+
app = FastAPI()
|
|
52
|
+
|
|
53
|
+
POSTS = [...]
|
|
54
|
+
|
|
55
|
+
@app.get("/", response_class=HTMLResponse)
|
|
56
|
+
async def index() -> str:
|
|
57
|
+
published = [p for p in POSTS if p.published]
|
|
58
|
+
return <>
|
|
59
|
+
<Layout title="My Blog">
|
|
60
|
+
<h1>Latest Posts</h1>
|
|
61
|
+
<PostCard for={{ post in published }} post={{ post }} />
|
|
62
|
+
</Layout>
|
|
63
|
+
</>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## IDE Support
|
|
67
|
+
|
|
68
|
+
Type checking, completions, hover docs, go-to-definition, rename, and semantic highlighting — all working inside fragment syntax.
|
|
69
|
+
|
|
70
|
+

|
|
71
|
+
|
|
72
|
+
## Installation
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
pip install python-fragments
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Register the loader at your application's entry point, before importing any modules that contain fragments:
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
from fragments import loader # isort: skip
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Any `.py` file containing `<>` is transpiled automatically. Nothing else to configure.
|
|
85
|
+
|
|
86
|
+
## Feedback and feature requests
|
|
87
|
+
|
|
88
|
+
Bug reports and feature requests are welcome via [GitHub Issues](https://github.com/TheRunningAlgorithm2/python-fragments/issues). The project is not currently accepting code contributions.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> **This package is in early development and not yet stable. The API may change without notice between releases.**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Modern HTML template rendering in Python — no build step, no template files, and native HTML awareness out of the box.
|
|
6
6
|
|
|
7
7
|
```python
|
|
8
8
|
from fragments import loader # isort: skip
|
|
@@ -26,6 +26,12 @@ async def index() -> str:
|
|
|
26
26
|
</>
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
+
## IDE Support
|
|
30
|
+
|
|
31
|
+
Type checking, completions, hover docs, go-to-definition, rename, and semantic highlighting — all working inside fragment syntax.
|
|
32
|
+
|
|
33
|
+

|
|
34
|
+
|
|
29
35
|
## Installation
|
|
30
36
|
|
|
31
37
|
```bash
|
|
@@ -39,3 +45,7 @@ from fragments import loader # isort: skip
|
|
|
39
45
|
```
|
|
40
46
|
|
|
41
47
|
Any `.py` file containing `<>` is transpiled automatically. Nothing else to configure.
|
|
48
|
+
|
|
49
|
+
## Feedback and feature requests
|
|
50
|
+
|
|
51
|
+
Bug reports and feature requests are welcome via [GitHub Issues](https://github.com/TheRunningAlgorithm2/python-fragments/issues). The project is not currently accepting code contributions.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from dataclasses import dataclass, field
|
|
2
2
|
from typing import Sequence
|
|
3
3
|
|
|
4
|
-
type ASTHTMLChild = ASTHTMLElement | ASTHTMLComment | ASTHTMLText | ASTInterpolation | ASTComponent | ASTControlNode
|
|
4
|
+
type ASTHTMLChild = ASTHTMLElement | ASTHTMLComment | ASTHTMLText | ASTInterpolation | ASTComponent | ASTControlNode | ASTDoctype
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
@dataclass(slots=True)
|
|
@@ -392,6 +392,27 @@ class ASTComponentArgument:
|
|
|
392
392
|
return None
|
|
393
393
|
|
|
394
394
|
|
|
395
|
+
@dataclass(slots=True)
|
|
396
|
+
class ASTDoctype:
|
|
397
|
+
source_start: int = field(compare=False)
|
|
398
|
+
source_end: int = field(compare=False)
|
|
399
|
+
|
|
400
|
+
transpiled_content: str = field(init=False)
|
|
401
|
+
transpiled_start: int = field(init=False)
|
|
402
|
+
transpiled_end: int = field(init=False)
|
|
403
|
+
|
|
404
|
+
def transpile(self, transpiled_start: int) -> None:
|
|
405
|
+
self.transpiled_start = transpiled_start
|
|
406
|
+
self.transpiled_content = '"<!DOCTYPE html>"'
|
|
407
|
+
self.transpiled_end = self.transpiled_start + len(self.transpiled_content)
|
|
408
|
+
|
|
409
|
+
def map_offset(self, offset: int) -> None:
|
|
410
|
+
return None
|
|
411
|
+
|
|
412
|
+
def unmap_offset(self, offset: int) -> None:
|
|
413
|
+
return None
|
|
414
|
+
|
|
415
|
+
|
|
395
416
|
@dataclass(slots=True)
|
|
396
417
|
class ASTHTMLComment:
|
|
397
418
|
source_start: int = field(compare=False)
|
|
@@ -6,6 +6,7 @@ from fragments.ast_nodes import (
|
|
|
6
6
|
ASTComponentArgument,
|
|
7
7
|
ASTComponentName,
|
|
8
8
|
ASTControlNode,
|
|
9
|
+
ASTDoctype,
|
|
9
10
|
ASTFragment,
|
|
10
11
|
ASTHTMLAttribute,
|
|
11
12
|
ASTHTMLComment,
|
|
@@ -117,6 +118,10 @@ def expect_fragment(source: Source) -> tuple[Source, ASTFragment]:
|
|
|
117
118
|
|
|
118
119
|
def expect_child(source: Source) -> tuple[Source, ASTHTMLChild]:
|
|
119
120
|
"""Any HTML / functional block that might appear as part of the fragment."""
|
|
121
|
+
if source.remaining().startswith("<!DOCTYPE html>"):
|
|
122
|
+
source, doctype = expect_doctype(source)
|
|
123
|
+
return source, doctype
|
|
124
|
+
|
|
120
125
|
if source.remaining().startswith("<!--"):
|
|
121
126
|
source, html_comment = expect_html_comment(source)
|
|
122
127
|
return source, html_comment
|
|
@@ -192,6 +197,12 @@ def expect_component_name(source: Source) -> tuple[Source, ASTComponentName]:
|
|
|
192
197
|
return source, ASTComponentName(source_start, source.offset, name)
|
|
193
198
|
|
|
194
199
|
|
|
200
|
+
def expect_doctype(source: Source) -> tuple[Source, ASTDoctype]:
|
|
201
|
+
source_start = source.offset
|
|
202
|
+
source = expect_string(source, "<!DOCTYPE html>")
|
|
203
|
+
return source, ASTDoctype(source_start, source.offset)
|
|
204
|
+
|
|
205
|
+
|
|
195
206
|
def expect_html_comment(source: Source) -> tuple[Source, ASTHTMLComment]:
|
|
196
207
|
source_start = source.offset
|
|
197
208
|
source = expect_string(source, "<!--")
|
|
@@ -4,11 +4,11 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "python-fragments"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.29"
|
|
8
8
|
description = "Modern HTML template rendering in Python"
|
|
9
9
|
authors = [{ name = "The Running Algorithm", email = "services@therunningalgorithm.info" }]
|
|
10
10
|
readme = "README.md"
|
|
11
|
-
license = {
|
|
11
|
+
license = { file = "LICENSE" }
|
|
12
12
|
requires-python = ">=3.12"
|
|
13
13
|
dependencies = []
|
|
14
14
|
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: python-fragments
|
|
3
|
+
Version: 0.29
|
|
4
|
+
Summary: Modern HTML template rendering in Python
|
|
5
|
+
Author-email: The Running Algorithm <services@therunningalgorithm.info>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 The Running Algorithm
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Requires-Python: >=3.12
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Provides-Extra: lsp
|
|
32
|
+
Requires-Dist: basedpyright>=1.39.0; extra == "lsp"
|
|
33
|
+
Requires-Dist: lsprotocol>=2025.0.0; extra == "lsp"
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: pytest>=8.4.1; extra == "dev"
|
|
36
|
+
Dynamic: license-file
|
|
37
|
+
|
|
38
|
+
# Python Fragments
|
|
39
|
+
|
|
40
|
+
> **This package is in early development and not yet stable. The API may change without notice between releases.**
|
|
41
|
+
|
|
42
|
+
Modern HTML template rendering in Python — no build step, no template files, and native HTML awareness out of the box.
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from fragments import loader # isort: skip
|
|
46
|
+
|
|
47
|
+
from fastapi import FastAPI
|
|
48
|
+
from fastapi.responses import HTMLResponse
|
|
49
|
+
from components import Layout, PostCard
|
|
50
|
+
|
|
51
|
+
app = FastAPI()
|
|
52
|
+
|
|
53
|
+
POSTS = [...]
|
|
54
|
+
|
|
55
|
+
@app.get("/", response_class=HTMLResponse)
|
|
56
|
+
async def index() -> str:
|
|
57
|
+
published = [p for p in POSTS if p.published]
|
|
58
|
+
return <>
|
|
59
|
+
<Layout title="My Blog">
|
|
60
|
+
<h1>Latest Posts</h1>
|
|
61
|
+
<PostCard for={{ post in published }} post={{ post }} />
|
|
62
|
+
</Layout>
|
|
63
|
+
</>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## IDE Support
|
|
67
|
+
|
|
68
|
+
Type checking, completions, hover docs, go-to-definition, rename, and semantic highlighting — all working inside fragment syntax.
|
|
69
|
+
|
|
70
|
+

|
|
71
|
+
|
|
72
|
+
## Installation
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
pip install python-fragments
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Register the loader at your application's entry point, before importing any modules that contain fragments:
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
from fragments import loader # isort: skip
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Any `.py` file containing `<>` is transpiled automatically. Nothing else to configure.
|
|
85
|
+
|
|
86
|
+
## Feedback and feature requests
|
|
87
|
+
|
|
88
|
+
Bug reports and feature requests are welcome via [GitHub Issues](https://github.com/TheRunningAlgorithm2/python-fragments/issues). The project is not currently accepting code contributions.
|
|
@@ -6,6 +6,7 @@ from fragments.ast_nodes import (
|
|
|
6
6
|
ASTComponentArgument,
|
|
7
7
|
ASTComponentName,
|
|
8
8
|
ASTControlNode,
|
|
9
|
+
ASTDoctype,
|
|
9
10
|
ASTFragment,
|
|
10
11
|
ASTHTMLAttribute,
|
|
11
12
|
ASTHTMLComment,
|
|
@@ -23,6 +24,47 @@ def _transpiled(fragment: ASTFragment) -> ASTFragment:
|
|
|
23
24
|
return fragment
|
|
24
25
|
|
|
25
26
|
|
|
27
|
+
# ---------------------------------------------------------------------------
|
|
28
|
+
# Doctype
|
|
29
|
+
# ---------------------------------------------------------------------------
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_doctype_standalone():
|
|
33
|
+
source = Source.from_string("<><!DOCTYPE html></>")
|
|
34
|
+
source, fragment = grammar.expect_fragment(source)
|
|
35
|
+
assert source.at_end()
|
|
36
|
+
assert _transpiled(fragment) == _transpiled(ASTFragment(-1, -1, [
|
|
37
|
+
ASTDoctype(-1, -1)
|
|
38
|
+
]))
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_doctype_transpiles_to_literal_string():
|
|
42
|
+
source = Source.from_string("<><!DOCTYPE html></>")
|
|
43
|
+
_, fragment = grammar.expect_fragment(source)
|
|
44
|
+
fragment.transpile(0)
|
|
45
|
+
doctype = fragment.children[0]
|
|
46
|
+
assert isinstance(doctype, ASTDoctype)
|
|
47
|
+
assert doctype.transpiled_content == '"<!DOCTYPE html>"'
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def test_doctype_followed_by_element():
|
|
51
|
+
source = Source.from_string("<><!DOCTYPE html><html></html></>")
|
|
52
|
+
source, fragment = grammar.expect_fragment(source)
|
|
53
|
+
assert source.at_end()
|
|
54
|
+
assert _transpiled(fragment) == _transpiled(ASTFragment(-1, -1, [
|
|
55
|
+
ASTDoctype(-1, -1),
|
|
56
|
+
ASTHTMLElement(-1, -1, "html", {}, [], False),
|
|
57
|
+
]))
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_doctype_not_confused_with_comment():
|
|
61
|
+
source = Source.from_string("<><!DOCTYPE html><!-- a note --></>")
|
|
62
|
+
source, fragment = grammar.expect_fragment(source)
|
|
63
|
+
assert source.at_end()
|
|
64
|
+
assert isinstance(fragment.children[0], ASTDoctype)
|
|
65
|
+
assert isinstance(fragment.children[1], ASTHTMLComment)
|
|
66
|
+
|
|
67
|
+
|
|
26
68
|
# ---------------------------------------------------------------------------
|
|
27
69
|
# Comments
|
|
28
70
|
# ---------------------------------------------------------------------------
|
python_fragments-0.28/PKG-INFO
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: python-fragments
|
|
3
|
-
Version: 0.28
|
|
4
|
-
Summary: Modern HTML template rendering in Python
|
|
5
|
-
Author-email: The Running Algorithm <services@therunningalgorithm.info>
|
|
6
|
-
License: Proprietary
|
|
7
|
-
Requires-Python: >=3.12
|
|
8
|
-
Description-Content-Type: text/markdown
|
|
9
|
-
Provides-Extra: lsp
|
|
10
|
-
Requires-Dist: basedpyright>=1.39.0; extra == "lsp"
|
|
11
|
-
Requires-Dist: lsprotocol>=2025.0.0; extra == "lsp"
|
|
12
|
-
Provides-Extra: dev
|
|
13
|
-
Requires-Dist: pytest>=8.4.1; extra == "dev"
|
|
14
|
-
|
|
15
|
-
# Python Fragments
|
|
16
|
-
|
|
17
|
-
> **This package is in early development and not yet stable. The API may change without notice between releases.**
|
|
18
|
-
|
|
19
|
-
Production-ready, modern HTML template rendering in Python — no build step, no template files, and native HTML awareness out of the box.
|
|
20
|
-
|
|
21
|
-
```python
|
|
22
|
-
from fragments import loader # isort: skip
|
|
23
|
-
|
|
24
|
-
from fastapi import FastAPI
|
|
25
|
-
from fastapi.responses import HTMLResponse
|
|
26
|
-
from components import Layout, PostCard
|
|
27
|
-
|
|
28
|
-
app = FastAPI()
|
|
29
|
-
|
|
30
|
-
POSTS = [...]
|
|
31
|
-
|
|
32
|
-
@app.get("/", response_class=HTMLResponse)
|
|
33
|
-
async def index() -> str:
|
|
34
|
-
published = [p for p in POSTS if p.published]
|
|
35
|
-
return <>
|
|
36
|
-
<Layout title="My Blog">
|
|
37
|
-
<h1>Latest Posts</h1>
|
|
38
|
-
<PostCard for={{ post in published }} post={{ post }} />
|
|
39
|
-
</Layout>
|
|
40
|
-
</>
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
## Installation
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
pip install python-fragments
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
Register the loader at your application's entry point, before importing any modules that contain fragments:
|
|
50
|
-
|
|
51
|
-
```python
|
|
52
|
-
from fragments import loader # isort: skip
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
Any `.py` file containing `<>` is transpiled automatically. Nothing else to configure.
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: python-fragments
|
|
3
|
-
Version: 0.28
|
|
4
|
-
Summary: Modern HTML template rendering in Python
|
|
5
|
-
Author-email: The Running Algorithm <services@therunningalgorithm.info>
|
|
6
|
-
License: Proprietary
|
|
7
|
-
Requires-Python: >=3.12
|
|
8
|
-
Description-Content-Type: text/markdown
|
|
9
|
-
Provides-Extra: lsp
|
|
10
|
-
Requires-Dist: basedpyright>=1.39.0; extra == "lsp"
|
|
11
|
-
Requires-Dist: lsprotocol>=2025.0.0; extra == "lsp"
|
|
12
|
-
Provides-Extra: dev
|
|
13
|
-
Requires-Dist: pytest>=8.4.1; extra == "dev"
|
|
14
|
-
|
|
15
|
-
# Python Fragments
|
|
16
|
-
|
|
17
|
-
> **This package is in early development and not yet stable. The API may change without notice between releases.**
|
|
18
|
-
|
|
19
|
-
Production-ready, modern HTML template rendering in Python — no build step, no template files, and native HTML awareness out of the box.
|
|
20
|
-
|
|
21
|
-
```python
|
|
22
|
-
from fragments import loader # isort: skip
|
|
23
|
-
|
|
24
|
-
from fastapi import FastAPI
|
|
25
|
-
from fastapi.responses import HTMLResponse
|
|
26
|
-
from components import Layout, PostCard
|
|
27
|
-
|
|
28
|
-
app = FastAPI()
|
|
29
|
-
|
|
30
|
-
POSTS = [...]
|
|
31
|
-
|
|
32
|
-
@app.get("/", response_class=HTMLResponse)
|
|
33
|
-
async def index() -> str:
|
|
34
|
-
published = [p for p in POSTS if p.published]
|
|
35
|
-
return <>
|
|
36
|
-
<Layout title="My Blog">
|
|
37
|
-
<h1>Latest Posts</h1>
|
|
38
|
-
<PostCard for={{ post in published }} post={{ post }} />
|
|
39
|
-
</Layout>
|
|
40
|
-
</>
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
## Installation
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
pip install python-fragments
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
Register the loader at your application's entry point, before importing any modules that contain fragments:
|
|
50
|
-
|
|
51
|
-
```python
|
|
52
|
-
from fragments import loader # isort: skip
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
Any `.py` file containing `<>` is transpiled automatically. Nothing else to configure.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/client_message_handlers/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/client_message_handlers/completion.py
RENAMED
|
File without changes
|
{python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/client_message_handlers/definition.py
RENAMED
|
File without changes
|
{python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/client_message_handlers/diagnostics.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/client_message_handlers/hover.py
RENAMED
|
File without changes
|
{python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/client_message_handlers/inlay_hints.py
RENAMED
|
File without changes
|
{python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/client_message_handlers/lifecycle.py
RENAMED
|
File without changes
|
{python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/client_message_handlers/references.py
RENAMED
|
File without changes
|
{python_fragments-0.28 → python_fragments-0.29}/fragments/lsp/client_message_handlers/rename.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_fragments-0.28 → python_fragments-0.29}/python_fragments.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|