Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3 from buildcom/PLAT-6661
Browse files Browse the repository at this point in the history
PLAT-6661 - Add support for H4, H5, and H6 heading tags.
  • Loading branch information
Brandon Mains authored Apr 3, 2017
2 parents b8c61f6 + a929112 commit 4040fa4
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 10 deletions.
12 changes: 4 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@ var format = exports.format = {
},

lineify: {
h1: function() {
this[0].name = 'h1';
},
h2: function() {
this[0].name = 'h2';
},
h3: function() {
this[0].name = 'h3';
header: function($, level) {
if (level > 0 && level < 7) {
this[0].name = 'h' + level;
}
},
list: {
group: function($, formatValue) {
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": "2.1.0",
"version": "2.2.0",
"description": "Renders quilljs deltas into HTML",
"main": "index.js",
"dependencies": {
Expand Down
61 changes: 60 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('quill-render', function() {
},
{
"attributes": {
"h1": true
"header": 1
},
"insert": "\n"
}
Expand All @@ -55,6 +55,65 @@ describe('quill-render', function() {

});

it('renders all heading levels', function() {
var i,
ops = [],
expectedElements = [];

// build ops to represent a line for each heading 1-6,
// and build expected output
for (i = 1; i <= 6; ++i) {
var tagName = "h" + i;

ops.push({
"insert": "Heading"
});
ops.push({
"attributes": {
"header": i
},
"insert": "\n"
});

expectedElements.push("<" + tagName + ">Heading</" + tagName + ">");
}

expect(render(ops)).to.equal(expectedElements.join(""));
});

it('does not render invalid heading levels', function() {
expect(render([
{
"insert": "Heading"
},
{
"attributes": {
"header": 0
},
"insert": "\n"
},
{
"insert": "Heading"
},
{
"attributes": {
"header": 7
},
"insert": "\n"
},
{
"insert": "Heading"
},
{
"attributes": {
"header": 8
},
"insert": "\n"
}
]))
.to.equal('<p>Heading</p><p>Heading</p><p>Heading</p>');
});

it('renders lists with inline formats correctly', function() {

expect(render([
Expand Down

0 comments on commit 4040fa4

Please sign in to comment.