Merge pull request #964 from simonzack/mathjax_livepreview
Enable mathjax in live preview
This commit is contained in:
+9
-3
@@ -28,7 +28,7 @@ class String
|
|||||||
self # Do not transliterate utf-8 url's unless using Grit
|
self # Do not transliterate utf-8 url's unless using Grit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# _Header => header which causes errors
|
# _Header => header which causes errors
|
||||||
def to_url
|
def to_url
|
||||||
return nil if self.nil?
|
return nil if self.nil?
|
||||||
@@ -149,7 +149,7 @@ module Precious
|
|||||||
@allow_uploads = wiki.allow_uploads
|
@allow_uploads = wiki.allow_uploads
|
||||||
if page = wikip.page
|
if page = wikip.page
|
||||||
if wiki.live_preview && page.format.to_s.include?('markdown') && supported_useragent?(request.user_agent)
|
if wiki.live_preview && page.format.to_s.include?('markdown') && supported_useragent?(request.user_agent)
|
||||||
live_preview_url = '/livepreview/index.html?page=' + encodeURIComponent(@name)
|
live_preview_url = '/livepreview/?page=' + encodeURIComponent(@name)
|
||||||
if @path
|
if @path
|
||||||
live_preview_url << '&path=' + encodeURIComponent(@path)
|
live_preview_url << '&path=' + encodeURIComponent(@path)
|
||||||
end
|
end
|
||||||
@@ -363,6 +363,12 @@ module Precious
|
|||||||
mustache :page
|
mustache :page
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get '/livepreview/' do
|
||||||
|
wiki = wiki_new
|
||||||
|
@mathjax = wiki.mathjax
|
||||||
|
mustache :livepreview, { :layout => false }
|
||||||
|
end
|
||||||
|
|
||||||
get '/history/*' do
|
get '/history/*' do
|
||||||
@page = wiki_page(params[:splat].first).page
|
@page = wiki_page(params[:splat].first).page
|
||||||
@page_num = [params[:page].to_i, 1].max
|
@page_num = [params[:page].to_i, 1].max
|
||||||
@@ -380,7 +386,7 @@ module Precious
|
|||||||
@versions = @wiki.latest_changes({:max_count => max_count})
|
@versions = @wiki.latest_changes({:max_count => max_count})
|
||||||
mustache :latest_changes
|
mustache :latest_changes
|
||||||
end
|
end
|
||||||
|
|
||||||
post '/compare/*' do
|
post '/compare/*' do
|
||||||
@file = encodeURIComponent(params[:splat].first)
|
@file = encodeURIComponent(params[:splat].first)
|
||||||
@versions = params[:versions] || []
|
@versions = params[:versions] || []
|
||||||
|
|||||||
@@ -315,6 +315,10 @@ var makePreviewHtml = function () {
|
|||||||
// preview.innerHTML = text; // this doesn't work on IE.
|
// preview.innerHTML = text; // this doesn't work on IE.
|
||||||
previewSet( text );
|
previewSet( text );
|
||||||
|
|
||||||
|
if (win.MathJax) {
|
||||||
|
win.MathJax.Hub.Queue(['Typeset', win.MathJax.Hub, 'contentframe']);
|
||||||
|
}
|
||||||
|
|
||||||
// highlight code blocks.
|
// highlight code blocks.
|
||||||
var codeElements = preview.getElementsByTagName( 'pre' );
|
var codeElements = preview.getElementsByTagName( 'pre' );
|
||||||
var codeElementsLength = codeElements.length;
|
var codeElementsLength = codeElements.length;
|
||||||
@@ -374,19 +378,19 @@ var applyTimeout = function () {
|
|||||||
~-1 == false; !~-1 == true;
|
~-1 == false; !~-1 == true;
|
||||||
*/
|
*/
|
||||||
if ( !~ location.host.indexOf( 'github.com' ) ) {
|
if ( !~ location.host.indexOf( 'github.com' ) ) {
|
||||||
|
|
||||||
// returns unescaped key with leading slashes removed
|
// returns unescaped key with leading slashes removed
|
||||||
function key_no_leading_slash( key ) {
|
function key_no_leading_slash( key ) {
|
||||||
return unescape( $.key( key ) || '' ).replace( /^\/+/, '' );
|
return unescape( $.key( key ) || '' ).replace( /^\/+/, '' );
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure leading / is removed from path and that it ends with /
|
// ensure leading / is removed from path and that it ends with /
|
||||||
var path = key_no_leading_slash( 'path' );
|
var path = key_no_leading_slash( 'path' );
|
||||||
// don't append '/' if path is empty from removing leading slash
|
// don't append '/' if path is empty from removing leading slash
|
||||||
if ( path !== '' && path.charAt( path.length - 1 ) !== '/' ) {
|
if ( path !== '' && path.charAt( path.length - 1 ) !== '/' ) {
|
||||||
path += '/';
|
path += '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
jQuery.ajax( {
|
jQuery.ajax( {
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: baseUrl + '/data/' + path + key_no_leading_slash( 'page' ),
|
url: baseUrl + '/data/' + path + key_no_leading_slash( 'page' ),
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
window.MathJax = {
|
window.MathJax = {
|
||||||
tex2jax: {
|
tex2jax: {
|
||||||
inlineMath: [ ['\\(','\\)'] ],
|
inlineMath: [ ['$','$'], ['\\(','\\)'] ],
|
||||||
displayMath: [ ['$$','$$'], ['\\[','\\]'] ],
|
displayMath: [ ['$$','$$'], ['\\[','\\]'] ],
|
||||||
processEscapes: true
|
processEscapes: true
|
||||||
},
|
},
|
||||||
|
|||||||
+23
-1
@@ -9,7 +9,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id='editor'></div>
|
<div id='editor'></div>
|
||||||
<div id='previewframe'><div id='contentframe' class='markdown-body'></div></div>
|
<div id='previewframe'><div id='contentframe' class='markdown-body'></div></div>
|
||||||
<!-- tool panel from notepage.es. save & savecomment icons from Retina Display Icon Set. -->
|
<!-- tool panel from notepage.es. save & savecomment icons from Retina Display Icon Set. -->
|
||||||
<div id='toolpanel' class='toolpanel edit' style='width: 500px; right: 0px; visibility: hidden;'>
|
<div id='toolpanel' class='toolpanel edit' style='width: 500px; right: 0px; visibility: hidden;'>
|
||||||
<a id='preview' class='edit'><img src='images/globe_24.png' alt='Preview' title='Preview'></a>
|
<a id='preview' class='edit'><img src='images/globe_24.png' alt='Preview' title='Preview'></a>
|
||||||
<a id='save' class='edit'><img src='images/save_24.png' alt='Save' title='Save'></a>
|
<a id='save' class='edit'><img src='images/save_24.png' alt='Save' title='Save'></a>
|
||||||
@@ -40,5 +40,27 @@ var require = {
|
|||||||
<script src='js/sundown.js'></script>
|
<script src='js/sundown.js'></script>
|
||||||
<script src='js/md_sundown.js'></script>
|
<script src='js/md_sundown.js'></script>
|
||||||
<script src='js/livepreview.js'></script>
|
<script src='js/livepreview.js'></script>
|
||||||
|
{{#mathjax}}
|
||||||
|
{{^mathjax_config}}
|
||||||
|
<script type="text/javascript">
|
||||||
|
window.MathJax = {
|
||||||
|
tex2jax: {
|
||||||
|
inlineMath: [ ['$','$'], ['\\(','\\)'] ],
|
||||||
|
displayMath: [ ['$$','$$'], ['\\[','\\]'] ],
|
||||||
|
processEscapes: true
|
||||||
|
},
|
||||||
|
TeX: { extensions: ["autoload-all.js"] }
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
{{/mathjax_config}}
|
||||||
|
{{#mathjax_config}}
|
||||||
|
<script type="text/javascript" src="{{base_url}}/{{mathjax_config}}"></script>
|
||||||
|
{{/mathjax_config}}
|
||||||
|
<script>(function(d,j){
|
||||||
|
j = d.createElement('script');
|
||||||
|
j.src = '//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML';
|
||||||
|
(d.head || d.getElementsByTagName('head')[0]).appendChild(j);
|
||||||
|
}(document));
|
||||||
|
</script>{{/mathjax}}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
module Precious
|
||||||
|
module Views
|
||||||
|
class Livepreview < Layout
|
||||||
|
def mathjax
|
||||||
|
@mathjax
|
||||||
|
end
|
||||||
|
|
||||||
|
def mathjax_config
|
||||||
|
@mathjax_config
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user