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
|
# smart_truncate: A HTML-aware word-truncating filter for Jekyll/Liquid
|
||||||
# Copyright © 2016 RunasSudo (Yingtong Li)
|
# Copyright © 2016 RunasSudo (Yingtong Li)
|
||||||
#
|
#
|
||||||
@ -59,16 +60,23 @@ module Jekyll
|
|||||||
elsif doc.name == 'table'
|
elsif doc.name == 'table'
|
||||||
return smart_truncate_table(doc, num_words)
|
return smart_truncate_table(doc, num_words)
|
||||||
else
|
else
|
||||||
count = 0
|
if num_words > 0
|
||||||
doc.children.each do |child|
|
children_orig = doc.children.length
|
||||||
count += smart_truncate_doc(child, num_words - count)
|
|
||||||
end
|
count = 0
|
||||||
|
doc.children.each do |child|
|
||||||
if doc.children.length == 0
|
count += smart_truncate_doc(child, num_words - count)
|
||||||
|
end
|
||||||
|
|
||||||
|
if doc.children.length == 0 && children_orig != 0
|
||||||
|
doc.remove()
|
||||||
|
end
|
||||||
|
|
||||||
|
return count
|
||||||
|
else
|
||||||
doc.remove()
|
doc.remove()
|
||||||
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
return count
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user