Skip to content

Commit

Permalink
fix(prism): add strip_indent support (#184)
Browse files Browse the repository at this point in the history
* fix(prism): add strip_indent support

* test(prism): fix strip indent cases
  • Loading branch information
SukkaW committed Mar 5, 2020
1 parent e81733c commit 771f8ba
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/prism.js
@@ -1,6 +1,7 @@
'use strict';

const Prism = require('prismjs');
const stripIndent = require('strip-indent');
const prismLoadLanguages = require('prismjs/components/');

// https://github.com/PrismJS/prism/issues/2145
Expand Down Expand Up @@ -53,6 +54,7 @@ function replaceTabs(str, tab) {

function PrismUtil(str, options = {}) {
if (typeof str !== 'string') throw new TypeError('str must be a string!');
str = stripIndent(str);

const {
lineNumber = true,
Expand Down
5 changes: 3 additions & 2 deletions test/prism.spec.js
Expand Up @@ -2,6 +2,7 @@

require('chai').should();
const escapeHTML = require('../lib/escape_html');
const stripIndent = require('strip-indent');

const validator = require('html-tag-validator');
function validateHtmlAsync(str, done) {
Expand Down Expand Up @@ -44,7 +45,7 @@ describe('prismHighlight', () => {
// Line Number
result.should.contains(lineNumberStartTag);
// Code should only be escaped.
result.should.contains(escapeHTML(input));
result.should.contains(escapeHTML(stripIndent(input)));
result.should.not.contains(highlightToken);

validateHtmlAsync(result, done);
Expand Down Expand Up @@ -175,7 +176,7 @@ describe('prismHighlight', () => {
// Line Number
result.should.contains(lineNumberStartTag);
// Code should only be escaped.
result.should.contains(escapeHTML(input));
result.should.contains(escapeHTML(stripIndent(input)));
result.should.not.contains(highlightToken);

validateHtmlAsync(result, done);
Expand Down

0 comments on commit 771f8ba

Please sign in to comment.