Skip to content

Commit 8701e7c

Browse files
committed
Add clipboard button to code block
1 parent bcc3437 commit 8701e7c

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

_includes/refactor-content.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102

103103
{% endif %}
104104

105-
<!-- Add lang-badge for code snippets -->
105+
<!-- Add header for code snippets -->
106106

107107
{% if _content contains '<div class="language-' %}
108108
{% assign _code_splits = _content | split: '<div class="language-' %}
@@ -116,7 +116,7 @@
116116
{% capture _tag_head %}<div class="language-{% endcapture %}
117117
{% assign _replacement = '-rouge"><div class="code-header" data-lang="'
118118
| append: _lang
119-
| append: '"></div><div class="highlight">'
119+
| append: '"><button><i class="fa-fw far fa-clipboard"></i></button></div><div class="highlight">'
120120
%}
121121
{% capture _tag_tail %}{{ _snippet | replace: '-rouge"><div class="highlight">', _replacement }}{% endcapture %}
122122
{% assign _new_content = _new_content | append: _tag_head | append: _tag_tail %}

_sass/addon/syntax.scss

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ div {
166166
background: var(--code-header-bg);
167167
border-top-left-radius: $code-radius;
168168
border-top-right-radius: $code-radius;
169+
display: flex;
170+
justify-content: space-between;
171+
align-items: center;
172+
line-height: 1.85rem;
169173

170174
// language badge
171175
&::before {
@@ -176,6 +180,29 @@ div {
176180
text-transform: uppercase;
177181
padding-left: 1em;
178182
}
183+
184+
// clipboard
185+
button {
186+
border: 0;
187+
background-color: inherit;
188+
border-top-right-radius: $code-radius;
189+
color: var(--highlight-lineno-color);
190+
191+
&:hover {
192+
background-color: gray;
193+
color: white;
194+
}
195+
196+
&:focus {
197+
outline: none;
198+
}
199+
200+
i {
201+
font-size: 85%;
202+
}
203+
204+
}
205+
179206
}
180207

181208
@media all and (max-width: 576px) {
@@ -187,7 +214,11 @@ div {
187214

188215
.code-header {
189216
border-radius: 0;
190-
padding: 0 0.4rem;
217+
padding-left: 0.4rem;
218+
219+
button {
220+
border-top-right-radius: 0;
221+
}
191222
}
192223
}
193224
}

0 commit comments

Comments
 (0)