Skip to content

Commit 7cd21a8

Browse files
Removing bundle and reworking
Instead of bundling up assets, serve the smaller ones. Larger ones can be loaded from cdn.
1 parent 49ae179 commit 7cd21a8

File tree

14 files changed

+835
-25781
lines changed

14 files changed

+835
-25781
lines changed

mfr/extensions/md/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
## Markdown plus Mathjax readme
3+
4+
Most of the packages are in there to try to match what the OSF wiki is doing. The two exceptions being markdown-it-highlightjs.js and markdown-it-mathjax.js. The highlighter matches the functionality of what is on the osf however, and the markdown-it-mathjax.js increases functionality with mathjax.
5+
6+
to get all the libraries needed:
7+
8+
```
9+
10+
npm install @centerforopenscience/[email protected]
11+
npm install [email protected]
12+
npm install [email protected]
13+
npm install [email protected]
14+
npm install [email protected]
15+
```
16+
17+
To add a new library, you need to make sure its loadable in md.js somehow, either through exporting via `root.<name>` or some other means. Some of the markdown plugins added have custom code in them to load them into `root`.
18+
19+
Libraries should try to use the same version as the ones used on the OSF. The plugins do not matter as much, but `markdown-it` and `Mathjax` you should try to match exactly because styling can change between versions.
20+
21+
To add a new library that is not already set up to export to `root` can be a bit tricky, but the gist of it is, wrap the plugin in this code:
22+
23+
```
24+
;(function (root, factory) {
25+
if (typeof exports === 'object') {
26+
module.exports = factory()
27+
} else {
28+
root.<PLUGIN_NAME> = factory()
29+
}
30+
})(this, function () {
31+
32+
33+
return function(md){
34+
35+
.....
36+
}
37+
38+
})
39+
```
40+
41+
And then modify it to work in this context. See other plugins for examples.
42+
43+
Then, in md.js, you can add a plugin to the markdown renderer by adding a `.use(<window.<PLUGIN_NAME>)`

mfr/extensions/md/render.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
import os
22

33
import bleach
4-
# import markdown
5-
# from markdown.extensions import Extension
6-
74
from mako.lookup import TemplateLookup
85

96
from mfr.core import extension
107

118

12-
# class EscapeHtml(Extension):
13-
# def extendMarkdown(self, md, md_globals):
14-
# del md.preprocessors['html_block']
15-
# del md.inlinePatterns['html']
16-
17-
189
class MdRenderer(extension.BaseRenderer):
1910

2011
TEMPLATE = TemplateLookup(
@@ -24,7 +15,6 @@ class MdRenderer(extension.BaseRenderer):
2415

2516
def __init__(self, *args, **kwargs):
2617
super().__init__(*args, **kwargs)
27-
# self.metrics.add('markdown_version', markdown.version)
2818

2919
def render(self):
3020
"""Render a markdown file to html."""
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
@charset "utf-8";
2+
3+
/**
4+
* markdown.css
5+
*
6+
* Found on github at https://github.com/jasonm23/markdown-css-themes
7+
*
8+
* This program is free software: you can redistribute it and/or modify it under
9+
* the terms of the GNU Lesser General Public License as published by the Free
10+
* Software Foundation, either version 3 of the License, or (at your option) any
11+
* later version.
12+
*
13+
* This program is distributed in the hope that it will be useful, but WITHOUT
14+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15+
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
16+
* details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with this program. If not, see http://gnu.org/licenses/lgpl.txt.
20+
*
21+
* @project Weblog and Open Source Projects of Florian Wolters
22+
* @version GIT: $Id$
23+
* @package xhtml-css
24+
* @author Florian Wolters <[email protected]>
25+
* @copyright 2012 Florian Wolters
26+
* @cssdoc version 1.0-pre
27+
* @license http://gnu.org/licenses/lgpl.txt GNU Lesser General Public License
28+
* @link http://github.com/FlorianWolters/jekyll-bootstrap-theme
29+
* @media all
30+
* @valid true
31+
*/
32+
33+
34+
35+
36+
.mfrViewer {
37+
font-family: 'Open Sans';
38+
padding:1em;
39+
background:#fefefe;
40+
height: auto;
41+
word-wrap: break-word;
42+
}
43+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
;(function (root, factory) {
2+
if (typeof exports === 'object') {
3+
module.exports = factory()
4+
} else {
5+
root.markdownitHightlightjs = factory()
6+
}
7+
})(this, function () {
8+
9+
const maybe = f => {
10+
try {
11+
return f()
12+
} catch (e) {
13+
return false
14+
}
15+
}
16+
17+
// Highlight with given language.
18+
const highlight = (code, lang) =>
19+
maybe(() => hljs.highlight(lang, code, true).value) || ''
20+
21+
// Highlight with given language or automatically.
22+
const highlightAuto = (code, lang) =>
23+
lang
24+
? highlight(code, lang)
25+
: maybe(() => hljs.highlightAuto(code).value) || ''
26+
27+
// Wrap a render function to add `hljs` class to code blocks.
28+
const wrap = render =>
29+
function (...args) {
30+
return render.apply(this, args)
31+
.replace('<code class="', '<code class="hljs ')
32+
.replace('<code>', '<code class="hljs">')
33+
}
34+
var defaults = {
35+
auto: true,
36+
code: true
37+
}
38+
39+
return function(md, opts){
40+
opts = Object.assign({}, defaults, opts)
41+
42+
md.options.highlight = opts.auto ? highlightAuto : highlight
43+
md.renderer.rules.fence = wrap(md.renderer.rules.fence)
44+
45+
if (opts.code) {
46+
md.renderer.rules.code_block = wrap(md.renderer.rules.code_block)
47+
}
48+
}
49+
50+
})

0 commit comments

Comments
 (0)