Skip to content

Instantly share code, notes, and snippets.

@ivan3bx
Created June 10, 2014 03:59
Show Gist options
  • Save ivan3bx/f4f4fdf2a0f6f5d05ce1 to your computer and use it in GitHub Desktop.
Save ivan3bx/f4f4fdf2a0f6f5d05ce1 to your computer and use it in GitHub Desktop.
grabbing the last 200 characters preceeding a 'blockquote'
#
# Brute force method of grabbing 200 characters preceeding first <blockquote> element
#
p = Post.last
parts = p.split_as_html
root = Nokogiri::HTML.fragment(parts.first.raw_content)
bq = root.search('blockquote')[1]
test_string = root.inner_html[(root.inner_html.index(bq.to_html) - 200)...(root.inner_html.index(bq.to_html))]
# ">\n<br><br><div class=\"gmail_quote\">On Tue, Jun 29, 2014 at 11:19 AM, John Smith <span dir=\"ltr\">&lt;
# <a href=\"mailto:[email protected]\" target=\"_blank\">[email protected]</a>&gt;</span> wrote:<br>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment