-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
95 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const initCopyCode = () => { | ||
const containers = document.querySelectorAll('.highlight-container'); | ||
|
||
containers.forEach(container => { | ||
const copyBtn = container.querySelector('.copy-code-btn'); | ||
const codeElement = container.querySelector('.highlight code[data-lang]'); | ||
|
||
copyBtn.addEventListener('click', function () { | ||
navigator.clipboard.writeText(codeElement.textContent).then(function () { | ||
/* Chrome doesn't seem to blur automatically, | ||
leaving the button in a focused state. */ | ||
copyBtn.blur(); | ||
|
||
copyBtn.innerText = 'Copied!'; | ||
|
||
setTimeout(function () { | ||
copyBtn.innerText = 'Copy'; | ||
}, 2000); | ||
}, function (error) { | ||
copyBtn.innerText = 'Error'; | ||
}); | ||
}); | ||
}) | ||
} | ||
|
||
export default initCopyCode; |
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 was deleted.
Oops, something went wrong.
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,50 @@ | ||
.highlight-container { | ||
margin: 1em 0; | ||
} | ||
|
||
.highlight { | ||
position: relative; | ||
overflow-x: auto; | ||
border: 2px solid #dddddd; | ||
line-height: 1.6; | ||
|
||
& > div { | ||
padding: 1em 0.3em; | ||
} | ||
|
||
code { | ||
all: unset; | ||
border-radius: 0; | ||
padding: 0 !important; | ||
} | ||
|
||
pre { | ||
margin: 0; /* remove normal pre margin */ | ||
border-radius: 0; | ||
} | ||
|
||
table { | ||
padding: 1em 0.3em !important; | ||
|
||
// td:nth-child(2) code { | ||
// &::after { | ||
// position: absolute; | ||
// top: 0; | ||
// left: 0.5em; | ||
// font-weight: bold; | ||
// content: attr(data-lang); | ||
// } | ||
// } | ||
} | ||
} | ||
|
||
button.copy-code-btn { | ||
/* right-align */ | ||
display: block; | ||
margin-left: auto; | ||
margin-right: 0; | ||
|
||
margin-bottom: -2px; | ||
font-size: 0.6em; | ||
padding: 0.1em 0.3em; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<div class="highlight-container"> | ||
|
||
<button class="copy-code-btn outline">Copy</button> | ||
|
||
{{ $result := transform.HighlightCodeBlock . }} | ||
{{ $result.Wrapped }} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<div class="highlight-container"> | ||
<button class="copy-code-btn outline">Copy</button> | ||
{{- if len .Params | eq 2 }} | ||
{{ highlight (trim .InnerDeindent "\n\r") (.Get 0) (.Get 1) }} | ||
{{- else }} | ||
{{ highlight (trim .InnerDeindent "\n\r") (.Get 0) "" }} | ||
{{- end }} | ||
</div> |