New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add ansi support #386
Conversation
✅ Deploy Preview for shiki-matsu ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Realistically it's on @octref to make the call - that said I did audit anser though, and it seems like a small, well-built dependency. |
@octref what are your thoughts on this? I'd like to try contributing this to nextra instead if you're not interested. |
Hey @blake-mealey, I think this change is good. However I want to avoid overloading the list of Don't worry about making changes to the website. I'll make a new one. Also curious – how are you getting the terminal output with escape sequences? |
Sounds good, I'll look into using a separate API. I use iTerm2 which has a "Copy with Control Sequences" command in the Edit menu. If you don't have this feature you can also pipe the command into a file and it should maintain control sequences (some commands might disable colors if you're piping and you'll need to pass an option or set an env var to force colors). |
3ff422a
to
5f6db84
Compare
I updated it to use a new I'm also wondering about how this would get used downstream. I guess the markdown parser would need to look for a special meta tag on the code block like: ``` higlightAnsi
# ansi content here
``` ...and then pass the appropriate option when highlighting it |
For highlighting a For using something like const fs = require('fs')
const markdown = require('markdown-it')
const shiki = require('shiki')
shiki.getHighlighter().then(highlighter => {
const md = markdown({
highlight: (code, lang) => {
if (lang === 'ansi') {
highlighter.ansiToHtml(...)
}
return highlighter.codeToHtml(code, { lang })
}
})
}) And my bad, I didn't mean |
Ahh yeah that makes sense, and also works better for downstream use as you described. I'll update this later when I get a chance. Thanks |
OK, updated as described, lmk what you think. Should I write tests for this? I didn't see other tests |
Pretty clean code. Well done! You want to add a test in |
Added some tests, lmk if that's sufficient or what else you'd like to see tested |
LGTM but why are you using inline snapshots instead of snapshots? Aren't those harder to maintain? I don't have a strong preference though. Another thing is can you edit this PR so it merges into |
Made some changes:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
You wrote a new parser? That's productive 🚀 My rough plan for 1.0 is to have as much variety of input (text, ansi) and output (html, svg, svg-path, ansi) as possible. |
Cool! When are you planning to release 1.0? I'd like to be able to use this feature in a project :) |
Probably gonna take a while. I guess I'll just release this feature as 0.14 then. |
Thanks for making the exception for me! |
I'd like to try this feature but I found is there an additional Is there a related demo for reference~ ```ansi
$ czg --help
�[33mNAME:�[0m
�[32mczg�[0m - Interactive Commitizen CLI that generate standardized commit messages
�[33mWEBSITE:�[0m
�[4mhttps://cz-git.qbb.sh/cli/�[0m
�[4mhttps://github.com/Zhengqbbb/cz-git�[0m
�[33mSYNOPSIS:�[0m
czg [subcommand...] [options...] [git-commit-options...]
�[33mSUBCOMMAND:�[0m
�[36mbreak�[0m �[31mTurn on appends a ! after the type/scope�[0m
�[36memoji�[0m �[31mTurn on output message with emoji mode�[0m
�[36mcheckbox�[0m �[31mTurn on scope checkbox mode�[0m
�[36mgpg�[0m �[31mTurn on use GPG sign commit message�[0m
�[33mOPTIONS:�[0m
�[36m--config�[0m �[31mSpecify the configuration file to use�[0m
�[36m:, --alias�[0m �[31mDirectly submit the defined commit message�[0m
�[36m-r, --retry�[0m �[31mDirectly retry submit by the last message�[0m
�[36m-h, --help�[0m �[31mShow help�[0m
�[36m-v, --version�[0m �[31mShow version�[0m
�[33mEXAMPLES:�[0m
�[36mczg�[0m
�[36mczg emoji�[0m
�[36mczg :fd�[0m
�[36mczg --alias=fd�[0m
�[36mczg --config="./config/cz.json"�[0m
Extends 'git commit' options.
See 'git commit --help' for more information.
�[1m�[7m%�[27m�[1m�[0m
`` |
#386 (comment) |
This is a very rough proof of concept for closing #315. Looking for feedback on whether this is a desired feature or not. Here's some example output I got from editing the site with a new ansi codeblock: