diff options
author | Cheng-Han, Wu | 2016-06-21 21:44:06 +0800 |
---|---|---|
committer | Cheng-Han, Wu | 2016-06-21 21:44:06 +0800 |
commit | 3424cdd7713421d3fc88a501c1cd7606c943a05e (patch) | |
tree | 9dbdda181307dfe9903bdd05aedee1a0c070ede1 /public | |
parent | 558304ff62a648e604b03afe3372ef9566aea850 (diff) |
Add support of embed pdf
Diffstat (limited to 'public')
-rw-r--r-- | public/docs/features.md | 4 | ||||
-rw-r--r-- | public/js/extra.js | 41 | ||||
-rw-r--r-- | public/js/index.js | 18 | ||||
-rw-r--r-- | public/views/foot.ejs | 1 | ||||
-rw-r--r-- | public/views/pretty.ejs | 1 |
5 files changed, 50 insertions, 15 deletions
diff --git a/public/docs/features.md b/public/docs/features.md index 1aa3c220..07e7d669 100644 --- a/public/docs/features.md +++ b/public/docs/features.md @@ -186,6 +186,10 @@ alert(s); ### Speakerdeck {%speakerdeck sugarenia/xxlcss-how-to-scale-css-and-keep-your-sanity %} +### PDF +**Caution: this might be blocked by your browser if not using https url.** +{%pdf https://papers.nips.cc/paper/5346-sequence-to-sequence-learning-with-neural-networks.pdf %} + ## MathJax You can render *LaTeX* mathematical expressions using **MathJax**, as on [math.stackexchange.com](http://math.stackexchange.com/): diff --git a/public/js/extra.js b/public/js/extra.js index e67eee53..b30a8cb0 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -83,6 +83,20 @@ function slugifyWithUTF8(text) { return newText; } +function isValidURL(str) { + var pattern = new RegExp('^(https?:\\/\\/)?' + // protocol + '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name + '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address + '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path + '(\\?[;&a-z\\d%_.~+=-]*)?' + // query string + '(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator + if (!pattern.test(str)) { + return false; + } else { + return true; + } +} + //parse meta function parseMeta(md, edit, view, toc, tocAffix) { var lang = null; @@ -403,6 +417,16 @@ function finishView(view) { } }); }); + //pdf + view.find(".pdf.raw").removeClass("raw") + .each(function (key, value) { + var url = $(value).attr('data-pdfurl'); + var inner = $('<div></div>'); + $(this).append(inner); + PDFObject.embed(url, inner, { + height: '400px' + }); + }); //render title document.title = renderTitle(view); } @@ -901,6 +925,20 @@ var speakerdeckPlugin = new Plugin( return div[0].outerHTML; } ); +//pdf +var pdfPlugin = new Plugin( + // regexp to match + /{%pdf\s*([\d\D]*?)\s*%}/, + + // this function will be called when something matches + function (match, utils) { + var pdfurl = match[1]; + if (!isValidURL(pdfurl)) return match[0]; + var div = $('<div class="pdf raw"></div>'); + div.attr('data-pdfurl', pdfurl); + return div[0].outerHTML; + } +); //yaml meta, from https://github.com/eugeneware/remarkable-meta function get(state, line) { @@ -949,4 +987,5 @@ md.use(vimeoPlugin); md.use(gistPlugin); md.use(tocPlugin); md.use(slidesharePlugin); -md.use(speakerdeckPlugin);
\ No newline at end of file +md.use(speakerdeckPlugin); +md.use(pdfPlugin);
\ No newline at end of file diff --git a/public/js/index.js b/public/js/index.js index dc5f928c..43296af4 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -152,6 +152,10 @@ var supportExternals = [ { text: '{%speakerdeck speakerdeckid %}', search: 'speakerdeck' + }, + { + text: '{%pdf pdfurl %}', + search: 'pdf' } ]; var supportExtraTags = [ @@ -1836,20 +1840,6 @@ function importFromUrl(url) { }); } -function isValidURL(str) { - var pattern = new RegExp('^(https?:\\/\\/)?' + // protocol - '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name - '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address - '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path - '(\\?[;&a-z\\d%_.~+=-]*)?' + // query string - '(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator - if (!pattern.test(str)) { - return false; - } else { - return true; - } -} - //mode ui.toolbar.mode.click(function () { toggleMode(); diff --git a/public/views/foot.ejs b/public/views/foot.ejs index cb53acb1..4b8a566f 100644 --- a/public/views/foot.ejs +++ b/public/views/foot.ejs @@ -59,6 +59,7 @@ <script src="<%- url %>/vendor/sequence-diagrams/sequence-diagram-min.js" defer></script> <script src="<%- url %>/vendor/flowchart/release/flowchart.min.js" defer></script> <script src="<%- url %>/vendor/viz.js/viz.js" defer></script> +<script src="<%- url %>/vendor/pdfobject/pdfobject.min.js" defer></script> <script src="<%- url %>/vendor/file-saver/FileSaver.min.js" defer></script> <script src="<%- url %>/vendor/store-js/store.min.js" defer></script> <script src="<%- url %>/vendor/js-url/url.min.js" defer></script> diff --git a/public/views/pretty.ejs b/public/views/pretty.ejs index 5ba2e8e1..7a3b96b7 100644 --- a/public/views/pretty.ejs +++ b/public/views/pretty.ejs @@ -116,6 +116,7 @@ <script src="<%- url %>/vendor/sequence-diagrams/sequence-diagram-min.js" defer></script> <script src="<%- url %>/vendor/flowchart/release/flowchart.min.js" defer></script> <script src="<%- url %>/vendor/viz.js/viz.js" defer></script> +<script src="<%- url %>/vendor/pdfobject/pdfobject.min.js" defer></script> <script src="<%- url %>/vendor/md-toc.js" defer></script> <script src="<%- url %>/js/common.js" defer></script> <script src="<%- url %>/js/extra.js" defer></script> |