|
3 | 3 | <link type="text/css" rel="stylesheet" href="${base}/css/highlightjs-default.css"> |
4 | 4 | <link rel="stylesheet" href="${base}/css/default.css"> |
5 | 5 |
|
6 | | -<div class="mfrViewer" id="jaxified"> |
7 | | - ${body} |
8 | | -</div> |
| 6 | +## Quirks: |
| 7 | +## |
| 8 | +## ``markdownit`` and its plugins take in teh raw MD content and outputs renderable HTML that can be |
| 9 | +## directly embedded. However, for security conerns, MFR mustn't put the raw content onto the page. |
| 10 | +## It uses XMLHttpRequest to fetch the file content from WB and let ``markdownit`` santize and parse |
| 11 | +## it into the renderable HTML. |
| 12 | +## |
| 13 | +## Cross Origin Resource Sharing (CORS) is enforced for the XMLHttpRequest. One one hand, WB has |
| 14 | +## already been configured to respond with header "Access-Control-Allow-Origin", which allows the |
| 15 | +## MFR domain. On the other hand, OSF hasn't. This is why the request must goes to WB directly. |
| 16 | +## |
| 17 | +<div class="mfrViewer" id="mdViewer"></div> |
9 | 18 |
|
10 | 19 | <script type="text/x-mathjax-config"> |
11 | 20 | MathJax.Hub.Config({ |
|
18 | 27 | <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> |
19 | 28 | <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> |
20 | 29 |
|
21 | | -<!-- Order MATTERS! --> |
22 | 30 | <script src="/static/js/mfr.js"></script> |
23 | 31 | <script src="/static/js/mfr.child.js"></script> |
24 | | -<script src="${base}/js/markdown-it.min.js"></script> <!-- Note Loading markdown-it.min.js from CDN does not work --> |
| 32 | + |
| 33 | +## Note Loading markdown-it.min.js from CDN does not work |
| 34 | +<script src="${base}/js/markdown-it.min.js"></script> |
25 | 35 | <script src="${base}/js/markdown-it-mathjax.js"></script> |
26 | 36 | <script src="${base}/js/markdown-it-sanitizer.min.js"></script> |
27 | 37 | <script src="${base}/js/markdown-it-highlightjs.js"></script> |
28 | 38 | <script src="${base}/js/markdown-it-ins-del.js"></script> |
29 | 39 | <script src="${base}/js/markdown-it-toc.js"></script> |
30 | | -<script src="${base}/js/md.js"></script> |
| 40 | + |
| 41 | +<script> |
| 42 | +
|
| 43 | + ## How to load ``markdown-it``: https://github.com/markdown-it/markdown-it#simple |
| 44 | + var MarkdownIt = window.markdownit; |
| 45 | +
|
| 46 | + var bootstrapTable = function(md) { |
| 47 | + md.renderer.rules.table_open = function() { return "<table class=\"table\">"; }; |
| 48 | + }; |
| 49 | +
|
| 50 | + var markdown = new MarkdownIt("commonmark", {html: true, linkify: true}) |
| 51 | + .use(window.markdownitToc) |
| 52 | + .use(window.markdownitIns) |
| 53 | + .use(window.markdownitHightlightjs) |
| 54 | + .use(window.markdownitSanitizer) |
| 55 | + .use(window.markdownitMathjax()) |
| 56 | + .enable("table") |
| 57 | + .enable("linkify") |
| 58 | + .use(bootstrapTable) |
| 59 | + .disable("strikethrough"); |
| 60 | +
|
| 61 | + var wb_request = new XMLHttpRequest(); |
| 62 | + var wb_download_url = "${url}"; |
| 63 | + wb_request.open("GET", wb_download_url); |
| 64 | + wb_request.responseType = "text"; |
| 65 | + wb_request.withCredentials = true; |
| 66 | + wb_request.onload = function () { |
| 67 | + document.getElementById("mdViewer").innerHTML = markdown.render(wb_request.response); |
| 68 | + ## Force the host to resize |
| 69 | + window.pymChild.sendHeight(); |
| 70 | + }; |
| 71 | + wb_request.send(); |
| 72 | +</script> |
31 | 73 |
|
32 | 74 | <script>MathJax.Hub.Queue(["Typeset",MathJax.Hub,"jaxified"]);</script> |
0 commit comments