File tree Expand file tree Collapse file tree 4 files changed +33
-5
lines changed Expand file tree Collapse file tree 4 files changed +33
-5
lines changed Original file line number Diff line number Diff line change 4
4
module Jekyll
5
5
class Mentions
6
6
GITHUB_DOT_COM = "https://github.com" . freeze
7
+ BODY_START_TAG = "<body" . freeze
8
+
7
9
8
10
InvalidJekyllMentionConfig = Class . new ( Jekyll ::Errors ::FatalException )
9
11
10
12
class << self
11
13
def mentionify ( doc )
14
+ return unless doc . output . include? ( "@" )
12
15
src = mention_base ( doc . site . config )
13
- doc . output = filter_with_mention ( src ) . call ( doc . output ) [ :output ] . to_s
16
+ if doc . output . include? BODY_START_TAG
17
+ parsed_doc = Nokogiri ::HTML ::Document . parse ( doc . output )
18
+ body = parsed_doc . at_css ( 'body' )
19
+ body . children = filter_with_mention ( src ) . call ( body . inner_html ) [ :output ] . to_s
20
+ doc . output = parsed_doc . to_html
21
+ else
22
+ doc . output = filter_with_mention ( src ) . call ( doc . output ) [ :output ] . to_s
23
+ end
14
24
end
15
25
16
26
# Public: Create or fetch the filter for the given {{src}} base URL.
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE HTML>
2
+ < html lang ="en-US ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < title > {{ page.title }}</ title >
6
+ < meta name ="viewport " content ="width=device-width,initial-scale=1 ">
7
+ < link rel ="stylesheet " href ="/css/screen.css ">
8
+ </ head >
9
+ < body class ="wrap ">
10
+ {{ content }}
11
+ </ body >
12
+ </ html >
Original file line number Diff line number Diff line change 1
1
---
2
+ layout : default
2
3
title : I'm a page
3
4
---
4
5
5
- test @test test
6
+ test @test test
Original file line number Diff line number Diff line change @@ -56,11 +56,16 @@ def para(content)
56
56
expect ( complex_post . output ) . to include ( result )
57
57
end
58
58
59
- it "correctly replaces the mentions with the img in pages" do
60
- expect ( site . pages . first . output ) . to start_with ( para ( result ) )
59
+ it "correctly replaces the mentions with the link in pages" do
60
+ expect ( site . pages . first . output ) . to include ( para ( result ) )
61
61
end
62
62
63
- it "correctly replaces the mentions with the img in collection documents" do
63
+ it "doesn't mangle layouts" do
64
+ expect ( site . pages . first . output ) . to include ( "<html lang=\" en-US\" >" )
65
+ expect ( site . pages . first . output ) . to include ( "<body class=\" wrap\" >\n " )
66
+ end
67
+
68
+ it "correctly replaces the mentions with the link in collection documents" do
64
69
expect ( basic_doc . output ) . to start_with ( para ( result ) )
65
70
end
66
71
You can’t perform that action at this time.
0 commit comments