Skip to content

Commit

Permalink
Fix for improperly rendered adjacent inline formats in some scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
daguej committed Jul 10, 2015
1 parent 4715e77 commit 8e1de26
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
21 changes: 14 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,19 @@ function convert(ops) {
var first = [], then = [];
attrs = attrs || {};

var tag = el, seen = {};
while (tag[0]._format) {
seen[tag[0]._format] = true;
if (!attrs[tag[0]._format]) {
for (var k in seen) {
delete activeInline[k];
}
el = tag.parent();
}

tag = tag.parent();
}

for (var k in attrs) {
if (format.inline[k]) {

Expand All @@ -165,18 +178,12 @@ function convert(ops) {
}
}

for (var k in activeInline) {
if (!attrs[k]) {
el = el.parent();
delete activeInline[k];
}
}

first.forEach(apply);
then.forEach(apply);

function apply(fmt) {
var newEl = format.inline[fmt].call(null, $, attrs[fmt]);
newEl[0]._format = fmt;
el.append(newEl);
el = newEl;
}
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-render",
"version": "1.0.2",
"version": "1.0.3",
"description": "Renders quilljs deltas into HTML",
"main": "index.js",
"dependencies": {
Expand Down
25 changes: 25 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,29 @@ describe('quill-render', function() {

});

it('renders adjacent inline formats correctly', function() {
expect(render([
{
"attributes" : {
"italic" : true
},
"insert" : "Italics! "
},
{
"attributes": {
"italic": true,
"link": "http://example.com"
},
"insert": "Italic link"
},
{
"attributes": {
"link": "http://example.com"
},
"insert": " regular link"
}

]))
.to.equal('<p><i>Italics! <a href="http://example.com">Italic link</a></i><a href="http://example.com"> regular link</a></p>');
});
});

0 comments on commit 8e1de26

Please sign in to comment.