Comments (5)
This should work
script -q -c "python /tmp/asd.py --help" | ansi2html > asd.html
That being said i guess it would be nice to have something like --color-always
option like with the ls
-command:
ls -la --color=always | ansi2html > asd.html
from typer.
Another approach is to use the rich export functions:
If you're using sphinx-doc with reStructuredText, I wrote a directive extension to do this for you. Unfortunately typer has no official way to access the console object, so a monkey patch is involved.
from typer.
That being said i guess it would be nice to have something like
--color-always
option like with thels
-command:
Colors appear just fine here, after script -q -c "clitool --help" | ansi2html > clitoolhelp.html
and viewing the latter file in a browser.
from typer.
If you're using sphinx-doc with reStructuredText, I wrote a directive extension to do this for you. Unfortunately typer has no official way to access the console object, so a monkey patch is involved.
Nice work! Pity, I am trying out Material MkDocs :-/
from typer.
In case anyone wants to integrate this kind of thing directly into their application, here's an example of a command I created for our Typer application to get the full help output as HTML:
import typer
from typer.cli import docs, state
help = typer.Typer()
@help.command()
def view(ctx: typer.Context):
"""View HTML help for this tool."""
state.module = HELP_DOCS_TARGET # e.g. "myapp.main"
help_docs_gen_dir = Path(tempfile.mkdtemp())
markdown = help_docs_gen_dir / "help.md"
html = help_docs_gen_dir / "help.html"
docs(ctx, name=COMMAND_NAME, title=MAIN_TITLE, output=markdown)
# Convert Markdown containing Rich console syntax to HTML
markdown_content = markdown.read_text()
rich_text = Text.from_markup(markdown_content)
formatted_markdown_content = Markdown(str(rich_text))
console = Console(record=True, file=open(os.devnull, "w"))
console.print(formatted_markdown_content)
console.save_html(str(html))
print(f"Docs saved to: {html}")
typer.launch(f"file://{html}")
It's possible this will be greatly simplified and improved with #819
from typer.
Related Issues (20)
- How do I pass the None value explicitly? HOT 2
- Documentation is misleading. new `typer.run` behavior HOT 2
- See if rich 13.x is compatible HOT 4
- Using `some_type | None` syntax for type annotations causes error in python 3.11 HOT 12
- unlimited argument for an option with comma spliter HOT 1
- TAB completion is giving local directory files where command is called. HOT 2
- Support for bytes in Options and Arguments HOT 2
- Is it possible to include a Prolog in `--help` HOT 2
- how to use typer on class method __init__ with self argument, got this error: Error: Missing argument 'SELF'. HOT 2
- Support for localization of messages HOT 1
- Auto-completion when application works in 2 modes (GUI, CLI) HOT 1
- DOC: Documentation of passing multiple values in "option" vs "argument" isn't sufficiently explicit HOT 2
- SIGINT from docker is ignored HOT 4
- 🚀 Roadmap HOT 2
- Source distribution of 0.11.0 is missing the `docs_src` folder HOT 1
- 🐛 Upgrading from `typer<0.12.0` to `typer==0.12.0` breaks the install by partially removing the package/module files HOT 4
- Rich markup in generated Markdown docs HOT 1
- Add CI configs to run tests on Windows and MacOS
- Rich markup in Zsh completion help lines
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 typer.