ilius / pyglossary

A tool for converting dictionary files aka glossaries. Mainly to help use our offline glossaries in any Open Source dictionary we like on any modern operating system / device.
GNU General Public License v3.0
2.23k stars 237 forks source link

DSL: customized colours and styles via CSS #498

Closed soshial closed 8 months ago

soshial commented 1 year ago

Firstly, example default color is gray. Secondly, stressed letters should be red. Thirdly, I think it would be nice if other tags would have customizable colours, similar to Lingvo official program:

image

ilius commented 1 year ago

Firstly, we don't have to have the same defaults. Specially if you want to have the option of using a dark theme (that's why I don't like gray text)

Secondly, if you use a format like StarDict (not a binary format like slob or AppleDict binary), you can edit a CSS file after conversion, while using the dict app, rather than converting again to change a color.

So we just need an option to include a CSS file name in every entry.

soshial commented 1 year ago

I agree with you, a middle ground would to just make those 4 values customizable. Same parameters would be re-used when converting XDXF <ex>, <kref>, <abbr> tags.

soshial commented 11 months ago

We don't necessarily need to implement it via command parameters, I think just having a single CSS and a set of classes (examples, grammar, transcription etc. ) that's added to all glosses.

BorisNA commented 9 months ago

I propose the following solution (in the DSL reader):

  1. All the important tags (like t, ex, m[\d] etc.) should be converted to a span/div with a corresponding class. No hardcoded css styles, font names etc.
  2. Color tags (136 text-named colors?) should be converted to classes like <span class="c_red"> too
  3. There should be a pre-made external CSS file (bundled with the pyglossary) containing all these declarations.
  4. This behaviour could be turned on/off based on the only DSL read option like use_external_css or like. "Off" is default and means using old hard-coded css style behaviour.
    • Extra. Octopus writer plugin in gist should have an option to include a link to this external css in every card body.

In this case we could allow easy output dictionary customization for the user, like changing indents (important on phones) or even changing display:block to display:inline to remove line breaks (popup dictionaries like Kindle mobi).

@ilius if you are Ok with this and are ready to accept such a PR, I will try to implement it - it looks not too difficult.

soshial commented 9 months ago

Thanks for your proposal, @BorisNA — that's exactly how I imagined converting dictionaries: with CSS classes and not hardcoded colours & values.

soshial commented 9 months ago

@ilius what do you think about this? This improvement would help so much improving how dictionaries appearance and would become easier to read! Please consider this!

soshial commented 8 months ago

Здравствуй, @BorisNA, have you had a chance to work on your cool idea of customizable CSS for DSL dicts? :)

BorisNA commented 8 months ago

@soshial I see that this is not something that the author needs or even wants in his project, so I believe that it will be a waste of time, unfortunately.

ilius commented 8 months ago

Changing all html formatting to check for an option to switch between current logic and CSS makes it very bloated and hard to maintain (and slower). And we can't completely switch to CSS because some dictionaries don't support it.

I think a single-purpose tool (to convert DSL to StarDict for example) can do a much better job than pyglossary which is general-purpose.

It's probably my fault for not thinking it through at first. I'm gonna close this issue.