Write card HTML to txt file with JavaScript

I want to see how a card is rendered in Anki Mobile (iOS). My idea was to insert some JavaScript into the card template and write the HTML code to a txt file inside the collection.media folder. But I’m not sure how to write to a txt file. Is this even possible?


1 Like

You can’t write to the filesystem, but you can place the debug text you want into a div in the DOM, and view it from there.


It’s not ideal, but it works. Here is the code for anyone interested:

    var htmlContent = document.documentElement.outerHTML
    var container = document.getElementById('htmlCodeContainer')
    container.textContent = htmlContent
<div id="htmlCodeContainer" 
         font-size: small;
         white-space: pre;
         overflow-x: auto;
         background: #f9f9f9;
         border: 1px solid #ddd;
         margin-top: 20px;
         padding: 10px;">

Edit: And thanks for your help!