Hello,
Would you know how to format only a portion of a row as code (i.e. with the Courier font) ? As you know, using the
tags formats the entire row so I was wondering whether there was a workaround.
Thanks!
Hello,
Would you know how to format only a portion of a row as code (i.e. with the Courier font) ? As you know, using the
tags formats the entire row so I was wondering whether there was a workaround.
Thanks!
I think you post is missing a part/piece of it?
You can make a piece/part to the text as Courier New
by using HTML.
Just press Ctrl+Shift+X
while editing a field and add an HTML tag around the text you would like to change the font. For example:
This text has
the <span style="font-family:Courier; color:Blue; font-size:20px;">font
Courier, is Blue, and 20px.</span>
Thank you for your prompt answer. I was hoping to tweak the behaviour of the ācodeā button of the editorā¦ Maybe I will tweak the behaviour of another button that I do not use like Strikethrough. Thanks!
It would be possible to code a simple add-on which inserts HTML around selected text (via hotkey/button) by taking a look at how the MathJax/formatting/etc insertion works.
Given that you are learning how to code, it might seem like a nice challenge to learn to code
I would probably recommend using a style specified in the style of the card, even if it means adjusting all your card types accordingly. Note that you can save custom style files in the media and import them via:
@import url("_style.css");
Aha, you got me on this one!
I second this! I was just about to create a new post but got a suggestion that the topic already exists.
Have you found a fix or an add-on that does this? It should be really easy to fix for someone who knows the plugin system (me myself have never touched it). All we need is a button (or a fewā¦) that allows for custom mark-up, e.g. pressing the button would automatically surround your highlight with any tag of your choosing, in my case I would HAMMER that button so I donāt have to constantly manually write <code>
, which autocompletes to <code></code>
, then Iām forced to cut </code>
and place it after the wordā¦so very tedious.
Please please please, plugin-coders, create this add-on! =)
New Format Pack - AnkiWeb offers a code button.
You can also take a look at Custom Styles (font color, background colour, classes) - AnkiWeb, which allows you to surround text with anything you like and also set custom shortcuts.
Thanks for suggestions!
But the āNew Format Packā seems to only have the code block button, something which is already included in the āMini Format Packā, at least for me. I want to wrap inline text, e.g. a single word.
I think Iāll pass on your second tip, the instructions are filled with, "scary warning"s. Itās not worth it for the simple thing I want. It seems I have to create my own add-on, to be continuedā¦
Those are mostly unwarranted I guess the @ijgnd had some bad experiences with non-tech-savy users and felt the need to fend them off. Itās a really useful add-on, but admittedly overkill for your use case.
If youāre ready to write your own add-on, you might as well use New Format Pack as template and tweak it to insert an inline code
element. Let me know if you need help with that.
Right after my answer I actually did a quick research into the Anki plugin system. I opened the main.py for the āMini Format Packā and took the naĆÆve approach of modifying
editor.web.eval("setFormat('strikeThrough')")
into
editor.web.eval("setFormat('code')")
It didnāt work, I assume ācodeā is not a built-in function. But then I googled āanki formatblockā, because thatās whatās used when applying the <pre></pre>
wrap. I found the code for āMini Format Packā on Github and thereās actually a function called
def formatInlineCode(editor):
editor.web.eval("wrap('<code>', '</code>')")
which is missing from my add-on. It seems the add-on is not synced with the lasted version on Github. Donāt know why. Anyway I took the quick fix and just plain replaced the body of my already existing function:
def formatBlockPre(editor):
editor.web.eval("wrap('<code>', '</code>')")
It does exactly what I needā¦Except it adds those extremely annoying
so if I have the word āfloatā, I end up with
<code>float</code>
I know Iām not alone in hating the extra
that gets added everywhere. I manually always remove them and it eats a lot of time. EDIT(I know about the Find & Replace trick, but I canāt use that because sometimes I actually need the
). They are really messing with my formatting. Maybe itās a Qt thing.
I never use the strike-through tag, so one option is to overload the style to mimic a code-tag and donāt modify the add-on, for some reason the strike-through doesnāt add the
. But that seems like a very ugly solution to mess with the markup. But Iām considering it.
To familiarize myself with Svelte and the new editor API, I have created an addon that wraps the selected text with <code>
. It uses range.insertNode()
rather than wrap()
function, so no
is created. Itās a rush job so the quality of the code isnāt very good, but you can give it a try if youād like.
https://github.com/hikaru-y/anki21-addon-format-button-sample/releases/tag/v0.0.1
Awesome, thanks! I will definitely take a look.