Code Monkey home page Code Monkey logo

Comments (8)

pawamoy avatar pawamoy commented on June 2, 2024 1

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.

pawamoy avatar pawamoy commented on June 2, 2024 1

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.

15r10nk avatar 15r10nk commented on June 2, 2024 1

Thank you, it works for me now.

from markdown-exec.

pawamoy avatar pawamoy commented on June 2, 2024

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.

pawamoy avatar pawamoy commented on June 2, 2024

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.

pawamoy avatar pawamoy commented on June 2, 2024

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.

pawamoy avatar pawamoy commented on June 2, 2024

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.

pawamoy avatar pawamoy commented on June 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.