Getting plain text into Anki: a saga

I’ve used Anki for many years as a core piece of my language learning. I love it.

With the version 2.1 upgrade, I’ve had to spend more and more time finding ways to work around its quirks. The following issue is particularly thorny and support inquiries have been met with a version of “that’s just the way it is.”

My issue is in how Anki 2.1 decides whether you want HTML or plain text in the receiving field when cut-and-pasting from a website. Let’s say I want to snag part of the English definition from the Wikitionary article for the Russian word таи́ться . So I highlight “to conceal/hide one’s feelings (from)” on the page, ⌘-C to copy. In Anki, ⌘V to paste. Visually, it looks fine in the editor window, other than the unwanted italic text:

so let’s take a look at the HTML (⇧⌘X):

It’s a mess. All I want is the plain text. Where do all of the   elements come from? It must have been on the original page. So let’s look at the source:

<li>to <a href="/wiki/conceal" title="conceal">conceal</a>/<a href="/wiki/hide" title="hide">hide</a> <a href="/wiki/one" title="one">one</a>'s <a href="/wiki/feeling" title="feeling">feelings</a> <i>(from)</i>

Meh, there’s a lot markup but no   Either Anki or macOS is adding these unwanted non-breaking spaces. Since I’ve never seen that behaviour anywhere but Anki, I’m blaming Anki. The problems I have with this are both philosophical and practical.

  • Since Anki provides extensive capabilities to format your cards, why force users to accept Anki’s space to non-breaking space conventions? If you want something to align in a certain way, do it yourself. Why assume that every user wants it that way.
  • The practical issue is that the non-breaking spaces force words to break in strange ways at certain window widths.

Desperate for a solution (short of coding a full Anki Add-on) here’s what I came up. I assume that Anki is looking to see if there’s some HTML on the clipboard. If there is, it changes all the spaces to   elements. So, what if I just scrapped the HTML from the clipboard before it gets to Anki? AppleScript to the rescue.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

property paste : 9

delay 0.25
tell application "Anki"
   activate
   delay 0.25
   my pasteWithDelay(the clipboard)
end tell

on pasteWithDelay(someText)
   set the clipboard to {text:(someText as string), Unicode text:someText}
   tell application "System Events"
      key code paste using command down
      delay 0.25
   end tell
end pasteWithDelay

Now the remaining problem is how to launch the script easily. Here, I just added a Quicksilver trigger. So the key combination ⇧⌘W now takes the clipboard, turns it into plain text and uses UI automation to paste it into the field that currently has the focus. It works, but I’m left with the feeling that I’m missing a better way…

EDIT 2022-06-02: I’ve since come up with a variation on this approach which I’ve written about in Getting plaintext into Anki fields on macOS: An update.

L-R method for language learning

L-R method for language learning

I’ve recently discovered the L-R system of language learning and have been setting up to learn it.

The idea is that you begin with long texts - novels, for example - in your target language (L2) and follow a systematic approach to reading and listening.

L-R system in a nutshell

Here are the steps:

  1. Read the text in L1 (your native language) and become familiar with it.^[I rephrased this intruction from other sources that say “read the translation” because what if the text itself if a translation? For example, my first text to try this with is Гарри Поттер и философский камень which was originally written in English and then translated into Russian, among other languages. So, it’s best to say for the first step “Read the text in your L1 and become very very familiar with what it says.”]
  2. Listen to the recording and simultaneously read the text in L2.
  3. Listen to the recording while reading the text in L1.
  4. Repeat after the speaker. But only do this once you truly understand the meaning of what you’re repeating. The goal is meaning, not only pronunciation.
  5. Translate the text from L1 to L2 by covereing up one side while reading the other.

Tips

It is hard, very hard in fact, to find parallel texts. Even if you can find .txt documents online, the formatting is a challenge. Columns in Word or Pages simply don’t work, because the L2 and L1 doesn’t line up properly. So here’s what I did for formatting Harry Potter and the Philosopher’s Stone^[Before you accuse me of intellectual property theft, I will mention that I own both the Russian translation and the English language original in book form. So no harm done to anyone.]: