diff --git a/lib/jemoji.rb b/lib/jemoji.rb index 95adb5f..fc69fa0 100644 --- a/lib/jemoji.rb +++ b/lib/jemoji.rb @@ -9,6 +9,7 @@ class Emoji GITHUB_DOT_COM_ASSET_HOST_URL = "https://assets-cdn.github.com" ASSET_PATH = "/images/icons/" BODY_START_TAG = "\s*! class << self def emojify(doc) @@ -79,11 +80,11 @@ def default_asset_root end def replace_document_body(doc) - src = emoji_src(doc.site.config) - parsed_doc = Nokogiri::HTML::Document.parse(doc.output) - body = parsed_doc.at_css("body") - body.children = filter_with_emoji(src).call(body.inner_html)[:output].to_s - parsed_doc.to_html + src = emoji_src(doc.site.config) + head, opener, tail = doc.output.partition(OPENING_BODY_TAG_REGEX) + body_content, *rest = tail.partition("") + processed_markup = filter_with_emoji(src).call(body_content)[:output].to_s + String.new(head) << opener << processed_markup << rest.join end end end diff --git a/spec/fixtures/index.html b/spec/fixtures/index.html index 1f9b534..b742659 100644 --- a/spec/fixtures/index.html +++ b/spec/fixtures/index.html @@ -1,7 +1,6 @@ - Jemoji