Aloso / to-html

Utilities for making the colo documentation
MIT License
75 stars 10 forks source link

allow mapping color palette #23

Closed bend-n closed 1 year ago

bend-n commented 1 year ago

expose some way of instead of using the default color. so i can change green (etc) to be light green, or even a completely different color. currently i can just .replace("#color", "#color") but yeah..

may i suggest a option to instead of style="color:#fff", class="white"

bend-n commented 1 year ago

never mind it seems that you can use a style sheet

bend-n commented 1 year ago

never never mind it seems the style sheet thing is for like "terminal" styling

CosmicHorrorDev commented 1 year ago

I've actually been meaning to open an issue about this same feature! (It's one of the reasons I wanted a to-html config file)

My use case is that currently the styling will generate something like this

$ to-html 'ls --color'
<pre class="terminal">
<span class='shell'>&gt; </span><span class='cmd'>ls</span> <span class='flag'>--color</span>
file.txt  <b><span style='color:#00a'>dir</span></b>
<span class='shell'>&gt; </span><span class='caret'> </span>
</pre>

where the color blue is hard-coded through <span style='color:#00a'>. For my use case I would like it to be <span class='term-blue'> instead

I was thinking that we could handle all the 4-bit colors by adding a section to the config like so

[color]  # alias for [colour] as well
black.attr = "<attr-value>"
# The same for all other 4-bit colors

So I could handle the above by setting

[color]
black.class = "term-black"
red.class = "term-red"
# ...
bright-black.class = "term-bright-black"
bright-red.class = "term-bright-red"
# ...

This doesn't handle 8 or 24 bit colors, but it seems so much less likely that someone would want to customize them that I think we could just kick the can on handling it. Could probably be something like

[color]
eight_bit = [
    ["16", { attr = "<attr-value>" }],
    # ...
]
Aloso commented 1 year ago

I don't think the color values should be configurable by hand, but using CSS classes rather than inline styles makes sense.

I'd like having a flag, --color-classes, for producing class="red" instead of style="color:#f00".

The --prefix flag can be used here as well, so you can write --color-classes --prefix=term to get class="term-red".

I initially went with the hard-coded color values to make to-html very easy to use out of the box, with no setup. This is insufficient when you want to customize it, but it should still be intuitive and easy to use, so I think CSS classes make the most sense here.

CosmicHorrorDev commented 1 year ago

That sounds like a nice simple solution 👍

I can give the implementation a shot sometime later this week unless someone else wants to handle it

Aloso commented 1 year ago

Thanks! BTW I'm against customizing 8 bit or 24 bit colors; these correspond to specific sRGB values, and unlike 3/4 bit colors, usually aren't customizable in terminals either.

P.S. @CosmicHorrorDev you are welcome to do it, I'd be pleased :)

bend-n commented 1 year ago

I use the library, not the CLI, so can there be a flag there too? Also i agree on not being able to customize truecolor.

CosmicHorrorDev commented 1 year ago

I use the library, not the CLI, so can there be a flag there too?

Yup, that's where the core functionality will have to live 👍

Aloso commented 1 year ago

@bend-n interesting, may I ask what you use it for?

bend-n commented 1 year ago

A html terminal panel thing which is dark-theme'd.