Upload relative-path images to Canvas and modify html accordingly.
Source:R/canvas.R
canvas_move_images.Rd
Example:
Value
Modified doc object, also overwritten on disk, with absolute remote src urls to Canvas in place of relative ones.
Details
Assume doc.html contains
After canvas_move_images(html), doc.html contains the following, where image identifiers have been assigned by Canvas.
img src="https://example.instructure.com/courses/1234/files/5678/preview" img src="https://example.instructure.com/courses/1234/files/9012/preview" img src="https://example.instructure.com/courses/1234/files/3456/preview"
The xml_document is scanned for src urls that are relative (i.e. don't start with http, and are not data URIs), and those urls are replaced with the output of canvas_upload_image().
Examples
if (FALSE) { # \dontrun{
dtemp <- tempdir()
ftemp <- file.path(dtemp, "æøå.html")
src <- "a/fileæøå.jpg"
file.path(dtemp, src) |> dirname() |> dir.create(showWarnings = FALSE, recursive = TRUE)
writeLines("test", file.path(dtemp, src))
writeLines('<html><body><img src="a/fileæøå.jpg"></body></html>', ftemp)
canvas_move_images(ftemp)
# {html_document}
# <html>
# [1] <body><img src="https://example.instructure.com/courses/1234/files/5678/preview"></body>
file.remove(ftemp)
file.remove(file.path(dtemp, src))
} # }