-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial commit for code examples (#53)
* Show multi code examples
- Loading branch information
Showing
5 changed files
with
159 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,3 @@ aux_links_new_tab: true | |
|
||
plugins: | ||
- jekyll-sitemap | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<style> | ||
.tabs input[type="radio"] { | ||
position: absolute; | ||
opacity: 0; | ||
pointer-events: none; | ||
} | ||
|
||
.tabs label { | ||
display: inline-block; | ||
padding: 10px; | ||
cursor: pointer; | ||
} | ||
|
||
.tabs label:hover { | ||
background: #31343f; | ||
} | ||
|
||
.tabs input[type="radio"]:checked+label { | ||
background: #31343f; | ||
border-bottom: 1px solid transparent; | ||
} | ||
|
||
.tabs .tab-content { | ||
background: #31343f; | ||
padding: 10px; | ||
} | ||
|
||
.tabs .tab-content pre { | ||
margin: 0; | ||
overflow-x: auto; | ||
} | ||
|
||
.tabs .tab-content code { | ||
display: block; | ||
white-space: pre; | ||
} | ||
|
||
.tabs input[type="radio"]:nth-of-type(1):checked~.tab-content:nth-of-type(1), | ||
.tabs input[type="radio"]:nth-of-type(2):checked~.tab-content:nth-of-type(2), | ||
.tabs input[type="radio"]:nth-of-type(3):checked~.tab-content:nth-of-type(3) | ||
.tabs input[type="radio"]:nth-of-type(4):checked~.tab-content:nth-of-type(4) | ||
.tabs input[type="radio"]:nth-of-type(5):checked~.tab-content:nth-of-type(5) | ||
.tabs input[type="radio"]:nth-of-type(6):checked~.tab-content:nth-of-type(6) { | ||
display: block; | ||
} | ||
|
||
.tabs .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 class="tabs"> | ||
{% assign codes = "python,javascript,cpp,rust" | split: "," %} | ||
|
||
{% for code_name in codes %} | ||
{% if include[code_name] %} | ||
<input type="radio" id="tab{{ include.id }}{{ forloop.index }}" name="tab" {% 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 %} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters