8000 Merge pull request #3101 from minrk/marked · ipython/ipython@2d6f354 · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit 2d6f354

Browse files
committed
Merge pull request #3101 from minrk/marked
use marked / highlight.js instead of pagedown and prettify
2 parents c43e07e + d10958b commit 2d6f354

File tree

13 files changed

+204
-1693
lines changed

13 files changed

+204
-1693
lines changed

IPython/frontend/html/notebook/static/css/codemirror-ipython.css

Lines changed: 0 additions & 40 deletions
This file was deleted.

IPython/frontend/html/notebook/static/css/style.min.css

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

IPython/frontend/html/notebook/static/js/notebookmain.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ $(document).ready(function () {
4242
var baseProjectUrl = $('body').data('baseProjectUrl')
4343

4444
IPython.page = new IPython.Page();
45-
IPython.markdown_converter = new Markdown.Converter();
4645
IPython.layout_manager = new IPython.LayoutManager();
4746
IPython.pager = new IPython.Pager('div#pager', 'div#pager_splitter');
4847
IPython.quick_help = new IPython.QuickHelp('span#quick_help_area');
@@ -94,6 +93,23 @@ $(document).ready(function () {
9493

9594
$([IPython.events]).on('notebook_loaded.Notebook', first_load);
9695
IPython.notebook.load_notebook($('body').data('notebookId'));
96+
97+
if (marked) {
98+
marked.setOptions({
99+
gfm : true,
100+
tables: true,
101+
langPrefix: "language-",
102+
highlight: function(code, lang) {
103+
var highlighted;
104+
if (lang) {
105+
highlighted = hljs.highlight(lang, code, false);
106+
} else {
107+
highlighted = hljs.highlightAuto(code);
108+
}
109+
return highlighted.value;
110+
}
111+
})
112+
}
97113

98114
});
99115

IPython/frontend/html/notebook/static/js/textcell.js

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ var IPython = (function (IPython) {
298298

299299
MarkdownCell.options_default = {
300300
cm_config: {
301-
mode: 'markdown'
301+
mode: 'gfm'
302302
},
303303
placeholder: "Type *Markdown* and LaTeX: $\\alpha^2$"
304304
}
@@ -315,9 +315,9 @@ var IPython = (function (IPython) {
315315
if (this.rendered === false) {
316316
var text = this.get_text();
317317
if (text === "") { text = this.placeholder; }
318-
text = IPython.mathjaxutils.remove_math(text)
319-
var html = IPython.markdown_converter.makeHtml(text);
320-
html = IPython.mathjaxutils.replace_math(html)
318+
text = IPython.mathjaxutils.remove_math(text);
319+
var html = marked.parser(marked.lexer(text));
320+
html = IPython.mathjaxutils.rep 10000 lace_math(html);
321321
try {
322322
this.set_rendered(html);
323323
} catch (e) {
@@ -329,18 +329,6 @@ var IPython = (function (IPython) {
329329
}
330330
this.element.find('div.text_cell_input').hide();
331331
this.element.find("div.text_cell_render").show();
332-
var code_snippets = this.element.find("pre > code");
333-
code_snippets.replaceWith(function () {
334-
var code = $(this).html();
335-
/* Substitute br for newlines and   for spaces
336-
before highlighting, since prettify doesn't
337-
preserve those on all browsers */
338-
code = code.replace(/(\r\n|\n|\r)/gm, "<br/>");
339-
code = code.replace(/ /gm, '&nbsp;');
340-
code = prettyPrintOne(code);
341-
342-
return '<code class="prettyprint">' + code + '</code>';
343-
});
344332
this.typeset()
345333
this.rendered = true;
346334
}
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/*
2+
3+
Original style from softwaremaniacs.org (c) Ivan Sagalaev <Maniac@SoftwareManiacs.Org>
4+
Adapted from GitHub theme
5+
6+
*/
7+
8+
pre code {
9+
display: block;
10+
padding: 0.5em;
11+
}
12+
13+
.highlight-base,
14+
pre code,
15+
pre .subst,
16+
pre .tag .title,
17+
pre .lisp .title,
18+
pre .clojure .built_in,
19+
pre .nginx .title {
20+
color: black;
21+
}
22+
23+
.highlight-string,
24+
pre .string,
25+
pre .constant,
26+
pre .parent,
27+
pre .tag .value,
28+
pre .rules .value,
29+
pre .rules .value .number,
30+
pre .preprocessor,
31+
pre .ruby .symbol,
32+
pre .ruby .symbol .string,
33+
pre .aggregate,
34+
pre .template_tag,
35+
pre .django .variable,
36+
pre .smalltalk .class,
37+
pre .addition,
38+
pre .flow,
39+
pre .stream,
40+
pre .bash .variable,
41+
pre .apache .tag,
42+
pre .apache .cbracket,
43+
pre .tex .command,
44+
pre .tex .special,
45+
pre .erlang_repl .function_or_atom,
46+
pre .markdown .header {
47+
color: #BA2121;
48+
}
49+
50+
.highlight-comment,
51+
pre .comment,
52+
pre .annotation,
53+
pre .template_comment,
54+
pre .diff .header,
55+
pre .chunk,
56+
pre .markdown .blockquote {
57+
color: #408080;
58+
font-style: italic;
59+
}
60+
61+
.highlight-number,
62+
pre .number,
63+
pre .date,
64+
pre .regexp,
65+
pre .literal,
66+
pre .smalltalk .symbol,
67+
pre .smalltalk .char,
68+
pre .go .constant,
69+
pre .change,
70+
pre .markdown .bullet,
71+
pre .markdown .link_url {
72+
color: #080;
73+
}
74+
75+
pre .label,
76+
pre .javadoc,
77+
pre .ruby .string,
78+
pre .decorator,
79+
pre .filter .argument,
80+
pre .localvars,
81+
pre .array,
82+
pre .attr_selector,
83+
pre .important,
84+
pre .pseudo,
85+
pre .pi,
86+
pre .doctype,
87+
pre .deletion,
88+
pre .envvar,
89+
pre .shebang,
90+
pre .apache .sqbracket,
91+
pre .nginx .built_in,
92+
pre .tex .formula,
93+
pre .erlang_repl .reserved,
94+
pre .prompt,
95+
pre .markdown .link_label,
96+
pre .vhdl .attribute,
97+
pre .clojure .attribute,
98+
pre .coffeescript .property {
99+
color: #88F
100+
}
101+
102+
.highlight-keyword,
103+
pre .keyword,
104+
pre .id,
105+
pre .phpdoc,
106+
pre .aggregate,
107+
pre .css .tag,
108+
pre .javadoctag,
109+
pre .phpdoc,
110+
pre .yardoctag,
111+
pre .smalltalk .class,
112+
pre .winutils,
113+
pre .bash .variable,
114+
pre .apache .tag,
115+
pre .go .typename,
116+
pre .tex .command,
117+
pre .markdown .strong,
118+
pre .request,
119+
pre .status {
120+
color: #008000;
121+
font-weight: bold;
122+
}
123+
124+
.highlight-builtin,
125+
pre .built_in {
126+
color: #008000;
127+
}
128+
129+
pre .markdown .emphasis {
130+
font-style: italic;
131+
}
132+
133+
pre .nginx .built_in {
134+
font-weight: normal;
135+
}
136+
137+
pre .coffeescript .javascript,
138+
pre .javascript .xml,
139+
pre .tex .formula,
140+
pre .xml .javascript,
141+
pre .xml .vbscript,
142+
pre .xml .css,
143+
pre .xml .cdata {
144+
opacity: 0.5;
145+
}
146+
147+
/* apply the same style to codemirror */
148+
149+
.cm-s-ipython span.cm-variable { .highlight-base()}
150+
.cm-s-ipython span.cm-keyword { .highlight-keyword() }
151+
.cm-s-ipython span.cm-number { .highlight-number() }
152+
.cm-s-ipython span.cm-comment { .highlight-comment() }
153+
.cm-s-ipython span.cm-string { .highlight-string()}
154+
.cm-s-ipython span.cm-builtin { .highlight-builtin() }
155+
.cm-s-ipython span.cm-error { color: #f00; }
156+
.cm-s-ipython span.cm-operator {color: #AA22FF; font-weight: bold;}
157+
.cm-s-ipython span.cm-meta {color: #AA22FF;}

IPython/frontend/html/notebook/static/less/notebook.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
@import "variables.less";
8-
8+
@import "highlight.less";
99

1010
body {
1111
background-color:@notebook_background;

IPython/frontend/html/notebook/static/pagedown/LICENSE.txt

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0