Pagedown extra enhancements. Fixes #15
This commit is contained in:
parent
cc36894da7
commit
d1e9b8c0a5
@ -794,7 +794,7 @@
|
||||
|
||||
<div id="modal-non-unique" class="modal hide">
|
||||
<div class="modal-header">
|
||||
<h3>Whoops...</h3>
|
||||
<h3>Ooops...</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>StackEdit has stopped because another instance was running in
|
||||
|
21
js/core.js
21
js/core.js
@ -321,14 +321,22 @@ define([
|
||||
e.stopPropagation();
|
||||
});
|
||||
|
||||
$(".modal").on('shown', function() {
|
||||
var shownModalId = undefined;
|
||||
$(".modal").on('shown', function(e) {
|
||||
// Focus on the first input when modal opens
|
||||
_.defer(function(elt) {
|
||||
elt.find("input:enabled:visible:first").focus();
|
||||
}, $(this));
|
||||
var modalId = $(this).attr("id");
|
||||
if(shownModalId != modalId) {
|
||||
// Hack to avoid conflict with tabs, collapse, tooltips events
|
||||
shownModalId = modalId;
|
||||
_.defer(function(elt) {
|
||||
elt.find("input:enabled:visible:first").focus();
|
||||
}, $(this));
|
||||
}
|
||||
}).on('hidden', function() {
|
||||
// Focus on the editor when modal is gone
|
||||
if($(this).is(":hidden")) {
|
||||
var modalId = $(this).attr("id");
|
||||
if(shownModalId == modalId && $(this).is(":hidden")) {
|
||||
shownModalId = undefined;
|
||||
_.defer(function() {
|
||||
$("#wmd-input").focus();
|
||||
});
|
||||
@ -345,12 +353,14 @@ define([
|
||||
var value = utils.getInputTextValue($("#input-insert-link"), e);
|
||||
if(value !== undefined) {
|
||||
core.insertLinkCallback(value);
|
||||
core.insertLinkCallback = undefined;
|
||||
}
|
||||
});
|
||||
$(".action-insert-image").click(function(e) {
|
||||
var value = utils.getInputTextValue($("#input-insert-image"), e);
|
||||
if(value !== undefined) {
|
||||
core.insertLinkCallback(value);
|
||||
core.insertLinkCallback = undefined;
|
||||
}
|
||||
});
|
||||
|
||||
@ -358,6 +368,7 @@ define([
|
||||
$("#modal-insert-link, #modal-insert-image").on('hidden', function() {
|
||||
if(core.insertLinkCallback !== undefined) {
|
||||
core.insertLinkCallback(null);
|
||||
core.insertLinkCallback = undefined;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -88,11 +88,6 @@ define([
|
||||
}
|
||||
|
||||
documentSelector.onReady = function() {
|
||||
$("#file-selector").click(function() {
|
||||
_.defer(function() {
|
||||
$("#wmd-input").focus();
|
||||
});
|
||||
});
|
||||
$(".action-open-file").click(function() {
|
||||
filterFileSelector();
|
||||
_.defer(function() {
|
||||
|
@ -204,14 +204,14 @@ else
|
||||
|
||||
text = _UnescapeSpecialChars(text);
|
||||
|
||||
text = pluginHooks.postConversion(text); // benweet
|
||||
|
||||
// attacklab: Restore dollar signs
|
||||
text = text.replace(/~D/g, "$$");
|
||||
|
||||
// attacklab: Restore tildes
|
||||
text = text.replace(/~T/g, "~");
|
||||
|
||||
text = pluginHooks.postConversion(text);
|
||||
|
||||
g_html_blocks = g_titles = g_urls = null;
|
||||
|
||||
return text;
|
||||
|
@ -693,6 +693,7 @@
|
||||
timer = undefined;
|
||||
inputStateObj = undefined;
|
||||
refreshState();
|
||||
inputStateObj.setInputAreaSelection();
|
||||
saveState();
|
||||
};
|
||||
|
||||
|
@ -88,30 +88,15 @@
|
||||
}
|
||||
|
||||
// Convert markdown within an element, retaining only span-level tags
|
||||
// (An inefficient version of Pagedown's runSpanGamut. We rely on a
|
||||
// pagedown coverter to do the complete conversion, and then retain
|
||||
// only the specified tags -- inline in this case).
|
||||
function convertSpans(text, converter) {
|
||||
text = denormalize(text);
|
||||
var html = converter.makeHtml(text);
|
||||
return sanitizeHtml(html, inlineTags);
|
||||
function convertSpans(text, extra) {
|
||||
return sanitizeHtml(convertAll(text, extra), inlineTags);
|
||||
}
|
||||
|
||||
// Convert internal markdown using the stock pagedown converter
|
||||
function convertAll(text, converter) {
|
||||
text = denormalize(text);
|
||||
return converter.makeHtml(text);
|
||||
}
|
||||
|
||||
// We use convertSpans and convertAll to convert markdown inside of Markdown Extra
|
||||
// elements we create. Since this markdown has already been through the pagedown
|
||||
// normalization process before our hooks were called, we need to do some
|
||||
// denormalization before sending it back through a different Pagedown converter.
|
||||
function denormalize(text) {
|
||||
// Restore dollar signs and tildes
|
||||
text = text.replace(/~D/g, "$$");
|
||||
text = text.replace(/~T/g, "~");
|
||||
return text;
|
||||
function convertAll(text, extra) {
|
||||
var result = extra.blockGamutHookCallback(text);
|
||||
result = extra.previousPostConversion(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Convert escaped special characters to HTML decimal entity codes.
|
||||
@ -123,13 +108,6 @@
|
||||
return text.replace(/\\\|/g, '|').replace(/\\:/g, ':');
|
||||
}
|
||||
|
||||
// Determine if the given pagedown converter performs sanitization
|
||||
// on postConversion
|
||||
function isSanitizing(converter) {
|
||||
// call the converter's postConversion hook and see if it sanitizes its input
|
||||
return converter.hooks.postConversion("<table>") === "";
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************
|
||||
* Markdown.Extra *
|
||||
@ -186,10 +164,13 @@
|
||||
|
||||
// preBlockGamut also gives us access to a hook so we can run the
|
||||
// block gamut recursively, however we don't need it at this point
|
||||
converter.hooks.chain("preBlockGamut", function(text) {
|
||||
converter.hooks.chain("preBlockGamut", function(text, blockGamutHookCallback) {
|
||||
extra.blockGamutHookCallback = blockGamutHookCallback;
|
||||
return extra.doConversion(preBlockGamutTransformations, text);
|
||||
});
|
||||
|
||||
// Keep a reference to the hook chain running before finishConversion to apply on hashed extra blocks
|
||||
extra.previousPostConversion = converter.hooks.postConversion;
|
||||
converter.hooks.chain("postConversion", function(text) {
|
||||
return extra.finishConversion(text);
|
||||
});
|
||||
@ -203,10 +184,7 @@
|
||||
extra.tableClass = options.table_class;
|
||||
}
|
||||
|
||||
// we can't just use the same converter that the user passes in, as
|
||||
// Pagedown forbids it (doing so could cause an infinite loop)
|
||||
extra.converter = isSanitizing(converter) ? Markdown.getSanitizingConverter()
|
||||
: new Markdown.Converter();
|
||||
extra.converter = converter;
|
||||
|
||||
// Caller usually won't need this, but it's handy for testing.
|
||||
return extra;
|
||||
@ -255,10 +233,21 @@
|
||||
// html blocks in the hashBlocks array.
|
||||
Markdown.Extra.prototype.unHashExtraBlocks = function(text) {
|
||||
var self = this;
|
||||
text = text.replace(/<p>~X(\d+)X<\/p>/g, function(wholeMatch, m1) {
|
||||
var key = parseInt(m1, 10);
|
||||
return self.hashBlocks[key];
|
||||
});
|
||||
function recursiveUnHash() {
|
||||
var hasHash = false;
|
||||
text = text.replace(/<p>~X(\d+)X<\/p>/g, function(wholeMatch, m1) {
|
||||
hasHash = true;
|
||||
var key = parseInt(m1, 10);
|
||||
var result = self.hashBlocks[key];
|
||||
// We need to perform that since we skipped the steps in the converter
|
||||
result = result.replace(/~D/g, "$$").replace(/~T/g, "~");
|
||||
return result;
|
||||
});
|
||||
if(hasHash === true) {
|
||||
recursiveUnHash();
|
||||
}
|
||||
}
|
||||
recursiveUnHash();
|
||||
return text;
|
||||
};
|
||||
|
||||
@ -419,7 +408,7 @@
|
||||
|
||||
// build column headers.
|
||||
for (i = 0; i < colCount; i++) {
|
||||
var headerHtml = convertSpans(trim(headers[i]), self.converter);
|
||||
var headerHtml = convertSpans(trim(headers[i]), self);
|
||||
html += [" <th", align[i], ">", headerHtml, "</th>\n"].join('');
|
||||
}
|
||||
html += "</tr>\n</thead>\n";
|
||||
@ -438,7 +427,7 @@
|
||||
|
||||
html += "<tr>\n";
|
||||
for (j = 0; j < colCount; j++) {
|
||||
var colHtml = convertSpans(trim(rowCells[j]), self.converter);
|
||||
var colHtml = convertSpans(trim(rowCells[j]), self);
|
||||
html += [" <td", align[j], ">", colHtml, "</td>\n"].join('');
|
||||
}
|
||||
html += "</tr>\n";
|
||||
@ -592,7 +581,7 @@
|
||||
for (var i = 0; i < terms.length; i++) {
|
||||
var term = terms[i];
|
||||
// process spans inside dt
|
||||
term = convertSpans(trim(term), self.converter);
|
||||
term = convertSpans(trim(term), self);
|
||||
text += "\n<dt>" + term + "</dt>";
|
||||
}
|
||||
return text + "\n";
|
||||
@ -606,11 +595,11 @@
|
||||
// process markdown inside definition
|
||||
// TODO?: currently doesn't apply extensions
|
||||
def = outdent(def) + "\n\n";
|
||||
def = "\n" + convertAll(def, self.converter) + "\n";
|
||||
def = "\n" + convertAll(def, self) + "\n";
|
||||
} else {
|
||||
// convert span-level markdown inside definition
|
||||
def = rtrim(def);
|
||||
def = convertSpans(outdent(def), self.converter);
|
||||
def = convertSpans(outdent(def), self);
|
||||
}
|
||||
|
||||
return "\n<dd>" + def + "</dd>\n";
|
||||
|
@ -7,13 +7,17 @@ define([
|
||||
layoutOrientation: "horizontal",
|
||||
lazyRendering: true,
|
||||
editorFontSize: 14,
|
||||
defaultContent: "\n\n\n> Written with [StackEdit](http://benweet.github.io/stackedit/).",
|
||||
commitMsg: "Published by http://benweet.github.io/stackedit",
|
||||
defaultContent: "\n\n\n> Written with [StackEdit](" + MAIN_URL + ").",
|
||||
commitMsg: "Published with " + MAIN_URL,
|
||||
template: [
|
||||
'<!DOCTYPE html>\n',
|
||||
'<html>\n',
|
||||
'<head>\n',
|
||||
'<meta charset="utf-8">\n',
|
||||
'<title><%= documentTitle %></title>\n',
|
||||
'<link rel="stylesheet" href="',
|
||||
MAIN_URL,
|
||||
'css/main-min.css" />\n',
|
||||
'</head>\n',
|
||||
'<body><%= documentHTML %></body>\n',
|
||||
'</html>'
|
||||
|
@ -3,7 +3,7 @@ set -e
|
||||
echo '### Optimizing resources ###'
|
||||
scripts/run_optimize
|
||||
echo '### Modifying cache.manifest ###'
|
||||
sed -i "s/^#.*$/# `date`/g" cache.manifest
|
||||
sed -i "s/^#.*/# `date`/" cache.manifest
|
||||
echo '### Commit and push ###'
|
||||
git commit -a -m "Prepare deployment"
|
||||
git branch -f gh-pages master
|
||||
|
@ -79,7 +79,7 @@
|
||||
|
||||
<div id="modal-non-unique" class="modal hide">
|
||||
<div class="modal-header">
|
||||
<h3>Whoops...</h3>
|
||||
<h3>Ooops...</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>StackEdit has stopped because another instance was running in
|
||||
|
Loading…
Reference in New Issue
Block a user