Skip to contents

See ?wiseflow_images for a user-friendlier version.

Usage

move_images(html, url_prefix, remote_dir = NULL, clean = TRUE)

Arguments

html

Path of HTML file to be modified, e.g. c:/temp/doc.html

url_prefix

URL to root path on server, e.g. https://example.org/~user/doc

remote_dir

Optional scp destination path, e.g. user@server.example.org:~/public_html/doc

clean

Recursively delete supporting files generated when knitting?

Value

Modified doc object, also overwritten on disk, with absolute remote src urls in place of relative ones.

Details

Example:

Assume html = "c:/path/doc.html" url_prefix = "https://example.org/~user/doc" remote_dir = "user@server.example.org:~/public_html/doc" and that doc.html contains

<img src="a.jpg">

<img src="b/c.jpg">

<img src="doc_files/figure-html/img-1.png">

After move_images(html, url_prefix, remote_dir), doc.html contains the following, where HASH1 and HASH2 are strings derived from the html path and system time, to avoid image name clashes for images from unnamed or identically named chunks, or for multiple realizations of Rmd files using random variables.

img src="https://example.org/~user/doc/HASH1/HASH2/a.jpg"

img src="https://example.org/~user/doc/HASH1/HASH2/b/c.jpg"

img src="https://example.org/~user/doc/HASH1/HASH2/_fig/img-1.jpg"

and, if remote_dir is not NULL, server.example.org contains

~user/public_html/doc/HASH1/HASH2/a.jpg

~user/public_html/doc/HASH1/HASH2/b/c.jpg

~user/public_html/doc/HASH1/HASH2/_fig/img-1.jpg

If clean=TRUE, the directory c:/path/doc_files/* is recursively deleted. Set this to FALSE if you need to manually copy files instead of having move_images() call ssh and scp.

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 absolute ones under url_prefix.

The src images will be copied using scp to remote_dir if that is set.

Otherwise you'll want to manually copy the local images to the remote server.

Note: Upgrading to OpenSSH_for_Windows_8.1p1, LibreSSL 2.9.2 fixed issues with GetConsoleMode on STD_INPUT_HANDLE failed with 6 as suggested here: https://gitlab.com/gitlab-org/gitlab-runner/-/issues/4540#note_196938343