Get, prepare, and check toots
get_prep_check_toots.Rd
This is a convenience function to prepare a toto_df
ready to preview
or post. It simply calls split_to_toots()
,
append_thread_counter()
,
prep_and_check_toot_df()
,
preview_toot_df()
in that order, shows the preview in the
viewer, and returns the resulting data frame invisibly.
Usage
get_prep_check_toots(
x,
postsPath = NULL,
fragmentsToSkip = getOption("quartodon_fragmentsToSkip", 1),
tootSeparator = getOption("quartodon_tootSeparator", "^-----\\s*$"),
preprocess = getOption("quartodon_preprocess", list(c("^#.*", ""), c("`", ""))),
imgRegex = getOption("quartodon_imgRegex",
"^!\\[([^\\]]*)\\]\\(([^\\)]*)\\)\\{?([^}]*)\\}?$"),
imgAltRegex = getOption("quartodon_imgAltRegex", "fig-alt=\"([^\"]*)\""),
urlRegex = getOption("quartodon_urlRegex",
"(?!\\!)\\[([^\\]]*)\\]\\(([^\\)]*)\\)\\{?([^}]*)\\}?"),
cleanWhitespace = getOption("quartodon_urlRegex", TRUE),
sep = getOption("quartodon_counter_sep", "\n\n"),
prefix = getOption("quartodon_counter_prefix", "🧵"),
delim = getOption("quartodon_counter_delim", "/"),
suffix = getOption("quartodon_counter_suffix", ""),
instance = getOption("quartodon_instance", NULL),
minAltLength = getOption("quartodon_minAltLength", 10),
max_characters = getOption("quartodon_max_characters", 500),
characters_reserved_per_url = getOption("quartodon_characters_reserved_per_url", 23),
image_size_limit = getOption("image_size_limit", 8 * 1024 * 1024),
stopOnErrors = getOption("stopOnErrors", TRUE),
tokenname = getOption("quartodon_tokenname", "RTOOT_DEFAULT_TOKEN"),
select = NULL,
filename = tempfile(pattern = "quartodon_preview", fileext = ".html"),
encoding = getOption("quartodon_encoding", "UTF-8")
)
Arguments
- x
The plain text file as a character vector.
- postsPath
The path to the posts that were processed to produce the
toot_df
provided asx
.- fragmentsToSkip
The number of fragments to skip when reading the text file (Quarto post, R Markdown file, etc). By default, the first fragment (i.e. the lines preceding the toot separator specified in
tootSeparator
, by default the first five dashes,-----
) will be skipped.- tootSeparator
The separator that is used to split the file into toots: matched against every line (i.e. element of the character vector).
- preprocess
A list of 2-element vectors specifying the preprocessing to perform on each extracted toot. These two argument are the first two arguments to a call to
gsub()
, with the toot as the third argument, andperl = TRUE
.- imgRegex
The regular expression used to find images. It should have one capturing group that extracts the path to the image.
- imgAltRegex
The regular expression used to find the images' alt text; it should have one capturing group that extracts the alt text.
- urlRegex
The regular expression used to find hyperlinks. It should have one capturing group that extracts the title (not the URL).
- cleanWhitespace
Whether to clean white space. If
TRUE
, all newline characters (\n
) are stripped from the beginning and end of each toot, and all sequences of more than two newline characters are replaced with exactly two newline characters.- sep
The character(s) to insert between the original toot and the thread counter.
- prefix
The prefix to insert before the thread counter.
- delim
The character(s) to insert in between the number of the current toot and the total number of toots.
- suffix
The character(s) to insert after the thread counter.
- instance
Optionally, the instance where you want to toot to. If provided, its API is called to get its policies, which are then used to override the default values of
max_characters
,characters_reserved_per_url
, andimage_size_limit
. If not specified, but if a valid token is stored in the environment variable specified byrokenname
, the instance is taken from that token.- minAltLength
The minimum length of alt texts for the images.
- max_characters
The maximum number of characters for a toot.
- characters_reserved_per_url
The number of characters counted for URLs.
- image_size_limit
The maximum file size for images.
- stopOnErrors
Whether to stop when a verification fails (
TRUE
) or whether to just store the errors in a column callederrors
.- tokenname
The name of the environment variable containing the rtoot token produced with
rtoot::auth_setup()
andrtoot::convert_token_to_envvar()
.- select
Optionally, the number(s) of the toot(s) to select to preview.
- filename
The file to write the HTML with the preview to.
- encoding
The encoding to use when writing the file.
Examples
### Get example post directory
examplePostDir <-
system.file("example-post",
package = "quartodon");
### Get an example text (see the intro vignette)
exampleText <-
readLines(
file.path(examplePostDir, "quartodon.Rmd"),
encoding = "UTF-8"
);
### Extract toots, add thread counters, prepare and
### check the toots, and preview the thread in the viewer
quartodon::get_prep_check_toots(
exampleText,
postsPath = examplePostDir
);