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

support for custom, non-selectable code block prompts #1051

Open
1 task done
hazel-nut opened this issue Feb 21, 2025 · 2 comments
Open
1 task done

support for custom, non-selectable code block prompts #1051

hazel-nut opened this issue Feb 21, 2025 · 2 comments

Comments

@hazel-nut
Copy link

hazel-nut commented Feb 21, 2025

Is there an existing issue for this?

  • I have searched the existing issues

What problem does this feature solve?

there's a simple bash lexer in #551 and ongoing discussion about said lexer in the open issue #137, which uses a regex to find a few prompt options based on content included directly in the code block.

the issues i see:

  • this only supports a hard-coded list of prompts specifically for bash sessions, and not other shells/REPLs

  • this requires the prompts to be inline mixed with the console commands

  • this has copy/paste issues: it allows the resulting .gp styled span to be copied and pasted, and the command following the prompt contains a preceding space

What feature do you propose?

it'd be nice to have a way to specify a custom prompt that displays on specified lines and isn't selectable.

use cases

for example, this could display user@host:~/path/to/dir for ssh connections, >>> for the python repl, or databaseName=# for psql.

i'm coming at this from a hugo perspective, so what i'd love to be able to do is add an info string to a code fence like this:

bash {prompt="user@host:~/path/to/dir",p_lines=[1-4,6,8]}

and have the resulting code block display the prompt, unselectable, on the specified lines.

implementation?

i'm not terribly familiar with chroma itself, so i'm not sure if the following implementation would make sense, but is there a plausible approach for this with a new formatter constructor option (akin to HighlightLines())?

the same way highlighting lines adds the .hl class to each line specified, prompts could add a data attribute each line specified, and styles could use something like:

.line::before {
   content: attr(data-chroma-prompt);
}

to style them. using a before pseudoelement would also make the prompt unselectable.

@alecthomas
Copy link
Owner

Unfortunately that would be quite difficult in Chroma. Lexing and rendering are separate steps, so by the time the renderer receives the tokens it doesn't really know what language it is, so there is no way to do something custom.

@hazel-nut
Copy link
Author

@alecthomas, hmm, the thought i had about custom prompts wouldn't be based off of parsing in the lexer or anything language specific. it would be a constructor option for the formatter that applies a style to each line (not token), similar to the way HighlightLines() seems to work.

thank you for replying!

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

No branches or pull requests

2 participants