lmg-anon / mikupad

LLM Frontend in a single html file
https://lmg-anon.github.io/mikupad/mikupad.html
Creative Commons Zero v1.0 Universal
175 stars 24 forks source link

[Feature request] Custom regex rule-based text styling #45

Open BugReporterZ opened 3 months ago

BugReporterZ commented 3 months ago

It can be incredibly helpful for readability, especially in those circumstances where Mikupad is used to hand-craft data for training or in-context learning (which most often needs to be formatted in a specific or at least in a consistent way) to have some form of syntax highlighting, in a way similar to what SillyTavern does for dialogue and actions. However, given the free-form nature of text completion, it would be useful if customizable rules could be used instead of fixed ones.

To make UI implementation simpler, every Mikupad theme could come bundled a number of predefined "style classes" (designed to work properly with the theme and affecting things like back/foreground color, bold/italic/underline or even size, etc), and the custom regex matches could then be associated with them.

As a demonstration of the general idea, below is an example of a short chat-like formatted text with various portions styled for easy recognition. The styled example is from a text editor with syntax highlighting (+ additional image editing).

image

phuvo commented 2 months ago

I've managed to get syntax highlighting works on my local machine, using https://github.com/WebReflection/highlighted-code, which uses https://highlightjs.org to highlight the text as Markdown. It's all I need at the moment.

To make your idea works using the library above, we need to implement the UI, code to transform the regex's to a highlight.js language, and the styles to highlight.js theme. It's a big task, and I'm not sure if most people will need custom highlighting, or if they just simply need Markdown.

Edit: not as difficult as I initially thought, expect to have a PR in a next few weeks.