Skip to content

Commit 057151e

Browse files
committed
Fix block removal on cleanup
1 parent a83dc9c commit 057151e

File tree

4 files changed

+8679
-4
lines changed

4 files changed

+8679
-4
lines changed

index.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ module.exports = class Flatten
111111
blocks.push b
112112

113113
blockIdx = item.content.indexOf block
114-
return callback() if blockIdx is -1
114+
#return callback() if blockIdx is -1
115115
unless blocks.length
116116
# Empty block, remove
117-
item.content = item.content.splice blockIdx, 1
117+
item.content.splice blockIdx, 1
118118
return callback()
119119
if blocks.length is 1
120120
# Block returned only one block, update values

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "html-flatten",
3-
"version": "0.1.9",
3+
"version": "0.1.10",
44
"description": "flattens arbitrary html into a sane structure",
55
"main": "index.coffee",
66
"scripts": {

spec/Cleanup.coffee

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe 'Cleanup', ->
2929
done()
3030

3131
describe 'cleaning a dirty HTML structure', ->
32-
it 'produce clean blocks', (done) ->
32+
it 'should produce clean blocks', (done) ->
3333
item =
3434
content: [
3535
id: 'foo'
@@ -58,3 +58,18 @@ describe 'Cleanup', ->
5858
html: '<p>Foobar</p>'
5959
chai.expect(item.content[2]).to.eql orig.content[1]
6060
done()
61+
62+
describe 'cleaning up a full item', ->
63+
it 'should produce clean blocks', (done) ->
64+
fs = require 'fs'
65+
path = require 'path'
66+
item = JSON.parse fs.readFileSync __dirname+'/fixtures/put.json', 'utf-8'
67+
orig = JSON.parse JSON.stringify item
68+
f.flattenItem item, ->
69+
types = item.content.map (b) -> b.type
70+
chai.expect(types).to.eql [
71+
'image'
72+
'image'
73+
'image'
74+
]
75+
done()

0 commit comments

Comments
 (0)