diff --git a/lib/highlight.ts b/lib/highlight.ts index 6279be09..22d42015 100644 --- a/lib/highlight.ts +++ b/lib/highlight.ts @@ -16,14 +16,11 @@ interface Options { mark?: number[]; tab?: string; wrap?: boolean; - disableStripIndent?: boolean + stripIndent?: boolean; } function highlightUtil(str: string, options: Options = {}) { if (typeof str !== 'string') throw new TypeError('str must be a string!'); - if (!options.disableStripIndent) { - str = stripIndent(str); - } const useHljs = Object.prototype.hasOwnProperty.call(options, 'hljs') ? options.hljs : false; const { @@ -32,10 +29,15 @@ function highlightUtil(str: string, options: Options = {}) { caption, mark = [], languageAttr = false, - tab + tab, + stripIndent: enableStripIndent = true } = options; let { wrap = true } = options; + if (enableStripIndent) { + str = stripIndent(str); + } + if (!hljs) { hljs = require('highlight.js'); } diff --git a/lib/prism.ts b/lib/prism.ts index 79776feb..daa0c4f6 100644 --- a/lib/prism.ts +++ b/lib/prism.ts @@ -65,14 +65,11 @@ interface Options { lineNumber?: boolean; mark?: string; tab?: string; - disableStripIndent?: boolean + stripIndent?: boolean; } function PrismUtil(str: string, options: Options = {}) { if (typeof str !== 'string') throw new TypeError('str must be a string!'); - if (!options.disableStripIndent) { - str = stripIndent(str); - } const { lineNumber = true, @@ -81,9 +78,14 @@ function PrismUtil(str: string, options: Options = {}) { mark, firstLine, isPreprocess = true, - caption + caption, + stripIndent: enableStripIndent = true } = options; + if (enableStripIndent) { + str = stripIndent(str); + } + // To be consistent with highlight.js let language = lang === 'plaintext' || lang === 'none' ? 'none' : lang;