From bf937485202bb0be489c07664f24304c8e140ac9 Mon Sep 17 00:00:00 2001 From: benweet Date: Thu, 28 Nov 2013 01:04:41 +0000 Subject: [PATCH] New theme --- public/res/core.js | 11 +- public/res/extensions/userCustom.js | 109 ++++++++- public/res/html/bodyIndex.html | 6 +- public/res/html/buttonHtmlCode.html | 2 +- public/res/html/buttonMarkdownSyntax.html | 2 +- public/res/html/buttonStat.html | 2 +- public/res/html/buttonToc.html | 2 +- public/res/html/buttonViewer.html | 2 +- public/res/img/stackedit-64.png | Bin 447 -> 4423 bytes public/res/settings.js | 4 +- public/res/styles/main.less | 264 +++++++++++++--------- 11 files changed, 278 insertions(+), 126 deletions(-) diff --git a/public/res/core.js b/public/res/core.js index 4846f6bf..2e2a9479 100644 --- a/public/res/core.js +++ b/public/res/core.js @@ -304,8 +304,8 @@ define([ livePaneResizing: true, enableCursorHotkey: false, resizerDblClickToggle: false, - north__spacing_open: 6, - north__spacing_closed: 6, + north__spacing_open: 0.001, + north__spacing_closed: 0.001, spacing_open: 35, spacing_closed: 35, togglerLength_open: 60, @@ -386,12 +386,11 @@ define([ $previewButtonsElt = $('
'); $editorButtonsElt = $('
'); if(window.viewerMode || settings.layoutOrientation == "horizontal") { - $('.ui-layout-resizer-north').append($resizerDecorator).append($previewButtonsElt); - $('.ui-layout-resizer-east').append($northTogglerElt).append($editorButtonsElt); + $('.ui-layout-resizer-north').append($previewButtonsElt); + $('.ui-layout-resizer-east').append($resizerDecorator).append($northTogglerElt).append($editorButtonsElt); } else { - $('.ui-layout-resizer-north').append($resizerDecorator); - $('.ui-layout-resizer-south').append($previewButtonsElt).append($editorButtonsElt).append($northTogglerElt); + $('.ui-layout-resizer-south').append($resizerDecorator).append($previewButtonsElt).append($editorButtonsElt).append($northTogglerElt); } setPanelVisibility(); diff --git a/public/res/extensions/userCustom.js b/public/res/extensions/userCustom.js index 5334810b..eae7f319 100644 --- a/public/res/extensions/userCustom.js +++ b/public/res/extensions/userCustom.js @@ -60,6 +60,113 @@ define([ console.error(e); } }; - + + userCustom.onPagedownConfigure = function (editor) { + var thmCounter = { num: 0 }; + var excsCounter = { num: 0 }; + var environmentMap = { + thm: { title: "Theorem" ,counter: thmCounter }, + lem: { title: "Lemma" ,counter: thmCounter }, + cor: { title: "Corollary" ,counter: thmCounter }, + prop: { title: "Property" ,counter: thmCounter }, + defn: { title: "Definition" ,counter: thmCounter }, + rem: { title: "Remark" ,counter: thmCounter }, + prob: { title: "Problem" ,counter: excsCounter }, + excs: { title: "Exercise" ,counter: excsCounter }, + examp: { title: "Example" ,counter: excsCounter }, + proof: { title: "Proof" } + }; + var converter = editor.getConverter(); + // Save the preConversion callbacks stack + var preConversion = converter.hooks.preConversion; + converter.hooks.preConversion = function (text) { + // Change \begin...\end to /begin.../end to avoid MathJax processing + text = text.replace(/\\begin{(\w+)}([\s\S]*?)\\end{\1}/g, function (wholeMatch, m1, m2) { + if(!environmentMap[m1]) return wholeMatch; + // At this stage we need to keep the same number of characters for accurate section parsing + return '/begin{' + m1 + '}' + m2 + '/end{' + m1 + '}'; + }); + // Transform \title and \section into markdown title to take benefit of partial rendering + text = text.replace(/\\(\w+){([^\r\n}]+)}/g, function (wholeMatch, m1, m2) { + // At this stage we need to keep the same number of characters for accurate section parsing + if (m1 == 'section') { + // \section{} has to be replaced by 10 chars + return '\n### ' + m2 + '\n'; + } + if (m1 == 'subsection') { + // \subsection{} has to be replaced by 13 chars + return '\n#### ' + m2 + '\n'; + } + if (m1 == 'subsubsection') { + // \subsubsection{} has to be replaced by 16 chars + return '\n##### ' + m2 + '\n'; + } + if (m1 == 'title') { + // \title{} has to be replaced by 8 chars + return '\n## ' + m2 + '\n'; + } + return wholeMatch; + }); + // We are replacing the preConversion stack, call the other preConversion callbacks from the old stack + return preConversion(text); + }; + converter.hooks.chain("preBlockGamut", function (text, blockGamutHookCallback) { + text = text.replace(/\\ref{(\w+):(\d+)}/g, function (wholeMatch, m1, m2) { + if(!environmentMap[m1]) return wholeMatch; + return '' + environmentMap[m1].title + ' ' + m2 + ''; + }); + text = text.replace(/\\(author|date){([\s\S]*?)}/g, '
$2
'); + return text.replace(/\/begin{(\w+)}([\s\S]*?)\/end{\1}/g, function (wholeMatch, m1, m2) { + if(!environmentMap[m1]) return wholeMatch; + var result = '
' + blockGamutHookCallback(m2); + if (m1 == "proof") { + result += '$■$'; + } + return result + '
'; + }); + }); + var previewContentsElt = document.getElementById('preview-contents'); + editor.hooks.chain('onPreviewRefresh', function() { + thmCounter.num = 0; + excsCounter.num = 0; + _.each(previewContentsElt.querySelectorAll('[class^="latex_"]'), function(elt) { + var key = elt.className.match(/^latex_(\S+)/)[1]; + var environment = environmentMap[key]; + if(!environment) return; + var title = environment.title; + if(environment.counter) { + environment.counter.num++; + title += ' ' + environment.counter.num; + elt.id = key + ':' + environment.counter.num; + } + elt.querySelector('.latex_title').innerHTML = title + '.'; + }); + }); + }; + + userCustom.onReady = function () { + var style = [ + '.latex_thm, .latex_lem, .latex_cor, .latex_defn, .latex_prop, .latex_rem {', + ' font-style:italic;', + ' display: block;', + ' margin:15px 0;', + '}', + '.latex_prob, .latex_examp, .latex_excs, .latex_proof {', + ' font-style:normal;', + ' margin: 10px 0;', + ' display: block;', + '}', + '.latex_title {', + ' float:left;', + ' font-weight:bold;', + ' padding-right: 10px;', + '}', + '.latex_proofend {', + ' float:right;', + '}', + ].join('\n'); + $("head").append($('