Extract snippet out of HTML with Ruby? -
I need to show the first 100 characters of an HTML text, which means I must first choose 100 characters < Em> No tag and then leave any HTML open and close the balanced tag. Is there any such library that can do it? Or is there any insignificant way to do this that I am missing?
The text is basically written in textile which keeps the HTML and can be in it, so I thought that I am better than converting it completely to HTML and then processing, but if something is to wear it At the level, I am also happy.
This is how I get the first 100 chars of text. You may need to modify according to your needs
Required 'nocagri' def get_first_100_chars doc = Nokogiri :: Slop (open 'html_file.html') text = doc.html.body Text return text [0..9 9] and
Not sure about the balance of HTML. If I come to know then will post
Comments
Post a Comment