Skip to content

Commit 8aaf0df

Browse files
authored
Implemented details tag for distill blog (alshedivat#1321)
1 parent 60209cf commit 8aaf0df

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

_plugins/details.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Code from http://movb.de/jekyll-details-support.html
2+
3+
module Jekyll
4+
module Tags
5+
class DetailsTag < Liquid::Block
6+
7+
def initialize(tag_name, markup, tokens)
8+
super
9+
@caption = markup
10+
end
11+
12+
def render(context)
13+
site = context.registers[:site]
14+
converter = site.find_converter_instance(::Jekyll::Converters::Markdown)
15+
caption = converter.convert(@caption).gsub(/<\/?p[^>]*>/, '').chomp
16+
body = converter.convert(super(context))
17+
"<details><summary>#{caption}</summary>#{body}</details>"
18+
end
19+
20+
end
21+
end
22+
end
23+
24+
Liquid::Template.register_tag('details', Jekyll::Tags::DetailsTag)

_posts/2018-12-22-distill.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ fig.write_html('assets/plotly/demo.html')
156156

157157
***
158158

159+
## Details boxes
160+
161+
Details boxes are collapsible boxes which hide additional information from the user. They can be added with the `details` liquid tag:
162+
163+
{% details Click here to know more %}
164+
Additional details, where math $$ 2x - 1 $$ and `code` is rendered correctly.
165+
{% enddetails %}
166+
167+
***
168+
159169
## Layouts
160170

161171
The main text column is referred to as the body.

_sass/_distill.scss

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,28 @@ d-article {
3535
display: inline;
3636
}
3737

38+
// Style taken from code blocks
39+
details {
40+
color: var(--global-text-color);
41+
background-color: var(--global-code-bg-color);
42+
margin-top: 0;
43+
padding: 8px 12px;
44+
position: relative;
45+
border-radius: 6px;
46+
display: block;
47+
margin-bottom: 20px;
48+
grid-column: text;
49+
overflow: auto;
50+
max-width: 100%;
51+
summary {
52+
color: var(--global-theme-color);
53+
}
54+
p {
55+
margin-top: 0.5rem;
56+
margin-bottom: 0.5rem;
57+
}
58+
}
59+
3860
d-contents {
3961
align-self: start;
4062
grid-column: 1 / 4;

0 commit comments

Comments
 (0)