| 1 |
import Prism from 'prismjs' |
| 2 |
import 'prismjs/components/prism-clike' |
| 3 |
import 'prismjs/components/prism-javascript' |
| 4 |
import 'prismjs/components/prism-css' |
| 5 |
import 'prismjs/components/prism-php' |
| 6 |
import 'prismjs/components/prism-markup' |
| 7 |
import 'prismjs/plugins/keep-markup/prism-keep-markup' |
| 8 |
|
| 9 |
/** |
| 10 |
* Handle clicks on snippet preview button. |
| 11 |
*/ |
| 12 |
export const handleShowCloudPreview = () => { |
| 13 |
const previewButtons = document.querySelectorAll('.cloud-snippet-preview') |
| 14 |
|
| 15 |
previewButtons.forEach(button => { |
| 16 |
button.addEventListener('click', () => { |
| 17 |
const snippetId = button.getAttribute('data-snippet') |
| 18 |
const snippetLanguage = button.getAttribute('data-lang') |
| 19 |
|
| 20 |
const snippetCodeInput = <HTMLInputElement | null> document.getElementById(`cloud-snippet-code-${snippetId}`) |
| 21 |
const snippetCodeModalTag = document.getElementById('snippet-code-thickbox') |
| 22 |
|
| 23 |
if (!snippetCodeModalTag || !snippetCodeInput) { |
| 24 |
return |
| 25 |
} |
| 26 |
|
| 27 |
snippetCodeModalTag.classList.remove(...snippetCodeModalTag.classList) |
| 28 |
snippetCodeModalTag.classList.add(`language-${snippetLanguage}`) |
| 29 |
snippetCodeModalTag.textContent = snippetCodeInput.value |
| 30 |
|
| 31 |
if ('markup' === snippetLanguage) { |
| 32 |
snippetCodeModalTag.innerHTML = `<xmp>${snippetCodeInput.value}</xmp>` |
| 33 |
} |
| 34 |
|
| 35 |
if ('php' === snippetLanguage) { |
| 36 |
// Check if there is an opening php tag if not add it. |
| 37 |
if (!snippetCodeInput.value.startsWith('<?php')) { |
| 38 |
snippetCodeModalTag.textContent = `<?php\n${snippetCodeInput.value}` |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
Prism.highlightElement(snippetCodeModalTag) |
| 43 |
}) |
| 44 |
}) |
| 45 |
} |
| 46 |
|