ijgnd / anki__editor__apply__font_color__background_color__custom_class__custom_style Goto Github PK
View Code? Open in Web Editor NEWLicense: Other
License: Other
I want to leave a suggestion, which in my view will be quite simple and useful.
I have many options to solve the problem, such as fixing the letter in the color I want. But this is not practical.
You could create an option to add a different color to the nightmode, along with the backcolor.
I thought on two occasions:
color: initial;
. This will set the default color in light mode, even in night mode. Preventing the color inversion of the letter.I currently use the following configuration:
Background-color: yellow; color: initial; display: inline;
with the following result:
thanks.
I'm an avid user of your addon, and wondered whether you would add support for wrapping a selection with raw text, rather than a tag. An example:
Capital of Italy is Rome
You select the text "Rome". Then you press a shortcut defined in the Config dialog, and you end up with:
Capital of Italy is {{c1::Rome}}
Of course this would just recreate the cloze shortcut, however the difference would be that it is configurable.
My use case is specifically my add-on Set Randomizer. I'm sure users would find other users.
I've been thinking about implementing it on my own for some time now, but it kinda exceeds the scope that I originally envisioned, and I think it would much better fit into this add-on.
I would write a pull request if it's okay with you.
I attached a zip file which contains a video of me screen recording the bug and a screenshot of my configs in case you need to see it.
Essentially the bug happens when I try highlighting text and then use the hotkey that I preset for a certain text styling and what happens is that it does the styling on other non-highlighted text which is very annoying!
This use to never happen at all. But I believe after one of these recent updates the bug appeared!
Thank you again for making such an awesome add on! I love using it! I also posted this on the anki thread forum/help thing.
the add-on now uses the gui_hook main_window_did_init
which was introduced on 2020-05-28 and released with 2.1.28.
source: reddit post
Error
An error occurred. Please start Anki while holding down the shift key, which will temporarily disable the add-ons you have installed.
If the issue only occurs when add-ons are enabled, please use the Tools > Add-ons menu item to disable some add-ons and restart Anki, repeating until you discover the add-on that is causing the problem.
When you've discovered the add-on that is causing the problem, please report the issue on the add-on support site.
Debug info:
Anki 2.1.26 (70784154) Python 3.8.0 Qt 5.14.1 PyQt 5.14.1
Platform: Windows 7
Flags: frz=True ao=True sv=2
Add-ons, last update check: 2020-06-09 23:00:34
Caught exception:
Traceback (most recent call last):
File "C:\Users\Ronil Patel\AppData\Roaming\Anki2\addons21\1899278645\confdialog_MAIN.py", line 118, in accept
if a.exec_():
AttributeError: 'NoneType' object has no attribute 'exec_'
The config for the add-on pops up every time I click on Anki Preferences.
I have tried this on both of my computers.
Below is a video of the problem.
I recently noticed a bug when updating your _editor_button_styles.css
. It seems like Anki doesn't recognize that the file was updated, and won't upload it to AnkiWeb, which means the file won't be updated on AnkiMobile (and possible AnkiDroid).
With 2.0 this behavior could be fixed with an app like this: https://ankiweb.net/shared/info/162278717. However it doesn't work on 2.1. I'm sure this could be replicated in 2.1.
The option in the dialog is named "Restore default config" but at the moment this only affects what's in the active and inactive table, see this line.
So what's in the "General config" tab (cb_global_contextmenu_show, remove_formatting_shortcut, multi_button_shortcut) is not reset at the moment.
I've just downloaded this add on and noticed this little bug when I wanted to disable the default styles in the options window. When multiple lines are selected it only disables the entry that was clicked on last, e. g. when I select lines 3 to 5 by first clicking on 3 and then on 5 (with Shift hold) it only disables line 5, if I select them the other way round it only disables line 3.
No big issue but I thought I mention it.
I tested the default shorcuts with the binary for 2.1.30 from apps.ankiweb.net in Linux without any other add-ons.
The following default shortcuts work in 2.1.26 but not in 2.1.30 for me:
I have no idea these don't work anymore, as far as I see there were no changes in the Anki source code (i.e. in editor.py and addcards.py) that could have this effect.
So I tried to change the font-style but unfortunately I didn't find anything in the styling sections in which I can change that. And adding stuff like "font-style" oder family in the .card section does not change anything.
What am I doing wrong?
I received the following bug when trying to change the hotkey for font size to 130%
Debug info:
Anki 2.1.26 (70784154) Python 3.8.0 Qt 5.14.1 PyQt 5.14.1
Platform: Windows 7
Flags: frz=True ao=True sv=2
Add-ons, last update check: 2020-05-30 04:08:38
Caught exception:
Traceback (most recent call last):
File "C:\Users\Ronil Patel\AppData\Roaming\Anki2\addons21\1899278645\confdialog_Fontsize.py", line 62, in accept
"Text_in_menu_styling": self.return_font_size(),
File "C:\Users\Ronil Patel\AppData\Roaming\Anki2\addons21\1899278645\confdialog_Fontsize.py", line 53, in return_font_size
return font.rstrip(";").lstrip("font-size:")
AttributeError: 'tuple' object has no attribute 'rstrip'
Error
An error occurred. Please start Anki while holding down the shift key, which will temporarily disable the add-ons you have installed.
If the issue only occurs when add-ons are enabled, please use the Tools > Add-ons menu item to disable some add-ons and restart Anki, repeating until you discover the add-on that is causing the problem.
When you've discovered the add-on that is causing the problem, please report the issue on the add-on support site.
Debug info:
Anki 2.1.50 (81cc5a09) Python 3.10.1 Qt 5.15.2 PyQt 5.15.6
Platform: Linux
Flags: frz=False ao=True sv=2
Add-ons, last update check: 2022-01-20 21:36:13
Add-ons possibly involved: editor: apply font color, background color, custom class, custom style
Caught exception:
Traceback (most recent call last):
File "/usr/lib/python3.10/site-packages/aqt/main.py", line 336, in onOpenProfile
self.loadProfile(self.profileDiag.closeWithoutQuitting)
File "/usr/lib/python3.10/site-packages/aqt/main.py", line 462, in loadProfile
gui_hooks.profile_did_open()
File "/usr/lib/python3.10/site-packages/aqt/hooks_gen.py", line 3077, in call
anki.hooks.runHook("profileLoaded")
File "/usr/lib/python3.10/site-packages/anki/hooks.py", line 34, in runHook
func(*args)
File "/home/grim/.local/share/Anki2/addons21/1899278645/color_style_class_buttons.py", line 230, in prepareEditorStylesheet
editor._html = editor_style + editor._html
AttributeError: module 'aqt.editor' has no attribute '_html'
I think there is a bug in the "Backcolor (via class)" and "class" categories.
Sometimes they work applying "class=..." inside the tag. E.g.: .
But other times, especially when we do not select the entire paragraph, it just apply the styling which has been configured to the class (and is on the _editor_button_styles.css file. E.g. .
Why does it happen?
I wonder what is the background of this method call?
I couldn't find anything about this method. For me, the method call will always fail, in both the Ankiweb version and the version on GitHub.
In the newest version (that's also on AnkiWeb), when I try to open the Anki Preferences, I instead get the config window for this addon.
I cannot say, whether the same happens on other platforms though.
I recently got a new computer and had to re-download anki as well as the add-on. In my old computer I had used the add-on extensively and made so many edits on cards using the shortcuts I made. However, I noticed immediately that since I got this new laptop that all the edits are gone (about ~5 to 10% are still there but very rarely). I downloaded everything on the new computer and then synced it. I then synced it to my phone and noticed they were also gone there as well. Is there any way to fix this?
If it helps-
The old computer (which is currently getting fixed) may have had an older version of Anki. I believe it was 2.1.31 and it was up to date as of 9/9/20 for the add-on updates. Could this be why? That's the only reason I see it failing. Of course, since I got this new computer this version is 2.1.33.
Hi,
we've already talked about this some time ago, are you still up for it?
I see the need for several fixes, and I don't want to force the whole uploading to you every single time, especially if I introduce stupid subtle bugs.
If yes, I would post the request on the Anki forum itself.
Hello, I have lots of hotkeys set up for this add-on, like alt+d or alt+r. They no longer work, probably since I updated to 2.1.30 (not sure).
I tried different combinations and can't get it to work. The multi-button hotkey still works though.
Platform: MacOS
I was migrating to this addon from the "Wrapper meta-addon" and "editor wrap selected text with custom HTML" addons, and I encountered a possible bug when I tried to make a Text Wrapping function with the Wrap Before string being <div style="font-size: 0px;">{{c1::.
and After string being }}</div>
.
The addon works as expected when I use the shortcut, but if I switch on the "show extra button" option, it displays like so:
Steps to reproduce:
Upon clicking the button or using the
The error message is:
Error
An error occurred. Please start Anki while holding down the shift key, which will temporarily disable the add-ons you have installed.
If the issue only occurs when add-ons are enabled, please use the Tools>Add-ons menu item to disable some add-ons and restart Anki, repeat until you discover the add-on that is causing the problem.
When you've discovered the add-on that is causing the problem, please report the issue on the add-ons section of our support site.
Debug info:
Anki 2.1.33 (3f403040) Python 3.8.0 Qt 5.14.1 PyQt 5.14.1
Platform: Windows 10
Flags: frz=True ao=True sv=2
Add-ons, last update check: 2021-04-17 00:42:28
Caught exception:
Traceback (most recent call last):
File "aqt\webview.py", line 37, in cmd
File "aqt\webview.py", line 123, in _onCmd
File "aqt\webview.py", line 547, in _onBridgeCmd
File "<D:\Programs\Anki\decorator.pyc:decorator-gen-64>", line 2, in onBridgeCmd
File "anki\hooks.py", line 638, in decorator_wrapper
File "anki\hooks.py", line 635, in repl
File "D:\Data Storage\AnkiData\addons21\516643804\main.py", line 135, in onBridge
return _old(self, str)
File "aqt\editor.py", line 416, in onBridgeCmd
File "D:\Data Storage\AnkiData\addons21\1899278645\editor\shortcuts_buttons.py", line 49, in <lambda>
function = lambda e=editor, c=e["Setting"]: func(e, c)
File "D:\Data Storage\AnkiData\addons21\1899278645\editor\editor_apply_categories.py", line 27, in my_wrap_helper
before, after = beforeAfter.split(unique_string)
ValueError: not enough values to unpack (expected 2, got 1)
The wrapping function works well with strings that do not contain quotation marks.
I can get around the issue by simply not having a gui button in the add dialog and relying on the shortcut, so it's not really an inconvenience for now, but thought it better to inform you about it anyway.
Something that bothered me for sometime, is the name of this add-on.
I wonder how you think about renaming it a little bit succinctly.
For example take the beginning, and the end, and go with "Editor Apply Custom Styles".
This way "custom styles" can include all the other things mentioned (font color, custom class, etc.).
I like descriptive names, but to this day my brain refuses to memorize the name of this add-on ^^;
a recent review had:
Wish can have full CSS support for custom class. For example, I could use something like .myclass:before {content: "xxx"}
I'd like to have an option to disable the dialog that asks if I want to update all my templates.
I understand that it is required for the add on to fully work, but I don't want to use it on all my note types, so I'd rather add the import manually to the note types where I need it.
In case you don't want such an option because people might activate it without knowing what it does, is there an easy (preferably permanent) way to disable the dialog in the source files?
This add-on allows to define alternative styling for the night mode. So css like this is set by this add-on while Anki is in night mode
.myclassname{
background-color: #... !important;
}
.nightMode .myclassname{
background-color: #... !important;
}
The css for the nightmode works in the reviewer and previewer but since 2.1.41 no longer in the editor.
I tested with the binaries for .41 and .42 for linux from apps.ankiweb.net with the most recent version of the "custom styles" add-on from ankiweb (from 2021-03-03). During this test I had no other add-ons installed.
I have no idea what to do at the moment. I hope that you'll have time to look into this.
Thanks.
Would it be difficult to implement a feature so that you could wrap text with customised HTML.
one interesting use would be quickly making expandable lists:
<details><summary>Expand/collapse me!</summary>sample text to be wrapped</details>
to give something like this
I thought just standard text wrapping should work but when I try it, it removes the text between </summary>
and </details>
############## forms 里面没有settings_main_widgets ##########
from .forms import settings_main_widgets
from .addEntry import AddEntry
from .utils import gui_dialog
class MainConfDialog(QDialog):
def init(self, c):
parent = mw.app.activeWindow()
QDialog.init(self, parent)
self.config = c
self.bo = settings_main_widgets.Ui_Dialog()
Is there any way that one can make the red box smaller and not over the whole flashcard width?
MacOS
Anki 2.1.49
Thank you for your addon, it's very easy to add format。
After installing the addon, I formatted the text but couldn't clean it up.
When I pressed F2
, I clicked on the option Clear More Formatting
but it didn't work.
Pressing Alt + R
doesn't work either.
I tried to disable all addons but this one, but it still didn't work
Trying to activate a wrap of type "class (other)" triggers an exception.
This is on the version from 2020-05-14.
Caught exception:
Traceback (most recent call last):
File "/Users/hgiesel/.local/share/AnkiDev/addons21/1899278645/menu.py", line 126, in <lambda>
x.triggered.connect(lambda _, a=cat, b=se: my_highlight_helper(editor, a, b))
File "/Users/hgiesel/.local/share/AnkiDev/addons21/1899278645/menu.py", line 35, in my_highlight_helper
func(editor, setting)
File "/Users/hgiesel/.local/share/AnkiDev/addons21/1899278645/editor_apply_styling_functions.py", line 115, in my_apply_span_class
if e["Category"] == "class (other)" and e["Setting"] == _class and e["surround_with_div_tag"]:
KeyError: 'surround_with_div_tag'
I can no longer apply classes to selected text: the html source code of the field is unchanged.
I tried without any other add-ons, the custom styles version I used was the latest commit from this repo. It worked in 2.1.40. I think the problems is the javascript code used in the add-on.
@hgiesel: Since you know js and made some changes to the editor in 2.1.41 maybe you could have a look at this? Thanks.
I don't want to bother you with something unimportant for most people, so I consider this a very humble suggestion.
In this add-on, as coded in the file css_for_webviews.py
, all the css colors are added with the "!important" tag. Managing various styles, and especially in face of the need of different settings for nightmode colors, sometimes this "!important" tag, that fundamentally changes the way that page's CSS is processed, prevents me from, for example, setting in another CSS file (or styling section of the card) that the "fg_red" class (red font) will not be red when it is inserted in a blue box (div section with an specific class applied), for example. This may be annoying sometimes, and I didn't realize yet the need for this "!important" being added in the CSS file. Personally, I always alter that css_for_webviews.py
, removing the 5 "!important" that there are in that file. And I would suggest you, if it is not that relevant, not to add this "!important".
First mentioned here.
Love the add-on. This is just an idea for anyone who may want to have a simpler context menu.
contextmenu.py
from aqt.gui_hooks import editor_will_show_context_menu
from aqt.qt import *
from aqt.editor import Editor
from ..config_var import getconfig
from ..colors import hex_to_rgb_string
from .rangy_helpers import classes_addon_rangy_remove_all
from .apply_categories import apply_categories
def my_highlight_helper(view, category, setting):
func = apply_categories[category]
func(view.editor, setting)
def create_menu_entry(view, e, menu):
textInMenu = e["Text_in_menu"]
cat = e["Category"]
se = e.get("Setting", e.get("Category", False))
x = menu.addAction(textInMenu)
x.triggered.connect(lambda _, a=cat, b=se: my_highlight_helper(view, a, b)) # ???
return x
def setup_contextmenu(view, menu):
config = getconfig()
if config.get("v2_show_in_contextmenu", False):
return
menu.addSeparator()
a = menu.addAction("Clear formatting")
a.triggered.connect(lambda _: classes_addon_rangy_remove_all(view.editor))
for row in config['v3']:
if row.get('Show_in_menu', True):
menu.addAction(create_menu_entry(view, row, menu))
menu.addSeparator()
In text wrapper, a placeholder for text under selection would be nice
For eg: "Hello there %s, How are you today %s
" when applied while having "Robert" under selection, you get Hello there Robert, How are you today Robert
I noticed this already in a previous Anki version, even though I couldn't exactly tell which one.
In the Editor webview, it says:
Failed to load resource rangy-core.js: the server responded with a status of 403 (FORBIDDEN)
I will try to look at this myself, and make some general improvement PRs at the same time.
hi,
Is there any way we can change the name of the "class", for example, from <div class="red_box">
to <div class="test">
, and that changes in all cards already made?
Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.