streamdown 0.14.0__py3-none-any.whl → 0.15.0__py3-none-any.whl

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.
streamdown/sd.py CHANGED
@@ -26,6 +26,7 @@ import importlib
26
26
  from io import BytesIO
27
27
  from term_image.image import from_file, from_url
28
28
  import pygments.util
29
+ from functools import reduce
29
30
  from argparse import ArgumentParser
30
31
  from pygments import highlight
31
32
  from pygments.lexers import get_lexer_by_name
@@ -91,8 +92,8 @@ KEYCODE_RE = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
91
92
 
92
93
  visible = lambda x: re.sub(ANSIESCAPE, "", x)
93
94
  visible_length = lambda x: len(visible(x))
94
-
95
95
  extract_ansi_codes = lambda text: re.findall(ESCAPE, text)
96
+ remove_ansi = lambda line, codeList: reduce(lambda line, code: line.replace(code, ''), codeList, line)
96
97
 
97
98
  def debug_write(text):
98
99
  if state.Logging:
@@ -271,6 +272,7 @@ def code_wrap(text_in):
271
272
 
272
273
  return (indent, res)
273
274
 
275
+
274
276
  # This marvelously obscure code "compacts" long lines of repetitive ANSI format strings by
275
277
  # removing duplicates. Here's how it works
276
278
  def ansi_collapse(codelist, inp):
@@ -665,6 +667,10 @@ def parse(stream):
665
667
  # then naively search back until our visible_lengths() match. This is not fast and there's certainly smarter
666
668
  # ways of doing it but this thing is way trickery than you think
667
669
  highlighted_code = highlight(state.code_buffer + tline, lexer, formatter)
670
+
671
+ # Sometimes the highlighter will do things like a full reset or a background reset.
672
+ # This is not what we want
673
+ highlighted_code = re.sub(r"\033\[39(;00|)m", '', highlighted_code)
668
674
 
669
675
  # Since we are streaming we ignore the resets and newlines at the end
670
676
  if highlighted_code.endswith(FGRESET + "\n"):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: streamdown
3
- Version: 0.14.0
3
+ Version: 0.15.0
4
4
  Summary: A streaming markdown renderer for modern terminals with syntax highlighting
5
5
  Project-URL: Homepage, https://github.com/kristopolous/Streamdown
6
6
  Project-URL: Bug Tracker, https://github.com/kristopolous/Streamdown/issues
@@ -23,6 +23,7 @@ Requires-Python: >=3.8
23
23
  Requires-Dist: appdirs
24
24
  Requires-Dist: pygments
25
25
  Requires-Dist: pylatexenc
26
+ Requires-Dist: term-image
26
27
  Requires-Dist: toml
27
28
  Description-Content-Type: text/markdown
28
29
 
@@ -30,30 +31,30 @@ Description-Content-Type: text/markdown
30
31
 
31
32
  [![PyPI version](https://badge.fury.io/py/streamdown.svg)](https://badge.fury.io/py/streamdown)
32
33
 
33
- I needed a streaming Markdown renderer and I couldn't find one. So here we go. From the ground up. It's a bad idea but it has to be done.
34
+ Streamdown is the streaming markdown renderer for the terminal that rocks.
35
+ This will work with [simonw's llm](https://github.com/simonw/llm). You even get full readline and keyboard navigation support.
34
36
 
35
- [sd demo](https://github.com/user-attachments/assets/48dba6fa-2282-4be9-8087-a2ad8e7c7d12)
37
+ It's fully streaming and does not block
38
+ ![Streamdown is Amazing](https://github.com/user-attachments/assets/268cb340-78cc-4df0-a773-c5ac95eceeeb)
36
39
 
37
- This will work with [simonw's llm](https://github.com/simonw/llm) unlike with [richify.py](https://github.com/gianlucatruda/richify) which rerenders the whole buffer and blocks with an elipses or [glow](https://github.com/charmbracelet/glow) which buffers everything, this streams and does exactly what it says.
40
+ ### Provides clean copyable code for long code lines
41
+ You may have noticed that other, *inferior* renderers will inject line breaks when copying code that wraps around. We're better and now, you can be as well.
42
+ ![Handle That Mandle](https://github.com/user-attachments/assets/a27aa70c-f691-4796-84f0-c2eb18c7de23)
38
43
 
39
- ## Some Features
40
-
41
- ### Provides clean copyable code for long code blocks and short terminals.
42
- ![copyable](https://github.com/user-attachments/assets/4a3539c5-b5d1-4d6a-8bce-032724d8909d)
43
-
44
- ### Supports images, why not?
44
+ ### Supports images
45
45
  Here's kitty and alacritty. Try to do that in glow...
46
46
  ![doggie](https://github.com/user-attachments/assets/9a392929-b6c2-4204-b257-e09305acb7af)
47
47
 
48
48
  ### Does OSC 8 links for modern terminals (and optionally OSC 52 for clipboard)
49
49
  [links.webm](https://github.com/user-attachments/assets/a5f71791-7c58-4183-ad3b-309f470c08a3)
50
50
 
51
- ### Doesn't consume characters like _ and * as style when they are in `blocks like this` because `_they_can_be_varaiables_`
52
- ![dunder](https://github.com/user-attachments/assets/d41d7fec-6dec-4387-b53d-f2098f269a5e)
53
-
54
51
  ### Tables are carefully supported
55
52
  ![table](https://github.com/user-attachments/assets/dbe3d13e-6bac-4f45-bf30-f1857ed98898)
56
53
 
54
+ As well as everything else...
55
+
56
+ ![dunder](https://github.com/user-attachments/assets/d41d7fec-6dec-4387-b53d-f2098f269a5e)
57
+
57
58
  ### Colors are highly (and quickly) configurable for people who care a lot, or just a little.
58
59
  ![configurable](https://github.com/user-attachments/assets/04b36749-4bb8-4c14-9758-84eb6e19b704)
59
60
 
@@ -84,7 +85,7 @@ Defines the base Hue (H), Saturation (S), and Value (V) from which all other pal
84
85
  * `Width` (integer, default: `0`): Along with the `Margin`, `Width` specifies the base width of the content, which when set to 0, means use the terminal width. See [#6](https://github.com/kristopolous/Streamdown/issues/6) for more details
85
86
  * `PrettyPad` (boolean, default: `false`): Uses a unicode vertical pad trick to add a half height background to code blocks. This makes copy/paste have artifacts. See [#2](https://github.com/kristopolous/Streamdown/issues/2). I like it on. But that's just me
86
87
  * `ListIndent` (integer, default: `2`): This is the recursive indent for the list styles.
87
- * `Syntax` (string, default `monokai`): This the syntax [highlighting theme which come via pygments](https://pygments.org/styles/).
88
+ * `Syntax` (string, default `monokai`): This is the syntax [highlighting theme which come via pygments](https://pygments.org/styles/).
88
89
 
89
90
  Example:
90
91
  ```toml
@@ -143,10 +144,8 @@ Do this
143
144
 
144
145
  $ ./streamdown/sd.py tests/*md
145
146
 
146
- Certainly room for improvement and I'll probably continue to make them
147
-
148
147
  ## Install from source
149
- At least one of these should work, hopefully
148
+ After the git clone least one of these should work, hopefully. it's using the modern uv pip tool.
150
149
 
151
150
  $ pipx install -e .
152
151
  $ pip install -e .
@@ -1,13 +1,13 @@
1
1
  streamdown/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- streamdown/sd.py,sha256=ZS7iqHme-GG5LzUlLT3dL6Cyw60Fscq6_7fL6kx777A,35250
2
+ streamdown/sd.py,sha256=TqW_kbt1YxeWOByaMuJD86XAfWq_Z9Lq1YFsCo0Apjk,35622
3
3
  streamdown/tt.mds,sha256=srDldQ9KnMJd5P8GdTXTJl4mjTowwV9y58ZIaBVbtFY,359
4
4
  streamdown/plugins/README.md,sha256=KWqYELs9WkKJmuDzYv3cvPlZMkArsNCBUe4XDoTLjLA,1143
5
5
  streamdown/plugins/latex.py,sha256=xZMGMdx_Sw4X1piZejXFHfEG9qazU4fGeceiMI0h13Y,648
6
6
  streamdown/scrape/file_0.py,sha256=OiFxFGGHu2C2iO9LVnhXKCybqCsnw0bu8MmI2E0vs_s,610
7
7
  streamdown/scrape/file_1.js,sha256=JnXSvlsk9UmU5LsGOfXkP3sGId8VNEJRJo8-uRohRCM,569
8
8
  streamdown/scrape/file_2.cpp,sha256=4hbT9TJzDNmrU7BVwaIuCMlI2BvUEVeTKoH6wUJRkrI,397
9
- streamdown-0.14.0.dist-info/METADATA,sha256=NLbNcNtHs7PNXAi6V4TcbxUtYZq_FU23KnPbIYllPoY,8054
10
- streamdown-0.14.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
11
- streamdown-0.14.0.dist-info/entry_points.txt,sha256=HroKFsFMGf_h9PRTE96NjvjJQWupMW5TGP5RGUr1O_Q,74
12
- streamdown-0.14.0.dist-info/licenses/LICENSE.MIT,sha256=SnY46EPirUsF20dZDR8HpyVgS2_4Tjxuc6f-4OdqO7U,1070
13
- streamdown-0.14.0.dist-info/RECORD,,
9
+ streamdown-0.15.0.dist-info/METADATA,sha256=-cJ1HR7jWmuxlwPYInt78MDl6i6r3asDtt2OAFDVxPs,7893
10
+ streamdown-0.15.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
11
+ streamdown-0.15.0.dist-info/entry_points.txt,sha256=HroKFsFMGf_h9PRTE96NjvjJQWupMW5TGP5RGUr1O_Q,74
12
+ streamdown-0.15.0.dist-info/licenses/LICENSE.MIT,sha256=SnY46EPirUsF20dZDR8HpyVgS2_4Tjxuc6f-4OdqO7U,1070
13
+ streamdown-0.15.0.dist-info/RECORD,,