I would like to create a custom mark for the writer field to insert Remix Icons into the text. The idea is to apply the mark to some text, for example, ri-arrow-up-line, and have Writer save it as:
I used the Kirby Reference as a template and tried to adapt the commands() from the default marks. However, no matter what I tried, either the code isn’t saved or the custom mark doesn’t appear at all.
Unfortunately I only know how to add an element around the selected text. What you want is to insert an icon without selecting the text? I am clueless how to do that myself. Perhaps have a read of the Prose documentation as that’s the underlying library used by the Writer field.
What you want is to insert an icon without selecting the text?
No, I want to select a text, for example „ri-arrow-up-line“, then click on the mark (since Remix Icon uses the <i> tag, the text will be in italic in the editor), and then I want the writer field to save the text like this:
The problem is that I don’t know how to transfer the selected text to this code correctly.
Why a <span> inside the <i>?
Remix Icon uses this markup:
<i class="ri-arrow-up-line"></i>
So the reason for the <span> inside the <i> is that you can still read the text in the editor. In the frontend the <span> will be set to display: none;
@saschabregenhorn I solved it with a simple plugin. However, I use FontAwesome icons. But the concept can easily be adapted for Remix icons. This is my solution:
Thanks for your help! Yes, this adds the <span> inside the <i>. Still, my main problem is that I don’t know how to correctly transfer the selected text to the saved code. ‘ri-arrow-up-line’ is just an example.
Did the icon even appear in the toolbar?
Yes. You’re right, the return statements don’t need semicolons.
I see. I think best to use the code provided by @GB_DESIGN. Unfortunately (and I just tested it) using the selected text as the class name is way too buggy that it’s not reliable. Someone else with more experience might have been able to get it to work though