Skip to content

Commit c207b7d

Browse files
committed
Strip newlines from generated HTML
This prevents a space to be added e.g. before a comma directly after the term, which looks bad. Fixes #9
1 parent d8548e3 commit c207b7d

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Fixed
9+
- Strip newlines from generated HTML to prevent unnecessary spaces to be added. [#9](https://github.com/erikw/jekyll-glossary_tooltip/issues/9)
810

911
## [1.5.0] - 2022-09-08
1012
### Added

lib/jekyll-glossary_tooltip/tag.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ def initialize(tag_name, args, tokens)
1515
def render(context)
1616
entry = lookup_entry(context.registers[:site], @opts[:term_query])
1717
@opts[:display] ||= @opts[:term_query]
18-
<<~HTML
18+
html = <<~HTML
1919
<span class="jekyll-glossary">
2020
#{@opts[:display]}
2121
<span class="jekyll-glossary-tooltip">#{entry["definition"]}#{render_tooltip_url(entry, context)}</span>
2222
</span>
2323
HTML
24+
html.gsub("\n", "")
2425
end
2526

2627
private

spec/fixtures/normal/page7.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: "Fixture page 6"
3+
layout: default
4+
---
5+
6+
# Fixture
7+
8+
When a term is followed by a comma {% glossary term_without_url %}, no space before comma..

spec/jekyll-glossary_tooltip/tag_spec.rb

+10
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
let(:page4) { File.read(dest_dir("page4.html")) }
2323
let(:page5) { File.read(dest_dir("page5.html")) }
2424
let(:page6) { File.read(dest_dir("page6.html")) }
25+
let(:page7) { File.read(dest_dir("page7.html")) }
2526

2627
it "renders a glossary tag with a URL" do
2728
expect_tag_match(page1, "term_with_url")
@@ -46,6 +47,15 @@
4647
it "renders a glossary tag with URL rendered from embedded liquid tags" do
4748
expect_tag_match(page6, "term_with_url_embedded_liquid", href: "/page2.html")
4849
end
50+
51+
it "renders no unnecessary space after tooltip" do
52+
# expect_tag_match(page7, "term_with_url", href: "/page2.html")
53+
term_name = "term_without_url"
54+
regex = %r{#{R1}#{term_name}#{R2}#{term_name} definition}
55+
regex = Regexp.new(regex.source + %r{#{R5}, no space before comma.}.source)
56+
57+
expect(page7).to match(regex)
58+
end
4959
end
5060

5161
context "when a site is incorrectly configured (missing term definition)" do

0 commit comments

Comments
 (0)