Comments (8)
Hey @15r10nk, thanks for the report!
Interesting. My first intuition is that Rich uses ANSI codes that are not supported by pygments-ansi. I'll replicate the issue locally and report back 🙂
from markdown-exec.
Should be fixed in v1.8.1. Try with the standard color system and the ansi_light/ansi_dark theme and let me know if there are any other issues 🙂
from markdown-exec.
Thank you, it works for me now.
from markdown-exec.
Unfortunately none of the available color systems improve the situation 😕 I really thought the standard
one would help.
I don't know Rich enough to understand what it does with ANSI codes. I think its Syntax
objects are a bit more clever and use more than just the 16 color variations. Rich also sets a background for the diff block, that might be what is causing issues here, as background+foreground can be combined in a single ANSI sequence that maybe pygments-ansi or its style sheet have trouble with.
Workaround:
# codi.py
import os
from rich.console import Console
from rich.syntax import Syntax
console=Console(color_system="256")
code = """
code
- a
+ b
"""
with open(os.devnull, "w") as devnull:
console = Console(record=True, width=65, file=devnull, markup=False)
renderable = Syntax(code, "diff", theme="material")
console.print(renderable, markup=True, highlight=False)
print(console.export_html(inline_styles=True, code_format="<pre><code>{code}</code></pre>"))
<!-- index.md -->
```python exec="1" html="1"
--8<-- "codi.py"
```
from markdown-exec.
Here's the ANSI output of Rich with 256 color mode:
\e[31m red\e[0m
\e[32m green\e[0m
\e[48;5;235m \e[0m
\e[38;5;231;48;5;235m \e[0m\e[38;5;231;48;5;235m code\e[0m\e[48;5;235m \e[0m
\e[38;5;204;48;5;235m- a\e[0m\e[48;5;235m \e[0m
\e[38;5;148;48;5;235m+ b\e[0m\e[48;5;235m \e[0m
\e[48;5;235m \e[0m
I've manually escaped the escape sequence (\e
) and removed some whitespace.
from markdown-exec.
Here it is with the standard color mode:
\e[31m red\e[0m
\e[32m green\e[0m
\e[40m \e[0m
\e[97;40m \e[0m\e[97;40m code\e[0m\e[40m \e[0m
\e[91;40m- a\e[0m\e[40m \e[0m
\e[92;40m+ b\e[0m\e[40m \e[0m
\e[40m \e[0m
from markdown-exec.
It's a bit better with this (works for b
but not for a
for some reason):
console = Console(color_system="standard")
code = """
code
- a
+ b
"""
console.print(Syntax(code, "diff", theme="ansi_light"))
from markdown-exec.
Aha! This translates as a -Color-BrightRed
CSS class but there's no such class in the style sheet, only -Color-Bold-Red
. Let me try to update the style sheet 😄
from markdown-exec.
Related Issues (20)
- [Feature] Output logging in rendered output HOT 1
- [Feature] Option to globally disable execution HOT 1
- Add a cwd option to console
- stdout from "external" functions not shown HOT 8
- Compability with snippets HOT 3
- Feature Request: Support Other Languages? HOT 1
- Feature request: default behaviour for code blocs HOT 2
- No output without print and no line breaks HOT 1
- bug: source="tabbed-left" showing source vertically, rather than horizontally HOT 9
- bug: ANSI escape codes in `jax.ClosedJaxpr` are not being converted to HTML HOT 3
- Consideration for `mkdocs get-deps` regarding the `[ansi]` extra HOT 2
- bug: Don't always include ANSI CSS file
- Appearance of code block headings in the navigation sidebar HOT 1
- bug: Directory change dos not persist between code blocks executed on the same session HOT 3
- feat: Support specifying terminal width HOT 5
- bug: can not run the example HOT 3
- feature: Issue warning if pymdownx.superfences is not enabled
- enhancement: Increase minimum height of pyodide output code block
- feature: Add option to specify initial number of lines in pyodide fence editors
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from markdown-exec.