1- require ' jekyll'
2- require ' gemoji'
3- require ' html/pipeline'
1+ require " jekyll"
2+ require " gemoji"
3+ require " html/pipeline"
44
55module Jekyll
66 class Emoji
@@ -11,15 +11,12 @@ class Emoji
1111 class << self
1212 def emojify ( doc )
1313 return unless doc . output =~ HTML ::Pipeline ::EmojiFilter . emoji_pattern
14- src = emoji_src ( doc . site . config )
15- if doc . output . include? BODY_START_TAG
16- parsed_doc = Nokogiri ::HTML ::Document . parse ( doc . output )
17- body = parsed_doc . at_css ( 'body' )
18- body . children = filter_with_emoji ( src ) . call ( body . inner_html ) [ :output ] . to_s
19- doc . output = parsed_doc . to_html
20- else
21- doc . output = filter_with_emoji ( src ) . call ( doc . output ) [ :output ] . to_s
22- end
14+ doc . output = if doc . output . include? BODY_START_TAG
15+ replace_document_body ( doc )
16+ else
17+ src = emoji_src ( doc . site . config )
18+ filter_with_emoji ( src ) . call ( doc . output ) [ :output ] . to_s
19+ end
2320 end
2421
2522 # Public: Create or fetch the filter for the given {{src}} asset root.
@@ -29,8 +26,8 @@ def emojify(doc)
2926 # Returns an HTML::Pipeline instance for the given asset root.
3027 def filter_with_emoji ( src )
3128 filters [ src ] ||= HTML ::Pipeline . new ( [
32- HTML ::Pipeline ::EmojiFilter
33- ] , { :asset_root => src , img_attrs : { align : nil } } )
29+ HTML ::Pipeline ::EmojiFilter ,
30+ ] , { :asset_root => src , :img_attrs => { :align => nil } } )
3431 end
3532
3633 # Public: Filters hash where the key is the asset root source.
@@ -78,10 +75,18 @@ def default_asset_root
7875 "#{ GITHUB_DOT_COM_ASSET_HOST_URL } #{ ASSET_PATH } "
7976 end
8077 end
78+
79+ def replace_document_body ( doc )
80+ src = emoji_src ( doc . site . config )
81+ parsed_doc = Nokogiri ::HTML ::Document . parse ( doc . output )
82+ body = parsed_doc . at_css ( "body" )
83+ body . children = filter_with_emoji ( src ) . call ( body . inner_html ) [ :output ] . to_s
84+ parsed_doc . to_html
85+ end
8186 end
8287 end
8388end
8489
85- Jekyll ::Hooks . register [ : pages, : documents] , :post_render do |doc |
90+ Jekyll ::Hooks . register %i[ pages documents ] , :post_render do |doc |
8691 Jekyll ::Emoji . emojify ( doc ) if Jekyll ::Emoji . emojiable? ( doc )
8792end
0 commit comments