Skip to content

Commit

Permalink
Encoding <pre> content regardless of the encodeHtml config setting
Browse files Browse the repository at this point in the history
  • Loading branch information
nozer committed May 14, 2018
1 parent 6659b9f commit 4e32f3d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
4 changes: 2 additions & 2 deletions dist/browser/QuillDeltaToHtmlConverter.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,9 @@ var QuillDeltaToHtmlConverter = (function () {
var htmlParts = converter.getHtmlParts();
if (bop.isCodeBlock()) {
return htmlParts.openingTag +
ops.map(function (iop) {
funcs_html_1.encodeHtml(ops.map(function (iop) {
return iop.isCustom() ? _this.renderCustom(iop, bop) : iop.insert.value;
}).join("")
}).join(""))
+ htmlParts.closingTag;
}
var inlines = ops.map(function (op) { return _this._renderInline(op, bop); }).join('');
Expand Down
4 changes: 2 additions & 2 deletions dist/commonjs/QuillDeltaToHtmlConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ var QuillDeltaToHtmlConverter = (function () {
var htmlParts = converter.getHtmlParts();
if (bop.isCodeBlock()) {
return htmlParts.openingTag +
ops.map(function (iop) {
funcs_html_1.encodeHtml(ops.map(function (iop) {
return iop.isCustom() ? _this.renderCustom(iop, bop) : iop.insert.value;
}).join("")
}).join(""))
+ htmlParts.closingTag;
}
var inlines = ops.map(function (op) { return _this._renderInline(op, bop); }).join('');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "quill-delta-to-html",
"version": "0.8.1",
"version": "0.8.2",
"description": "Converts Quill's delta ops to HTML",
"main": "dist/commonjs/main.js",
"dependencies": {},
Expand Down
10 changes: 6 additions & 4 deletions src/QuillDeltaToHtmlConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
VideoItem, InlineGroup, BlockGroup, ListGroup, ListItem, TDataGroup
} from './grouper/group-types';
import { ListNester } from './grouper/ListNester';
import { makeStartTag, makeEndTag } from './funcs-html';
import { makeStartTag, makeEndTag, encodeHtml } from './funcs-html';
import './extensions/Object';
import { NewLine, GroupType } from './value-types';

Expand Down Expand Up @@ -169,9 +169,11 @@ class QuillDeltaToHtmlConverter {

if (bop.isCodeBlock()) {
return htmlParts.openingTag +
ops.map((iop) =>
iop.isCustom() ? this.renderCustom(iop, bop) : iop.insert.value
).join("")
encodeHtml(
ops.map((iop) =>
iop.isCustom() ? this.renderCustom(iop, bop) : iop.insert.value
).join("")
)
+ htmlParts.closingTag;
}

Expand Down
21 changes: 18 additions & 3 deletions test/QuillDeltaToHtmlConverter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { callWhenAlltrue, callWhenXEqualY } from './_helper';

import { delta1 } from './data/delta1';
import { GroupType } from './../src/value-types';
import { encodeHtml } from './../src/funcs-html';


describe('QuillDeltaToHtmlConverter', function () {

Expand Down Expand Up @@ -340,24 +342,37 @@ describe('QuillDeltaToHtmlConverter', function () {
{
"insert": "line 3"
},
{
"attributes": {
"code-block": true
},
"insert": "\n"
},
{
"insert": "<p>line 4</p>"
},
{
"attributes": {
"code-block": true
},
"insert": "\n"
}
]

console.log(encodeHtml("<p>line 4</p>"));
var qdc = new QuillDeltaToHtmlConverter(ops);
let html = qdc.convert();
assert.equal(html, "<pre>line 1\nline 2\nline 3</pre>");
assert.equal(html, ["<pre>line 1\nline 2\nline 3\n",
encodeHtml("<p>line 4</p>"),
"</pre>"].join("")
);

qdc = new QuillDeltaToHtmlConverter(ops, {
multiLineCodeblock: false
});
html = qdc.convert();
assert.equal(
'<pre>line 1</pre><pre>line 2</pre><pre>line 3</pre>',
'<pre>line 1</pre><pre>line 2</pre><pre>line 3</pre>'+
'<pre>'+ encodeHtml("<p>line 4</p>") + '</pre>',
html);
qdc = new QuillDeltaToHtmlConverter([ops[0], ops[1]]);
html = qdc.convert();
Expand Down

0 comments on commit 4e32f3d

Please sign in to comment.