Add Table [Official thread]

@ak47: I can’t really help with this. I would look at other add-ons or card type templates that offer multiple choice like functionality, e.g.

maybe make a new topic in the add-on or development category of this forum so that you get more visibility.

@ijgnd , Like I told you that I am myself a web developer. I can do this functionality myself once I get proper understanding of how Anki and it’s add-ons work. Since I have not contributed to an open source project like this I am finding it difficult to start. Just guide me on how to start and which all documentations to refer to save time.

You don’t really need any open source experience to start developing add-ons.
You can just duplicate the folder of an arbitrary add-on (within addons21) as a starting point for your own stuff.

Like @ijgnd said, Closet for Anki covers a broad range of functionality and its source code is a great reference for best practices of add-on development (also for the JavaScript part).

There’s also an official guide (explains the use of hooks, collection operations etc.): Introduction - Writing Anki Add-ons

And I consider AnkiWebView Inspector - AnkiWeb essential for my personal add-on development.

@ak47: Since I don’t really understand what you want from me there’s a good chance that you won’t like this link either: https://www.reddit.com/r/Anki/comments/bae3yx/building_addons_without_reading_all_the_source/ekazvjd/ Hopefully there’s something useful for you. Some people said that found this collection useful.

2 Likes

When I create a table and then copy and paste it into another field so that I don’t have to retype all the headings, the table gets bigger. I know this is a minor thing, but when I have two variations of the same table on the same card, the tables aren’t the same size. Even the text isn’t the same size between the two tables, even though the styling part of the card template doesn’t contain anything that should change the size of the text. Any suggestions?

Thanks!

@Annapox: Anki is very flexible so a problem can be introduced in many different places. Do you see the review just when you are reviewing cards or do you also see this in the editor when you make a new note (or check it at the bottom of the browser)? If it’s just during reviews check your card styling in your card templates - there are some good youtube videos on this …

If it’s about the editor in the add/browser window: try without add-ons and check the font size you set for each field (that you see when you click the fields button in the upper left of the editor).

Ultimately you can check the html source code of both tables: in the editor put the cursor in a field and press ctrl+shift+x to see it (on macs it’s cmd+shift+x). Then compare the source code for both fields if there’s a difference. If there’s no difference it’s not about my add-on. Then at some place else different styling gets applie (most liekly cause for reviews it’s somewhere in the card templates).

The difference does also show up in the editor. I don’t see anything in the card styling or the editor settings that would cause the two tables to be different, but I did find a difference in the HTML code.

The original table starts with:

The copy starts with:

So now I know how to get all the tables looking the same, but any ideas how that would have happened in the first place? I haven’t messed with any of the code for the tables or for the add-on itself.

you didn’t post the html source code.

try this: cut a table from a field and paste it into it. Does this change the table? When you paste something into anki anki processes it which may slightly change how it looks.

ideally this shouldn’t happen so maybe there’s something in my add-on to fix. But it’s much easier for me if you show me html source code that leads to this problem.

Sorry, I did copy and paste it the code snippets that were different, but I forgot to use the “preformatted text” button. I’m having an off day, I guess. Let’s try this again. The original table starts with:

<table class="table_class_basic_full_width" style="font-size: 85%; width: 100%; border-collapse: collapse; border: 1px solid;">

When I copied and pasted the table into another field, that code changed into:

<table class="table_class_basic_full_width" style="width: 822px; border-collapse: collapse; border: 1px solid;">

So, I can fix it by changing the code so that it matches, but there’s still the question of why that change happens in the first place. For what it’s worth, if I copy and paste the copy of the table, the code of the new copy is identical to the code of the first copy, as far as I can tell.

I see. I’ll look into it in the coming weeks (when I’m less busy at work). In the meantime you could use my editor: paste raw unfiltered full html - AnkiWeb or if you don’t want more add-ons copy the html source from field a into the html source editor of field b - this avoids that anki processes (cleans) the input

Since ~2.1.20 when you copy and paste a table the styling seems to be removed by Anki fully. Annapox has a different problem: when pasting some styling is changed and not removed, e.g. the width is changed from relative to an absolute value. This reminds me of a problem I had with Custom Styles where css got changed to inline styling by chrome’s inserthtml. Maybe something similar goes on here.

The fact that coyping and pasting between fields removes stuff is not that unusual, e.g. only on MS Windows some hyperlinks made by another add-on got removed, see here.

Anyway the solution is the same: avoid the paste command and either copy the source code between fields or have a look at my editor: paste raw unfiltered full html - AnkiWeb.

Hi @ijgnd , quick question: You don’t yet save the configuration of this addon in the user_files-folder, correct? If you don’t, this would probably be a useful addition so we don’t have to recreate our settings after each update. :+1:

@basiskarten: When you update an existing add-on either by checking on ankiweb for updates or by dragging and dropping a ankiaddon file in the add-on dialog your custom config is kept.
That’s my experience and I just looked at the code. This behavior should be due to this:

This line should read the old config (meta.json), then one line later the old folder is deleted and then about 5 lines down the new meta (after updating it with your old config) is written into the newly installed folder.

As far as I see you keep custom versions of your recommended add-ons and install them with a helper add-on of yours. This could be related to losing custom configs on your add-on updates.

2 Likes

Thank you, very cool. :+1:

Do you know if the latest version of the add_table addon also works on older versions of Anki (below 2.1.45)?

I uploaded the same addtable version to ankiweb a week ago for all anki versions. Once you’ve created different versions of an add-on on ankiweb you can’t merge them back. The only thing I know to do is upload the same version multiple times.

The add-on should work with 2.1.15+ (at least with the version on ankiweb that was built with qt 5.12). I’m not sure if it works with much older anki versions or linux distros that rely on much older qt versions.

Since few people actually report bugs maybe you shouldn’t test for yourself (since you’re doing this commercially). But i haven’t gotten any bug reports over the last 8 days.

1 Like

Great. As always: Thank you very much for your time and your effort!

I have such a trouble.
I can’t make a change on fixed or not fixed.
How can I?

Screen Shot 2022-11-15 at 16.05.03

Unfortunately I don’t really understand your problem

At the bottom of your post there’s a screenshot of the dialog my add-on shows. In this there’s a line styling that for you shows “basic - full width”. Change this to “basic - minimal width”. Also make sure that at the bottom of the dialog you check “Save these settings as”. Then insert a table. This should make the add-on remember this setting so that when you transform selected text with markdown table formatting you’ll get a table that’s narrow

Thank you for replying.
Both have the same problem.
I don’t want to make extra spaces.
It won’t fix the width though I turn off “fixed width columns."

You’ve found a limitation that this add-ons has had for more than the last six years (still inherited from the power format pack for anki 2.0)

I added this to my todo list: when converting selection/markdown: don't force the same width for all columns · Issue #16 · ijgnd/anki__editor_add_table · GitHub

I have no idea when I have time for this.

1 Like