r/Anki•
RemoteDoc

Parsing every image from field into a javascript array.

Development

My goal is to create a Radiology Anki deck. I am creating the deck template. I want to be able to have several images on a single field, and be able to scroll through them, much like a radiologists would scroll through a CT or MRI. I am using the following HTML / JS for Scrolling Image Stack effect:

https://codepen.io/RemoteDoc/pen/KbKQOB

As you can see, the array of the images are in URL format. My goal is to use images stored in a single field.

I thought I have created a reasonable solution with:

var images10 = ['{{Image1}}'];

images10 = images10.map(function(x){ return x.replace(/[<]img src[=][\"](.*?)[\"]\s\/>/g,"\$1,") });

What the code above does is parse every image from the field: "Image1" into an array called "images10". What the second line does is strip the <img src="..." /> and add a comma (,) (simulating an array): image425.jpg,image426.jpg,image427.jpg (these don't necessarily have to be in numerical order, but in their current order within the field). Using a button alert, I can see that it is pulling the array, but it still does not work as a javascript function with scrolling image stack code. I know there is a better solution for parsing images from a field file names into an array, and just wanted to see if anyone had any ideas.

The goal of this would be to be able to drop 15 images in a single field, and then be able to scroll through them in the order they are in the field (like a CT/MRI).

Thank you in advance for your help.

Posted Dec 9, 2018, 10:28 PM UTC · edited

66
Loading comments…