-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcode_tabs.html
More file actions
99 lines (83 loc) · 2.36 KB
/
code_tabs.html
File metadata and controls
99 lines (83 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<div class="tabs">
{% assign codes = "python,javascript,cpp,rust,java,shell" | split: "," %}
{% for code_name in codes %}
{% if include[code_name] %}
<input type="radio" id="tab_{{ include.id }}_{{ forloop.index }}" name="tab_{{ include.id }}" {% if forloop.first %}checked{% endif %}>
<label for="tab_{{ include.id }}_{{ forloop.index }}">{{ code_name }}</label>
{% endif %}
{% endfor %}
{% for code_name in codes %}
{% if include[code_name] %}
<div class="tab-content">
<div class="code-container">
<button class="copy-btn"
onclick="navigator.clipboard.writeText(this.nextElementSibling.firstElementChild.innerText)">Copy</button>
<pre><code class="language-{{ code_name }}">{{ include[code_name] | escape }}</code></pre>
</div>
</div>
{% endif %}
{% endfor %}
<style scoped>
input[type="radio"] {
position: absolute;
opacity: 0;
pointer-events: none;
}
label {
display: inline-block;
padding: 10px;
cursor: pointer;
}
label:hover {
background: #31343f;
}
input[type="radio"]:checked+label {
background: #31343f;
border-bottom: 1px solid transparent;
}
.tab-content {
background: #31343f;
padding: 10px;
}
.tab-content pre {
margin: 0;
overflow-x: auto;
}
.tab-content code {
display: block;
white-space: pre;
}
input[type="radio"]:nth-of-type(1):checked~.tab-content:nth-of-type(1),
input[type="radio"]:nth-of-type(2):checked~.tab-content:nth-of-type(2),
input[type="radio"]:nth-of-type(3):checked~.tab-content:nth-of-type(3),
input[type="radio"]:nth-of-type(4):checked~.tab-content:nth-of-type(4),
input[type="radio"]:nth-of-type(5):checked~.tab-content:nth-of-type(5),
input[type="radio"]:nth-of-type(6):checked~.tab-content:nth-of-type(6) {
display: block;
}
.tab-content {
display: none;
}
.code-container {
position: relative;
}
.copy-btn {
position: absolute;
top: 10px;
right: 10px;
padding: 5px 10px;
background-color: #007bff;
color: white;
border: none;
border-radius: 3px;
cursor: pointer;
display: none;
}
.code-container:hover .copy-btn {
display: inline-block;
}
.copy-btn:hover {
background-color: #0056b3;
}
</style>
</div>