Fix behaviour on empty elements
This commit is contained in:
parent
e9e92bf9d8
commit
2c7407ebfd
@ -1,3 +1,4 @@
|
||||
# coding: utf-8
|
||||
# smart_truncate: A HTML-aware word-truncating filter for Jekyll/Liquid
|
||||
# Copyright © 2016 RunasSudo (Yingtong Li)
|
||||
#
|
||||
@ -59,16 +60,23 @@ module Jekyll
|
||||
elsif doc.name == 'table'
|
||||
return smart_truncate_table(doc, num_words)
|
||||
else
|
||||
if num_words > 0
|
||||
children_orig = doc.children.length
|
||||
|
||||
count = 0
|
||||
doc.children.each do |child|
|
||||
count += smart_truncate_doc(child, num_words - count)
|
||||
end
|
||||
|
||||
if doc.children.length == 0
|
||||
if doc.children.length == 0 && children_orig != 0
|
||||
doc.remove()
|
||||
end
|
||||
|
||||
return count
|
||||
else
|
||||
doc.remove()
|
||||
return 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user