Skip to content

Commit

Permalink
Feature/0.0.8 (#4)
Browse files Browse the repository at this point in the history
* Add async attribute to script tag

* Exclude mermaid block

* 0.0.8
  • Loading branch information
kudoh authored Feb 17, 2022
1 parent 820177a commit 3ac9041
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
7 changes: 5 additions & 2 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ const defaultRendererOptions = {
function renderCode(origRule, rendererOptions) {
return (tokens, idx, options, env, self) => {
const origRendered = origRule(tokens, idx, options, env, self);
if (tokens[idx].tag === 'code' && !tokens[idx].info) {
if (tokens[idx].tag !== 'code') {
return origRendered;
}
if (!tokens[idx].info || tokens[idx].info === 'mermaid') {
return origRendered;
}
if (tokens[idx].content.length === 0) {
Expand Down Expand Up @@ -53,7 +56,7 @@ function initClipboardJS(options) {
throw minified.error;
}
return `<script>${minified.code}</script>
<script src="https://cdn.jsdelivr.net/npm/clipboard@${options.clipboardJSVersion}/dist/clipboard.js"></script>`;
<script async src="https://cdn.jsdelivr.net/npm/clipboard@${options.clipboardJSVersion}/dist/clipboard.js">${minified.code}</script>`;
}

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The plugin consists of the following contents.

`markdown-it custom renderer`

This custom renderer attaches clipboard copy button to code block with language(does nothing for non-language block).
This custom renderer attaches clipboard copy button to code block with language(does nothing for non-language/mermaid block).
Of course, it only supports eleventy markdown template(markdown-it).

The clipboard button is provided by [Material Design Icons](https://materialdesignicons.com/) `content-copy` icon.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eleventy-plugin-code-clipboard",
"version": "0.0.7",
"version": "0.0.8",
"description": "eleventy plugin to copy fence into clipboard",
"homepage": "https://github.com/mamezou-tech/eleventy-plugin-code-clipboard",
"main": ".eleventy.js",
Expand Down
4 changes: 2 additions & 2 deletions test/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

exports[`clipboard.js initialization custom plugin config 1`] = `
"<script>function showTooltip(o,e){o.trigger.className.includes(\\"tooltipped\\")||(o.trigger.children[0].className=\\"tooltipped tooltipped-s\\",o.trigger.children[0].ariaLabel=e)}window.onload=()=>{const o=new ClipboardJS(\\".test-button\\");o.on(\\"success\\",o=>showTooltip(o,\\"Success!!\\")),o.on(\\"error\\",o=>showTooltip(o,\\"Failure!!\\"))};</script>
<script src=\\"https://cdn.jsdelivr.net/npm/[email protected]/dist/clipboard.js\\"></script>"
<script async src=\\"https://cdn.jsdelivr.net/npm/[email protected]/dist/clipboard.js\\">function showTooltip(o,e){o.trigger.className.includes(\\"tooltipped\\")||(o.trigger.children[0].className=\\"tooltipped tooltipped-s\\",o.trigger.children[0].ariaLabel=e)}window.onload=()=>{const o=new ClipboardJS(\\".test-button\\");o.on(\\"success\\",o=>showTooltip(o,\\"Success!!\\")),o.on(\\"error\\",o=>showTooltip(o,\\"Failure!!\\"))};</script>"
`;
exports[`clipboard.js initialization default plugin config 1`] = `
"<script>function showTooltip(o,e){o.trigger.className.includes(\\"tooltipped\\")||(o.trigger.children[0].className=\\"tooltipped tooltipped-s\\",o.trigger.children[0].ariaLabel=e)}window.onload=()=>{const o=new ClipboardJS(\\".code-copy\\");o.on(\\"success\\",o=>showTooltip(o,\\"Copied!\\")),o.on(\\"error\\",o=>showTooltip(o,\\"Failed...\\"))};</script>
<script src=\\"https://cdn.jsdelivr.net/npm/[email protected]/dist/clipboard.js\\"></script>"
<script async src=\\"https://cdn.jsdelivr.net/npm/[email protected]/dist/clipboard.js\\">function showTooltip(o,e){o.trigger.className.includes(\\"tooltipped\\")||(o.trigger.children[0].className=\\"tooltipped tooltipped-s\\",o.trigger.children[0].ariaLabel=e)}window.onload=()=>{const o=new ClipboardJS(\\".code-copy\\");o.on(\\"success\\",o=>showTooltip(o,\\"Copied!\\")),o.on(\\"error\\",o=>showTooltip(o,\\"Failed...\\"))};</script>"
`;
exports[`custom renderer custom renderer config 1`] = `
Expand Down

0 comments on commit 3ac9041

Please sign in to comment.