Adds markdown preview rendering. Adds markdown type and icons.

This commit is contained in:
Lars Jung 2012-08-06 00:21:00 +02:00
parent 298d2e2efd
commit 9c1142bd02
13 changed files with 1696 additions and 21 deletions

View file

@ -4,6 +4,13 @@ modulejs.define('ext/preview-txt', ['_', '$', 'core/settings', 'core/resource',
var defaults = {
enabled: false,
types: {
authors: 'plain',
copying: 'plain',
css: 'css',
install: 'plain',
markdown: 'plain',
readme: 'plain',
script: 'shell',
text: 'plain',
js: 'js'
}
@ -14,7 +21,7 @@ modulejs.define('ext/preview-txt', ['_', '$', 'core/settings', 'core/resource',
template = '<div id="pv-txt-overlay" class="noSelection">' +
'<div id="pv-txt-close" />' +
'<div id="pv-txt-content">' +
'<pre id="pv-txt-text" class="brush: js" />' +
'<div id="pv-txt-text" />' +
'</div>' +
'<div id="pv-txt-bottombar" class="clearfix">' +
'<ul id="pv-txt-buttons">' +
@ -30,27 +37,34 @@ modulejs.define('ext/preview-txt', ['_', '$', 'core/settings', 'core/resource',
'</div>',
templateText = '<pre id="pv-txt-text" />',
templateMarkdown = '<div id="pv-txt-text" class="markdown" />',
currentEntries = [],
currentIdx = 0,
loadSyntaxhighlighter = function (callback) {
loadScript = function (url, globalId, callback) {
var id = 'SyntaxHighlighter';
if (window[id]) {
callback(window[id]);
if (window[globalId]) {
callback(window[globalId]);
} else {
$.ajax({
url: allsettings.h5aiAbsHref + 'js/syntaxhighlighter.js',
url: url,
dataType: 'script',
complete: function () {
callback(window[id]);
callback(window[globalId]);
}
});
}
},
loadSyntaxhighlighter = function (callback) {
loadScript(allsettings.h5aiAbsHref + 'js/syntaxhighlighter.js', 'SyntaxHighlighter', callback);
},
loadMarkdown = function (callback) {
loadScript(allsettings.h5aiAbsHref + 'js/markdown.js', 'markdown', callback);
},
adjustSize = function () {
@ -109,15 +123,29 @@ modulejs.define('ext/preview-txt', ['_', '$', 'core/settings', 'core/resource',
$text.fadeOut(100, function () {
var $nText = $(templateText).hide().addClass('toolbar: false; brush:').addClass(settings.types[current.type] || 'plain').text(content);
var $nText;
$text.replaceWith($nText);
loadSyntaxhighlighter(function (sh) {
if (current.type === 'markdown') {
$nText = $(templateMarkdown).hide();
$text.replaceWith($nText);
if (sh) {
sh.highlight({}, $nText[0]);
}
});
loadMarkdown(function (md) {
if (md) {
$nText.html(md.toHTML(content));
}
});
} else {
$nText = $(templateText).hide().addClass('toolbar: false; brush:').addClass(settings.types[current.type] || 'plain').text(content);
$text.replaceWith($nText);
loadSyntaxhighlighter(function (sh) {
if (sh) {
sh.highlight({}, $nText[0]);
}
});
}
$nText.fadeIn(200);
adjustSize();

File diff suppressed because it is too large Load diff

2
src/_h5ai/js/markdown.js Normal file
View file

@ -0,0 +1,2 @@
// @include "lib/markdown-0.4.0.js"

View file

@ -0,0 +1,2 @@
// @include "lib/modernizr-2.6.1.min.js"