##// END OF EJS Templates
Allow direct print of the notebook....
Allow direct print of the notebook. this improve the current css of the print page and add css to the classical notebook with print as target to get a better print view ant the ability to directly print a notebook without going through the print view

File last commit:

r6058:ecc950ec
r7780:a59dd57c
Show More
markdown.js
246 lines | 5.9 KiB | application/javascript | JavascriptLexer
Fernando Perez
Update CodeMirror code to v2.15
r4933 CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
var htmlMode = CodeMirror.getMode(cmCfg, { name: 'xml', htmlMode: true });
var header = 'header'
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941 , code = 'comment'
Fernando Perez
Update CodeMirror code to v2.15
r4933 , quote = 'quote'
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941 , list = 'string'
Fernando Perez
Update CodeMirror code to v2.15
r4933 , hr = 'hr'
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941 , linktext = 'link'
, linkhref = 'string'
Fernando Perez
Update CodeMirror code to v2.15
r4933 , em = 'em'
, strong = 'strong'
, emstrong = 'emstrong';
var hrRE = /^[*-=_]/
, ulRE = /^[*-+]\s+/
Brian Granger
Updating CodeMirror to c813c94 to fix #1344.
r6058 , olRE = /^[0-9]+\.\s+/
Fernando Perez
Update CodeMirror code to v2.15
r4933 , headerRE = /^(?:\={3,}|-{3,})$/
, codeRE = /^(k:\t|\s{4,})/
, textRE = /^[^\[*_\\<>`]+/;
function switchInline(stream, state, f) {
state.f = state.inline = f;
return f(stream, state);
}
function switchBlock(stream, state, f) {
state.f = state.block = f;
return f(stream, state);
}
// Blocks
function blockNormal(stream, state) {
if (stream.match(codeRE)) {
stream.skipToEnd();
return code;
}
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941
Fernando Perez
Update CodeMirror code to v2.15
r4933 if (stream.eatSpace()) {
return null;
}
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941
Fernando Perez
Update CodeMirror code to v2.15
r4933 if (stream.peek() === '#' || stream.match(headerRE)) {
stream.skipToEnd();
return header;
}
if (stream.eat('>')) {
state.indentation++;
return quote;
}
if (stream.peek() === '[') {
return switchInline(stream, state, footnoteLink);
}
if (hrRE.test(stream.peek())) {
var re = new RegExp('(?:\s*['+stream.peek()+']){3,}$');
if (stream.match(re, true)) {
return hr;
}
}
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941
Fernando Perez
Update CodeMirror code to v2.15
r4933 var match;
if (match = stream.match(ulRE, true) || stream.match(olRE, true)) {
state.indentation += match[0].length;
return list;
}
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941
Fernando Perez
Update CodeMirror code to v2.15
r4933 return switchInline(stream, state, state.inline);
}
function htmlBlock(stream, state) {
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941 var style = htmlMode.token(stream, state.htmlState);
if (style === 'tag' && state.htmlState.type !== 'openTag' && !state.htmlState.context) {
state.f = inlineNormal;
Fernando Perez
Update CodeMirror code to v2.15
r4933 state.block = blockNormal;
}
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941 return style;
Fernando Perez
Update CodeMirror code to v2.15
r4933 }
// Inline
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941 function getType(state) {
return state.strong ? (state.em ? emstrong : strong)
: (state.em ? em : null);
}
Fernando Perez
Update CodeMirror code to v2.15
r4933
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941 function handleText(stream, state) {
Fernando Perez
Update CodeMirror code to v2.15
r4933 if (stream.match(textRE, true)) {
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941 return getType(state);
Fernando Perez
Update CodeMirror code to v2.15
r4933 }
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941 return undefined;
}
Fernando Perez
Update CodeMirror code to v2.15
r4933
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941 function inlineNormal(stream, state) {
var style = state.text(stream, state)
if (typeof style !== 'undefined')
return style;
Fernando Perez
Update CodeMirror code to v2.15
r4933 var ch = stream.next();
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941
Fernando Perez
Update CodeMirror code to v2.15
r4933 if (ch === '\\') {
stream.next();
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941 return getType(state);
Fernando Perez
Update CodeMirror code to v2.15
r4933 }
if (ch === '`') {
return switchInline(stream, state, inlineElement(code, '`'));
}
if (ch === '[') {
return switchInline(stream, state, linkText);
}
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941 if (ch === '<' && stream.match(/^\w/, false)) {
stream.backUp(1);
return switchBlock(stream, state, htmlBlock);
}
Fernando Perez
Update CodeMirror code to v2.15
r4933
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941 var t = getType(state);
Fernando Perez
Update CodeMirror code to v2.15
r4933 if (ch === '*' || ch === '_') {
if (stream.eat(ch)) {
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941 return (state.strong = !state.strong) ? getType(state) : t;
Fernando Perez
Update CodeMirror code to v2.15
r4933 }
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941 return (state.em = !state.em) ? getType(state) : t;
Fernando Perez
Update CodeMirror code to v2.15
r4933 }
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941
return getType(state);
Fernando Perez
Update CodeMirror code to v2.15
r4933 }
function linkText(stream, state) {
while (!stream.eol()) {
var ch = stream.next();
if (ch === '\\') stream.next();
if (ch === ']') {
state.inline = state.f = linkHref;
return linktext;
}
}
return linktext;
}
function linkHref(stream, state) {
stream.eatSpace();
var ch = stream.next();
if (ch === '(' || ch === '[') {
return switchInline(stream, state, inlineElement(linkhref, ch === '(' ? ')' : ']'));
}
return 'error';
}
function footnoteLink(stream, state) {
if (stream.match(/^[^\]]*\]:/, true)) {
state.f = footnoteUrl;
return linktext;
}
return switchInline(stream, state, inlineNormal);
}
function footnoteUrl(stream, state) {
stream.eatSpace();
stream.match(/^[^\s]+/, true);
state.f = state.inline = inlineNormal;
return linkhref;
}
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941 function inlineRE(endChar) {
if (!inlineRE[endChar]) {
// match any not-escaped-non-endChar and any escaped char
// then match endChar or eol
inlineRE[endChar] = new RegExp('^(?:[^\\\\\\' + endChar + ']|\\\\.)*(?:\\' + endChar + '|$)');
}
return inlineRE[endChar];
}
Fernando Perez
Update CodeMirror code to v2.15
r4933 function inlineElement(type, endChar, next) {
next = next || inlineNormal;
return function(stream, state) {
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941 stream.match(inlineRE(endChar));
state.inline = state.f = next;
Fernando Perez
Update CodeMirror code to v2.15
r4933 return type;
};
}
return {
startState: function() {
return {
f: blockNormal,
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941
Fernando Perez
Update CodeMirror code to v2.15
r4933 block: blockNormal,
htmlState: htmlMode.startState(),
indentation: 0,
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941
Fernando Perez
Update CodeMirror code to v2.15
r4933 inline: inlineNormal,
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941 text: handleText,
Fernando Perez
Update CodeMirror code to v2.15
r4933 em: false,
strong: false
};
},
copyState: function(s) {
return {
f: s.f,
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941
Fernando Perez
Update CodeMirror code to v2.15
r4933 block: s.block,
htmlState: CodeMirror.copyState(htmlMode, s.htmlState),
indentation: s.indentation,
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941
Fernando Perez
Update CodeMirror code to v2.15
r4933 inline: s.inline,
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941 text: s.text,
Fernando Perez
Update CodeMirror code to v2.15
r4933 em: s.em,
strong: s.strong
};
},
token: function(stream, state) {
if (stream.sol()) {
Brian Granger
Updating CodeMirror to c813c94 to fix #1344.
r6058 // Reset EM state
state.em = false;
// Reset STRONG state
state.strong = false;
Fernando Perez
Update CodeMirror code to v2.15
r4933 state.f = state.block;
var previousIndentation = state.indentation
, currentIndentation = 0;
while (previousIndentation > 0) {
if (stream.eat(' ')) {
previousIndentation--;
currentIndentation++;
} else if (previousIndentation >= 4 && stream.eat('\t')) {
previousIndentation -= 4;
currentIndentation += 4;
} else {
break;
}
}
state.indentation = currentIndentation;
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941
Fernando Perez
Update CodeMirror code to v2.15
r4933 if (currentIndentation > 0) return null;
}
return state.f(stream, state);
Brian Granger
Updating to CodeMirror 2.2, latest stable release.
r5941 },
getType: getType
Fernando Perez
Update CodeMirror code to v2.15
r4933 };
});
CodeMirror.defineMIME("text/x-markdown", "markdown");