Add 'generate markdown' button
Boris Kubiak kubiakboris@gmail.com
Thu, 05 Mar 2020 14:33:21 +0100
2 files changed,
8 insertions(+),
5 deletions(-)
M
index.html
→
index.html
@@ -13,6 +13,7 @@ npm/lzma@2.3.2/src/lzma.min.js,
npm/slim-select@1.25.0/dist/slimselect.min.js, npm/clipboard@2/dist/clipboard.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/mode/meta.min.js "></script>@@ -34,7 +35,8 @@ <div id="footer">
<label for="language"></label ><select id="language"></select> <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 id="copy" style="display: none"> <input
M
index.js
→
index.js
@@ -59,13 +59,13 @@ hideCopyBar(true);
}); }; -const generateLink = () => { +const generateLink = mode => { compress(editor.getValue(), (base64, err) => { if (err) { alert('Failed to compress data: ' + err); return; } - const url = buildUrl(base64); + const url = buildUrl(base64, mode); showCopyBar(url); }); };@@ -94,10 +94,11 @@ }, 800);
}; // Build a shareable URL -const buildUrl = rawData => { - return `${location.protocol}//${location.host}${location.pathname}?lang=${encodeURIComponent( +const buildUrl = (rawData, mode) => { + const url = `${location.protocol}//${location.host}${location.pathname}?lang=${encodeURIComponent( select.selected() )}#${rawData}`; + return mode === 'markdown' ? `[paste](${url})` : url; }; // Transform a compressed base64 string into a plain text string