Skip to content
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

Use nu-highlight for code blocks #1719

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

Conversation

132ikl
Copy link
Contributor

@132ikl 132ikl commented Dec 28, 2024

Work in progress. Adds a Shiki transformer which uses the highlight.nu script to highlight nushell code blocks using nu-highlight.

Also adds the ability to add code before the true code block, for examples which require extra code to work:

def "str mycommand" [] {
  "hello"
}
# BEGIN EXAMPLE
str mycommand

Only the str mycommand line will show up in the final code block, but it will not be error highlighted since the str mycommand definition exists.

The output of nu-highlight heavily depends on bold fonts for readability, so we should make sure all of the fonts listed in --code-font-family support bold. Notably, on my machine the font fell back to Andale Mono, which did not have a bold face. I was able to get bold ansi highlighting working install consolas, which is a higher priority font in --code-font-family and does have a bold face.

Need to rebase this on #1718 assuming that gets merged.

@NotTheDr01ds NotTheDr01ds requested a review from hustcer December 28, 2024 21:58
Copy link
Collaborator

@hustcer hustcer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a brilliant idea 👍 , just need a bit tweaks

Comment on lines +10 to +12
- name: Install Nushell
run: cargo install nu --locked --no-default-features

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Install Nu by this way is quite slow, try this one: https://github.com/hustcer/setup-nu

Comment on lines +211 to +218
this.options.defaultColor = 'onedarkpro';
// this doesn't work at the top-level for some reason
this.options.colorReplacements = {
// make one-dark-pro background color the same as dark-plus
'#282c34': '#1e1e1e',
// HACK: change color of comments, since nu-highlight can't highlight them
'#abb2bf': '#80858f',
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to extract these a few lines to a function like adjustTheme, so we can reuse it later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants