|
83 | 83 | filter: invert(1);
|
84 | 84 | }
|
85 | 85 |
|
| 86 | + .unselectable { |
| 87 | + -webkit-touch-callout: none !important; |
| 88 | + -webkit-user-select: none !important; |
| 89 | + -khtml-user-select: none !important; |
| 90 | + -moz-user-select: none !important; |
| 91 | + -ms-user-select: none !important; |
| 92 | + user-select: none !important; |
| 93 | + } |
| 94 | + |
86 | 95 | .maincontainer {
|
87 | 96 | padding-right: 4px;
|
88 | 97 | padding-left: 4px;
|
|
3621 | 3630 | return words.length;
|
3622 | 3631 | }
|
3623 | 3632 |
|
| 3633 | + function copyMarkdownCode(btn) |
| 3634 | + { |
| 3635 | + const codeContainer = btn.parentElement.querySelector('pre code'); |
| 3636 | + //selectElementContents(codeContainer); |
| 3637 | + navigator.clipboard.writeText(codeContainer.innerText); |
| 3638 | + } |
| 3639 | + |
3624 | 3640 | function simpleMarkdown(text) {
|
3625 | 3641 | const escapeHTML = (str) => str.replace(/</g, "<").replace(/>/g, ">");
|
3626 | 3642 | const highlightCode = (code) => {
|
| 3643 | + let cpybtn = `<button class="unselectable" onclick="return copyMarkdownCode(this)" style="float:right;">Copy</button>`; |
3627 | 3644 | code = escapeHTML(code);
|
3628 | 3645 | code = code.replace(/</g, "<").replace(/>/g, ">");
|
3629 | 3646 | code = code.replace(/\t/g, " ");
|
|
3632 | 3649 | code = code.replace(/\s\/\/(.*)/gm, " <rem>//$1</rem>");
|
3633 | 3650 | code = code.replace(/(\s?)(function|procedure|return|exit|if|then|else|end|loop|while|or|and|case|when)(\s)/gim, "$1<b>$2</b>$3");
|
3634 | 3651 | code = code.replace(/(\s?)(var|let|const|=>|for|next|do|while|loop|continue|break|switch|try|catch|finally)(\s)/gim, "$1<b>$2</b>$3");
|
3635 |
| - return `<pre><code>${code}</code></pre>`; |
| 3652 | + return `<pre>${cpybtn}<code>${code}</code></pre>`; |
3636 | 3653 | };
|
3637 | 3654 | const convertMarkdownTableToHtml = (t) => {
|
3638 | 3655 | let hsep = /^[\s]*\|(?:[\s]*[-:]+[-:|\s]*)+\|[\s]*$/gm;let l=/^[\s]*\|(.*)\|[\s]*$/gm,r=t.split(/\r?\n|\r/),e="<table class='tablelines'>";for(let o of r){let hs=o.match(hsep);if(hs){continue;}let d=o.match(l);if(d){let i=d[0].split("|").map(t=>t.trim());e+=`<tr class='tablelines'><td class='tablelines'>${i.join("</td><td class='tablelines'>")}</td></tr>`}}return e+"</table>"
|
|
0 commit comments