Figures from notebook outputs with link to img file #114
-
I have a notebook with a complex image output. It would be nice to make the image be link so that a mobile user could click to see the image. I know that normal figures are links. Normal output from notebooks do not have links. I tried using |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
I wrote some javascript that can be included. Maybe this will help someone else. Seems important on mobile especially. Put the code below in function insert_anchor(element) {
if (element.parentElement.tagName !== 'A') {
let new_a = document.createElement('a')
new_a.href = element.getAttribute('src')
let p = element.parentElement
element.parentElement.removeChild(element)
new_a.appendChild(element)
p.appendChild(new_a)
}
}
function add_img_anchors() {
let figs = document.querySelectorAll(".figure img")
figs.forEach(insert_anchor)
let cell_outputs = document.querySelectorAll(".cell_output img")
cell_outputs.forEach(insert_anchor)
}
window.addEventListener('load', **add_img_anchors)** |
Beta Was this translation helpful? Give feedback.
-
New in v0.8.0 see https://jupyterbook.org/content/figures.html#markdown-figures 😄 |
Beta Was this translation helpful? Give feedback.
New in v0.8.0 see https://jupyterbook.org/content/figures.html#markdown-figures 😄