Skip to content

Commit 32d8f25

Browse files
committed
Add hidden parenthesis that will be visible for post.excerpt
The parenthesis around the term definition is hidden with CSS in the normal case. When Jekyll renders a post.excerpt, HTML and CSS is stripped and the parenthesis are revealed! Fixes #7
1 parent 0e3dd2f commit 32d8f25

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ 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+
### Added
9+
- [BREAKING] Hidden with CSS parenthesis around term definition. These parenthesis will be revealed when jekyll produces a post.except as typically HTML and CSS stripped => the plain text rendering of the glossary tag will be "<term-name> (term-description> <term-url>)". [#7](https://github.com/erikw/jekyll-glossary_tooltip/issues/7)
10+
- To upgrade to new version, you need to update the CSS by re-copy the full contexts of [jekyll-glossary_tooltip.css](lib/jekyll-glossary_tooltip/jekyll-glossary_tooltip.css) to your side. The new CSS class `.jekyll-glossary-tooltip-hidden` is added and needed to hide parenthesis in the tooltip.
11+
812
## [1.5.1] - 2025-03-10
913
### Fixed
1014
- Strip newlines from generated HTML to prevent unnecessary spaces to be added. [#9](https://github.com/erikw/jekyll-glossary_tooltip/issues/9)
1115

1216
## [1.5.0] - 2022-09-08
1317
### Added
14-
- Support for embedded liqid tags in the url field. ([#3](https://github.com/erikw/jekyll-glossary_tooltip/issues/3])
18+
- Support for embedded liquid tags in the url field. ([#3](https://github.com/erikw/jekyll-glossary_tooltip/issues/3])
1519

1620
## [1.4.0] - 2021-08-18
1721
### Changed

lib/jekyll-glossary_tooltip/jekyll-glossary_tooltip.css

+9
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,12 @@
5757
.jekyll-glossary:hover .jekyll-glossary-tooltip {
5858
opacity: 1;
5959
}
60+
61+
/* HACK: hide surrounding parenthesis on definition. When Jekyll renders
62+
* post.excerpt, all HTML and CSS is stripped. The effect is that the extra
63+
* parenthesis that are added are hidden in the normal blog post with hoover, but
64+
* hidden in the post.except when html and css is stripped. Ref:
65+
* https://github.com/erikw/jekyll-glossary_tooltip/issues/7#issuecomment-2711471867 */
66+
.jekyll-glossary-tooltip-hidden {
67+
display: none;
68+
}

lib/jekyll-glossary_tooltip/tag.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ def render(context)
1717
@opts[:display] ||= @opts[:term_query]
1818
html = <<~HTML
1919
<span class="jekyll-glossary">
20-
#{@opts[:display]}
21-
<span class="jekyll-glossary-tooltip">#{entry["definition"]}#{render_tooltip_url(entry, context)}</span>
20+
#{@opts[:display]}
21+
<span class="jekyll-glossary-tooltip">
22+
<span class="jekyll-glossary-tooltip-hidden">(</span>#{entry["definition"]}#{render_tooltip_url(entry, context)}<span class="jekyll-glossary-tooltip-hidden">)</span>
23+
</span>
2224
</span>
2325
HTML
2426
html.gsub("\n", "")

spec/jekyll-glossary_tooltip/tag_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
it "renders no unnecessary space after tooltip" do
5252
# expect_tag_match(page7, "term_with_url", href: "/page2.html")
5353
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)
54+
regex = %r{#{R1}#{term_name}#{R2}#{R_PAR_OPEN}#{term_name} definition}
55+
regex = Regexp.new(regex.source + %r{#{R_PAR_CLOSE}#{R5}, no space before comma.}.source)
5656

5757
expect(page7).to match(regex)
5858
end

spec/spec_helper.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# Tag matching regex parts.
1515
R1 = %r{<span class="jekyll-glossary">\s*}
1616
R2 = %r{\s*<span class="jekyll-glossary-tooltip">\s*}
17+
R_PAR_OPEN = %r{\s*<span class="jekyll-glossary-tooltip-hidden">\(</span>\s*}
18+
R_PAR_CLOSE = %r{\s*<span class="jekyll-glossary-tooltip-hidden">\)</span>\s*}
1719
R3 = %r{\s*<br(\s/)?><a class="jekyll-glossary-source-link" href="}
1820
R4 = %r{" target="_blank"></a>\s*}
1921
R5 = %r{</span>\s*</span>}
@@ -64,12 +66,12 @@ def remove_dest_dir
6466
def expect_tag_match(content, term_name, url: true, term_display: nil, href: nil)
6567
term_display ||= term_name
6668

67-
regex = %r{#{R1}#{term_display}#{R2}#{term_name} definition}
69+
regex = %r{#{R1}#{term_display}#{R2}#{R_PAR_OPEN}#{term_name} definition}
6870
if url
6971
href ||= "#{term_name} url"
7072
regex = Regexp.new(regex.source + %r{#{R3}#{href}#{R4}}.source)
7173
end
72-
regex = Regexp.new(regex.source + %r{#{R5}}.source)
74+
regex = Regexp.new(regex.source + %r{#{R_PAR_CLOSE}#{R5}}.source)
7375

7476
expect(content).to match(regex)
7577
end

0 commit comments

Comments
 (0)