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?

Thanks

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.

2 Likes

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

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

Edit: And thanks for your help!

2 Likes