streamarkdown 0.1.0__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.
@@ -0,0 +1,10 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
@@ -0,0 +1 @@
1
+ 3.13
@@ -0,0 +1,8 @@
1
+ Metadata-Version: 2.4
2
+ Name: streamarkdown
3
+ Version: 0.1.0
4
+ Summary: streaming markdown
5
+ Author-email: c <0xe0ffff@gmail.com>
6
+ Requires-Python: >=3.13
7
+ Requires-Dist: markdown-it-py>=4.0.0
8
+ Requires-Dist: rich>=14.3.3
File without changes
@@ -0,0 +1,20 @@
1
+ [project]
2
+ name = "streamarkdown"
3
+ version = "0.1.0"
4
+ description = "streaming markdown"
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "c", email = "0xe0ffff@gmail.com" }
8
+ ]
9
+ requires-python = ">=3.13"
10
+ dependencies = [
11
+ "markdown-it-py>=4.0.0",
12
+ "rich>=14.3.3",
13
+ ]
14
+
15
+ [project.scripts]
16
+ streamarkdown = "streamarkdown:main"
17
+
18
+ [build-system]
19
+ requires = ["hatchling"]
20
+ build-backend = "hatchling.build"
@@ -0,0 +1,97 @@
1
+ import sys
2
+
3
+ from markdown_it import MarkdownIt
4
+ from rich.console import Console
5
+ from rich.live import Live
6
+ from rich.markdown import Markdown, TextElement
7
+ from rich.text import Text
8
+ from rich.theme import Theme
9
+
10
+
11
+ class MyHeading(TextElement):
12
+ @classmethod
13
+ def create(cls, _, token):
14
+ return cls(token.tag)
15
+
16
+ def on_enter(self, context) -> None:
17
+ self.text = Text()
18
+ context.enter_style("bold")
19
+
20
+ def __init__(self, tag) -> None:
21
+ self.tag = tag
22
+ super().__init__()
23
+
24
+ def __rich_console__(self, _console, _options):
25
+ text = Text("".join("#" for _ in range(int(self.tag[1:]))))
26
+ text.stylize("yellow")
27
+ text.stylize("bold")
28
+ text.append(" ")
29
+ text.append_text(self.text)
30
+ yield text
31
+
32
+
33
+ Markdown.elements["heading_open"] = MyHeading
34
+
35
+ console = Console(
36
+ theme=Theme(
37
+ {
38
+ "markdown.block_quote": "violet",
39
+ "markdown.hr": "medium_purple4",
40
+ "markdown.link_url": "sky_blue1",
41
+ }
42
+ )
43
+ )
44
+
45
+
46
+ def full(string):
47
+ console.print(Markdown(string))
48
+
49
+
50
+ def stream(strings) -> str:
51
+ whole_string = ""
52
+ current_block = ""
53
+
54
+ def flatten_strings(strings):
55
+ for string in strings:
56
+ for char in string:
57
+ yield char
58
+
59
+ def block_recognized():
60
+ nonlocal current_block
61
+ md = MarkdownIt("js-default")
62
+ tokens_len = 0
63
+ for char in flatten_strings(strings):
64
+ current_block += char
65
+ tokens = md.parse(current_block)
66
+ new_block = (
67
+ tokens_len != len(tokens)
68
+ and current_block[-3:][:2] == "\n\n"
69
+ and char not in "-*123456789|"
70
+ )
71
+ tokens_len = len(tokens)
72
+ yield (char, new_block)
73
+
74
+ def new_live() -> Live:
75
+ live = Live(console=console, refresh_per_second=10)
76
+ live.start()
77
+ return live
78
+
79
+ live = new_live()
80
+
81
+ for char, new_block in block_recognized():
82
+ if new_block:
83
+ current_block = char
84
+ live.stop()
85
+ console.print("")
86
+ live = new_live()
87
+
88
+ whole_string += char
89
+ live.update(Markdown(current_block))
90
+
91
+ live.stop()
92
+
93
+ return whole_string
94
+
95
+
96
+ def main() -> None:
97
+ stream(sys.stdin)
@@ -0,0 +1,61 @@
1
+ version = 1
2
+ revision = 2
3
+ requires-python = ">=3.13"
4
+
5
+ [[package]]
6
+ name = "markdown-it-py"
7
+ version = "4.0.0"
8
+ source = { registry = "https://pypi.org/simple" }
9
+ dependencies = [
10
+ { name = "mdurl" },
11
+ ]
12
+ sdist = { url = "https://files.pythonhosted.org/packages/5b/f5/4ec618ed16cc4f8fb3b701563655a69816155e79e24a17b651541804721d/markdown_it_py-4.0.0.tar.gz", hash = "sha256:cb0a2b4aa34f932c007117b194e945bd74e0ec24133ceb5bac59009cda1cb9f3", size = 73070, upload-time = "2025-08-11T12:57:52.854Z" }
13
+ wheels = [
14
+ { url = "https://files.pythonhosted.org/packages/94/54/e7d793b573f298e1c9013b8c4dade17d481164aa517d1d7148619c2cedbf/markdown_it_py-4.0.0-py3-none-any.whl", hash = "sha256:87327c59b172c5011896038353a81343b6754500a08cd7a4973bb48c6d578147", size = 87321, upload-time = "2025-08-11T12:57:51.923Z" },
15
+ ]
16
+
17
+ [[package]]
18
+ name = "mdurl"
19
+ version = "0.1.2"
20
+ source = { registry = "https://pypi.org/simple" }
21
+ sdist = { url = "https://files.pythonhosted.org/packages/d6/54/cfe61301667036ec958cb99bd3efefba235e65cdeb9c84d24a8293ba1d90/mdurl-0.1.2.tar.gz", hash = "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba", size = 8729, upload-time = "2022-08-14T12:40:10.846Z" }
22
+ wheels = [
23
+ { url = "https://files.pythonhosted.org/packages/b3/38/89ba8ad64ae25be8de66a6d463314cf1eb366222074cfda9ee839c56a4b4/mdurl-0.1.2-py3-none-any.whl", hash = "sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8", size = 9979, upload-time = "2022-08-14T12:40:09.779Z" },
24
+ ]
25
+
26
+ [[package]]
27
+ name = "pygments"
28
+ version = "2.20.0"
29
+ source = { registry = "https://pypi.org/simple" }
30
+ sdist = { url = "https://files.pythonhosted.org/packages/c3/b2/bc9c9196916376152d655522fdcebac55e66de6603a76a02bca1b6414f6c/pygments-2.20.0.tar.gz", hash = "sha256:6757cd03768053ff99f3039c1a36d6c0aa0b263438fcab17520b30a303a82b5f", size = 4955991, upload-time = "2026-03-29T13:29:33.898Z" }
31
+ wheels = [
32
+ { url = "https://files.pythonhosted.org/packages/f4/7e/a72dd26f3b0f4f2bf1dd8923c85f7ceb43172af56d63c7383eb62b332364/pygments-2.20.0-py3-none-any.whl", hash = "sha256:81a9e26dd42fd28a23a2d169d86d7ac03b46e2f8b59ed4698fb4785f946d0176", size = 1231151, upload-time = "2026-03-29T13:29:30.038Z" },
33
+ ]
34
+
35
+ [[package]]
36
+ name = "rich"
37
+ version = "14.3.3"
38
+ source = { registry = "https://pypi.org/simple" }
39
+ dependencies = [
40
+ { name = "markdown-it-py" },
41
+ { name = "pygments" },
42
+ ]
43
+ sdist = { url = "https://files.pythonhosted.org/packages/b3/c6/f3b320c27991c46f43ee9d856302c70dc2d0fb2dba4842ff739d5f46b393/rich-14.3.3.tar.gz", hash = "sha256:b8daa0b9e4eef54dd8cf7c86c03713f53241884e814f4e2f5fb342fe520f639b", size = 230582, upload-time = "2026-02-19T17:23:12.474Z" }
44
+ wheels = [
45
+ { url = "https://files.pythonhosted.org/packages/14/25/b208c5683343959b670dc001595f2f3737e051da617f66c31f7c4fa93abc/rich-14.3.3-py3-none-any.whl", hash = "sha256:793431c1f8619afa7d3b52b2cdec859562b950ea0d4b6b505397612db8d5362d", size = 310458, upload-time = "2026-02-19T17:23:13.732Z" },
46
+ ]
47
+
48
+ [[package]]
49
+ name = "streamarkdown"
50
+ version = "0.1.0"
51
+ source = { editable = "." }
52
+ dependencies = [
53
+ { name = "markdown-it-py" },
54
+ { name = "rich" },
55
+ ]
56
+
57
+ [package.metadata]
58
+ requires-dist = [
59
+ { name = "markdown-it-py", specifier = ">=4.0.0" },
60
+ { name = "rich", specifier = ">=14.3.3" },
61
+ ]