How to Manipulate Only the Text Within Cloze Deletions?

Hey everyone,

I’m looking to manipulate/extract only the text contained within cloze deletions in my cards.

For example, in a card with the sentence: ‘‘Hast du {{c1::eigentlich}} Hobbies?’’, I want to target and extract only the word “eigentlich” without affecting the rest of the sentence.

With that, I want to create a TTS audio only with the word, but what I am getting is blank or . (punkt)

Are you only wanting to “manipulate/extract” the word just for the purpose of TTS reading it? Or are you also wanting to use it for something else?

If it’s just for TTS, that’s what the cloze-only filter is intended for. Field Replacements - Anki Manual

If it’s for some other prupose – can you explain what you’re wanting to do with it? That will help folks think of possibilities for you.


On the front card cloze-only says blank or point.
That’s why I wanted to could get the text inside the c1:: and turn it on an audio with TTS.

You should post the actual text of your template here.

As you can see I used cloze-only, but only says “blank”.


{{tts de_DE voices=Apple_Anna_(Premium):cloze-only:Text}}


var currentCloze = document.querySelectorAll(".cloze");

// Hide the original cloze elements and create input boxes
for (i = 0; i < currentCloze.length; i++) {
  currentCloze[i].style.display = "none";
  const input = document.createElement("input");
  input.type = "text";

  currentCloze[i].insertAdjacentElement("afterend", input);

var ctb = document.querySelectorAll('.custom_typebox');

// Iterate through custom_typebox elements to set placeholders and adjust widths
for (j = 0; j < ctb.length; j++) {
  var text = document.getElementsByClassName('cloze')[j].innerText; 
  var result = text.replace("[...]", "");
  var final_result = result.slice(1,-1);
  ctb[j].placeholder = final_result;
// Create a hidden element to calculate the actual width of the placeholder
  var hiddenElement = document.createElement('span');
  hiddenElement.innerText = final_result; = 'hidden'; = 'pre'; // Preserve white spaces

// Insert the hidden element into the page and use it to calculate the actual width of the placeholder
  var placeholderWidth = hiddenElement.getBoundingClientRect().width;

// Remove the hidden element from the page

// Set the width of the input field
  ctb[j].style.width = placeholderWidth + 9 + "px";

Are you using Desktop, Droid, or Mobile – and what version?

Mobile: 23.12.1 and Desktop: Version ⁨23.12.1 (1a1d4d54)⁩

The issue I was thinking of would be Droid-specific. But now that you’ve posted your template, hopefully someone else can take a look and see if there are any issues.

cloze-only only works on the front template.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.