vscode-texinfo/src/converter.ts

43 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-10-03 18:04:18 +00:00
/**
* converter.ts
*
* @author CismonX <admin@cismon.net>
* @license MIT
*/
2020-10-14 19:22:32 +00:00
import Options from './options';
2020-10-22 22:40:41 +00:00
import { exec } from './utils';
2020-10-03 18:04:18 +00:00
/**
* Texinfo to HTML converter.
*/
2020-10-14 19:22:32 +00:00
export default class Converter {
2020-10-03 18:04:18 +00:00
/**
2020-10-04 12:40:54 +00:00
* Convert a Texinfo document to HTML.
2020-10-03 18:04:18 +00:00
*
2020-10-04 12:40:54 +00:00
* @param path Path to the Texinfo document.
2020-10-03 18:04:18 +00:00
*/
static async convertToHtml(path: string) {
return await new Converter().convert(path);
2020-10-03 18:04:18 +00:00
}
/**
* The options to be passed to the `makeinfo` command.
*/
private readonly options = ['-o', '-', '--no-split', '--html'];
private constructor() {
2020-10-04 12:40:54 +00:00
Options.noHeaders && this.options.push('--no-headers');
Options.force && this.options.push('--force');
2020-10-17 13:41:03 +00:00
Options.noValidation && this.options.push('--no-validate');
Options.noWarnings && this.options.push('--no-warn');
2020-10-03 18:04:18 +00:00
this.options.push(`--error-limit=${Options.errorLimit}`);
}
private async convert(path: string) {
2020-10-03 18:04:18 +00:00
const maxBuffer = Options.maxSize * 1024 * 1024;
2020-10-22 22:40:41 +00:00
return await exec(Options.makeinfo, this.options.concat(path), maxBuffer);
2020-10-03 18:04:18 +00:00
}
}