Skip to content

Commit 1ed2d33

Browse files
committed
Merge pull request #29 from jekyll/do-not-mangle-layouts
Merge pull request 29
2 parents 1506355 + 59c1d64 commit 1ed2d33

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

lib/jekyll-mentions.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@
44
module Jekyll
55
class Mentions
66
GITHUB_DOT_COM = "https://github.com".freeze
7+
BODY_START_TAG = "<body".freeze
8+
79

810
InvalidJekyllMentionConfig = Class.new(Jekyll::Errors::FatalException)
911

1012
class << self
1113
def mentionify(doc)
14+
return unless doc.output.include?("@")
1215
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
1424
end
1525

1626
# Public: Create or fetch the filter for the given {{src}} base URL.

spec/fixtures/_layouts/default.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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>

spec/fixtures/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
2+
layout: default
23
title: I'm a page
34
---
45

5-
test @test test
6+
test @test test

spec/mentions_spec.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,16 @@ def para(content)
5656
expect(complex_post.output).to include(result)
5757
end
5858

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))
6161
end
6262

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
6469
expect(basic_doc.output).to start_with(para(result))
6570
end
6671

0 commit comments

Comments
 (0)