<commit_before>import { change_filename_extension } from "smc-util/misc2";

// something in the rmarkdown source code replaces all spaces by dashes
// [hsy] I think this is because of calling pandoc.
// I'm not aware of any other replacements.
// https://github.com/rstudio/rmarkdown
export function derive_rmd_output_filename(path, ext) {
  return change_filename_extension(path, ext).replace(/ /g, "-");
}
<commit_msg>webapp/rmd: do not mangle dirname of rmd preview file<commit_after>import { change_filename_extension, path_split } from "smc-util/misc2";
import { join } from "path";

// something in the rmarkdown source code replaces all spaces by dashes
// [hsy] I think this is because of calling pandoc.
// I'm not aware of any other replacements.
// https://github.com/rstudio/rmarkdown
// problem: do not do this for the directory name, only the filename -- issue #4405
export function derive_rmd_output_filename(path, ext) {
  const { head, tail } = path_split(path);
  const fn = change_filename_extension(tail, ext).replace(/ /g, "-");
  // avoid a leading / if it's just a filename (i.e. head = '')
  return join(head, fn);
}

{'fraction_non_alphanumeric': 0.11568799298860649, 'fraction_numerical': 0.0052585451358457495, 'mean_word_length': 4.1909090909090905, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6980052', 'n_tokens_mistral': 361, 'n_tokens_neox': 345, 'n_words': 125}