Add 'generate markdown' button
parent
c815b7c125
commit
eb3e5fa5f0
|
|
@ -13,6 +13,7 @@ npm/lzma@2.3.2/src/lzma.min.js,
|
||||||
npm/slim-select@1.25.0/dist/slimselect.min.js,
|
npm/slim-select@1.25.0/dist/slimselect.min.js,
|
||||||
npm/clipboard@2/dist/clipboard.min.js,
|
npm/clipboard@2/dist/clipboard.min.js,
|
||||||
npm/codemirror@5.51.0/lib/codemirror.min.js,
|
npm/codemirror@5.51.0/lib/codemirror.min.js,
|
||||||
|
npm/codemirror@5.51.0/addon/mode/overlay.min.js,
|
||||||
npm/codemirror@5.51.0/addon/mode/loadmode.min.js,
|
npm/codemirror@5.51.0/addon/mode/loadmode.min.js,
|
||||||
npm/codemirror@5.51.0/mode/meta.min.js
|
npm/codemirror@5.51.0/mode/meta.min.js
|
||||||
"></script>
|
"></script>
|
||||||
|
|
@ -34,7 +35,8 @@ npm/codemirror@5.51.0/theme/dracula.min.css
|
||||||
<label for="language"></label
|
<label for="language"></label
|
||||||
><select id="language"></select>
|
><select id="language"></select>
|
||||||
<span class="grow"></span>
|
<span class="grow"></span>
|
||||||
<button onclick="generateLink()" type="button">Generate link</button>
|
<button onclick="generateLink('url')" type="button">Generate link</button>
|
||||||
|
<button onclick="generateLink('markdown')" type="button">Generate markdown</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="copy" style="display: none">
|
<div id="copy" style="display: none">
|
||||||
<input
|
<input
|
||||||
|
|
|
||||||
9
index.js
9
index.js
|
|
@ -59,13 +59,13 @@ const initClipboard = () => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const generateLink = () => {
|
const generateLink = mode => {
|
||||||
compress(editor.getValue(), (base64, err) => {
|
compress(editor.getValue(), (base64, err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
alert('Failed to compress data: ' + err);
|
alert('Failed to compress data: ' + err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const url = buildUrl(base64);
|
const url = buildUrl(base64, mode);
|
||||||
showCopyBar(url);
|
showCopyBar(url);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
@ -94,10 +94,11 @@ const hideCopyBar = success => {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Build a shareable URL
|
// Build a shareable URL
|
||||||
const buildUrl = rawData => {
|
const buildUrl = (rawData, mode) => {
|
||||||
return `${location.protocol}//${location.host}${location.pathname}?lang=${encodeURIComponent(
|
const url = `${location.protocol}//${location.host}${location.pathname}?lang=${encodeURIComponent(
|
||||||
select.selected()
|
select.selected()
|
||||||
)}#${rawData}`;
|
)}#${rawData}`;
|
||||||
|
return mode === 'markdown' ? `[paste](${url})` : url;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Transform a compressed base64 string into a plain text string
|
// Transform a compressed base64 string into a plain text string
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue