Support custom CSS for preview.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
CismonX 2021-02-22 15:06:05 +08:00
parent d0cd0f8fcd
commit 6fef748039
Signed by: cismonx
GPG Key ID: 3094873E29A482FB
3 changed files with 31 additions and 0 deletions

View File

@ -179,6 +179,11 @@
"type": "boolean",
"default": false,
"markdownDescription": "Display images in in preview.\n\nIf image display is not needed, turn off this option to improve preview performance."
},
"texinfo.preview.customCSS": {
"type": "string",
"default": "",
"markdownDescription": "URI of custom CSS for preview.\n\nA good example is https://www.gnu.org/software/gnulib/manual.css"
}
}
},

View File

@ -64,6 +64,10 @@ export default class Options implements vscode.Disposable {
return Options.instance.getBoolean('preview.displayImage');
}
static get customCSS() {
return Options.instance.getString('preview.customCSS');
}
static clear() {
Options.singleton = undefined;
}

View File

@ -5,6 +5,8 @@
* @license MIT
*/
import * as vscode from 'vscode';
import Logger from '../logger';
import Options from '../options';
import DOM from './dom';
import { exec } from './misc';
@ -20,6 +22,25 @@ export default class Converter {
*/
private readonly options = ['-o', '-', '--no-split', '--html'];
private includeCustomCSS(cssFileURI: string) {
try {
const uri = vscode.Uri.parse(cssFileURI, true);
switch (uri.scheme) {
case 'file':
this.options.push(`--css-include=${uri.path}`);
break;
case 'http':
case 'https':
this.options.push(`--css-ref=${uri.toString()}`);
break;
default:
throw URIError;
}
} catch (e) {
Logger.log(`Cannot load custom CSS. Invalid URI: '${cssFileURI}'`);
}
}
constructor(
private readonly path: string,
private readonly imgTransformer?: Operator<string>,
@ -29,6 +50,7 @@ export default class Converter {
Options.force && this.options.push('--force');
Options.noValidation && this.options.push('--no-validate');
Options.noWarnings && this.options.push('--no-warn');
Options.customCSS && this.includeCustomCSS(Options.customCSS);
this.options.push(`--error-limit=${Options.errorLimit}`);
}