/* * This file is part of CoCalc: Copyright © 2020 Sagemath, Inc. * License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details */ const { writeFile, readFile, unlink } = require("fs"); const tmp = require("tmp"); const { execute_code } = require("smc-util-node/execute-code"); const { callback } = require("awaiting"); const { callback_opts } = require("smc-util/async-utils"); interface ParserOptions { parser: string; } // the long list of options looks scary, but it is based on testing it. // e.g. that it doesn't introduce a "full" document, as long as there is no
tag. // also, the "indent" formatting of codemirror is similar to the indentation here. // ref: http://tidy.sourceforge.net/docs/quickref.html async function tidy(input_path) { const args = [ "-modify", "--show-body-only", "auto", "--indent", "yes", "--vertical-space", "yes", "--break-before-br", "yes", "--indent-spaces", "2", // tune that if we let users ever choose the indentation "--wrap", "80", "--sort-attributes", "alpha", "--quiet", "yes", "--write-back", "yes", // enable it, if we want to show warnings upon exit code == 1 "--show-warnings", "no", "--tidy-mark", "no", // https://github.com/sagemathinc/cocalc/issues/3867 "--drop-empty-elements", "no", "--drop-empty-paras", "no", input_path, ]; return await callback_opts(execute_code)({ command: "tidy", args: args, err_on_exit: false, bash: false, timeout: 15, }); } export async function html_format( input: string, options: ParserOptions, logger: any ): Promise