I want to display blog post excerpts, and I'm using Nokogiri to parse
the post body so that I can properly truncate the HTML, and then graft
an arbitrary HTML "read more" string as extra children of the last
node parent (so that the read-more is displayed inline).
But I've been unable to work out how to do this easily. Do I have to
write a recursive node-adding method?
I've searched this list, but haven't been able to find an answer.
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/348298
http://groups.google.com/group/nokogiri-talk/browse_thread/thread/8111ca56fa49545d
I've tried "parent.inner_html += more_html", and the "after" method,
but neither worked.
Thanks.
Hello,
I want to display blog post excerpts, and I'm using Nokogiri to parse
the post body so that I can properly truncate the HTML, and then graft
an arbitrary HTML "read more" string as extra children of the last
node parent (so that the read-more is displayed inline).
But I've been unable to work out how to do this easily.
Do I have to
write a recursive node-adding method?
I've searched this list, but haven't been able to find an answer.
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/348298
http://groups.google.com/group/nokogiri-talk/browse_thread/thread/8111ca56fa49545d
I've tried "parent.inner_html += more_html", and the "after" method,
but neither worked.
Thanks.
--
You received this message because you are subscribed to the Google Groups "nokogiri-talk" group.
To post to this group, send email to nokogi...@googlegroups.com.
To unsubscribe from this group, send email to nokogiri-tal...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nokogiri-talk?hl=en.
Thanks Mike for the pointer to "after". I'd tried it without success,
but your post induced me to persist until I got it working.
The working code for an inline graft of an HTML "Read More" fragment
was
[HTML-aware truncation of the document]
body = doc.root.children.first
last_node = body.children.last
last_node_children = last_node.children
last_node = last_node_children.last unless
last_node_children.empty?
last_node.after(more_html)
body.inner_html