<commit_before>/*
Backend spell checking support
*/

import { filename_extension } from "../generic/misc";
import { exec, ExecOutput } from "../generic/client";
import { language } from "../generic/misc-page";

interface Options {
  project_id: string;
  path: string;
  lang: string;
  time?: number;
}

export async function misspelled_words(opts: Options): Promise<string[]> {
  if (!opts.lang) {
    opts.lang = language();
  }
  if (opts.lang === "disabled") {
    return [];
  }

  let mode: string;
  switch (filename_extension(opts.path)) {
    case "html":
      mode = "--mode=html";
      break;
    case "tex":
      mode = "--mode=tex";
      break;
    default:
      mode = "--mode=none";
  }
  let lang;
  switch(opts.lang) {
    case 'default':
      lang = `--lang=${language()}`;
      break;
    case 'disabled':
      lang = '';
      break;
    default:
      lang = `--lang=${opts.lang}`;
<commit_msg>webapp/code editor spellcheck: canonicalize filename extension to select correct mode (#3030) and prep for spellchecking knitr related file formats<commit_after>/*
Backend spell checking support
*/

import { filename_extension } from "../generic/misc";
import { exec, ExecOutput } from "../generic/client";
import { language } from "../generic/misc-page";

interface Options {
  project_id: string;
  path: string;
  lang: string;
  time?: number;
}

export async function misspelled_words(opts: Options): Promise<string[]> {
  if (!opts.lang) {
    opts.lang = language();
  }
  if (opts.lang === "disabled") {
    return [];
  }

  let mode: string;
  switch (filename_extension(opts.path).toLowerCase()) {
    case "html":
      mode = "--mode=html";
      break;
    case "tex":
    case "rtex":
    case "rnw":
      mode = "--mode=tex";
      break;
    default:
      mode = "--mode=none";
  }
  let lang;
  switch(opts.lang) {
    case 'default':
      lang = `--lang=${language()}`;
      break;
    case 'disabled':
      lang = '';
      break;
    default:
      lang = `--lang=${opts.lang}`;

{'fraction_non_alphanumeric': 0.1646131099063578, 'fraction_numerical': 0.001971414489896501, 'mean_word_length': 2.738489871086556, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '3746366', 'n_tokens_mistral': 644, 'n_tokens_neox': 639, 'n_words': 172}