Code Monkey home page Code Monkey logo

Comments (4)

willmcgugan avatar willmcgugan commented on May 18, 2024 2

Couple of things going on here. Rich detects that it is not writing directly to a terminal and won't output control codes. Normally this is desirable, but you can force it to write control codes by adding force_terminal=True to the Console constructor.

I've also noticed that less itself won't display color/style unless you add the -R switch.

Hope that helps.

from rich.

willmcgugan avatar willmcgugan commented on May 18, 2024 1

@NightMachinary That's not a bad idea. It could work with python -m rich.markdown readme.md

from rich.

willmcgugan avatar willmcgugan commented on May 18, 2024 1

I've added a python -m rich.markdown command. Hopefully this will do what you need.

If you need any changes I'd be happy to accept a PR. See the end of markdown.py

from rich.

NightMachinery avatar NightMachinery commented on May 18, 2024

I suggest adding this code snippet to the readme, lots of people will find it useful (there are tools like mdless just for this, and I like rich better.)

#!/usr/bin/env python3

import sys, os
from rich.console import Console
from rich.markdown import Markdown

console = Console(force_terminal=bool(os.environ.get("rich_force_terminal", True)))
with open(sys.argv[1]) as readme:
    markdown = Markdown(readme.read(), code_theme="")
console.print(markdown)

I also use the following zsh snippet in addition to the above:

mdv() {
    # mdview
    local readme="$(fd -e md|head -1)"
    md.py "${@:-$readme}" | less
}

from rich.

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.