vscode-texinfo/src/converter.ts

44 lines
1.2 KiB
TypeScript
Raw Normal View History

2020-10-03 18:04:18 +00:00
/**
* converter.ts
*
* @author CismonX <admin@cismon.net>
* @license MIT
*/
import { Options } from './options';
import * as utils from './utils';
2020-10-03 18:04:18 +00:00
/**
* Texinfo to HTML converter.
*/
export class Converter {
/**
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-10 17:36:05 +00:00
* @returns HTML code, or `undefined` if conversion fails.
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');
Options.noValidate && this.options.push('--no-validate');
Options.noWarn && 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-04 18:16:08 +00:00
return await utils.exec(Options.makeinfo, this.options.concat(path), maxBuffer);
2020-10-03 18:04:18 +00:00
}
}