Added option to disable intra-word stars/underscores in Markdown Extra extension. Fixes #156. Fixes #243.

This commit is contained in:
benweet 2013-12-27 21:07:49 +01:00
parent 67eb79350f
commit fcb54b196e
4 changed files with 40 additions and 7 deletions

View File

@ -18,7 +18,7 @@
"requirejs-text": "~2.0.10",
"bootstrap-tour": "~0.7.1",
"ace": "4bbe5346f2ae5ad35c0c47defa244ab27aedd451",
"pagedown-ace": "https://github.com/benweet/pagedown-ace.git#72a27932f6f4f78e93a186aa2947d1f15c1cd7d5",
"pagedown-ace": "git@github.com:benweet/pagedown-ace.git#84d5e1b7ff233a1c8cafa9716e825228d275120c",
"pagedown-extra": "git@github.com:jmcmanus/pagedown-extra.git#9c77f3ad718fec32935f092a560c0023355caf9a",
"crel": "git@github.com:KoryNunn/crel.git#8dbda04b129fc0aec01a2a080d1cab26816e11c1",
"waitForImages": "git@github.com:alexanderdickson/waitForImages.git#~1.4.2",
@ -30,7 +30,6 @@
},
"resolutions": {
"jquery": "2.0.3",
"bootstrap": "v3.0.0",
"pagedown-extra": "05e56619f8fd74421575677c64eb895264f4c375"
"bootstrap": "v3.0.0"
}
}

View File

@ -524,6 +524,17 @@ define([
// Create the converter and the editor
var converter = new Markdown.Converter();
var options = {
_DoItalicsAndBold: function(text) {
// Restore original markdown implementation
text = text.replace(/(\*\*|__)(?=\S)(.+?[*_]*)(?=\S)\1/g,
"<strong>$2</strong>");
text = text.replace(/(\*|_)(?=\S)(.+?)(?=\S)\1/g,
"<em>$2</em>");
return text;
}
};
converter.setOptions(options);
function checkDocumentChanges() {
var newDocumentContent = $editorElt.val();

View File

@ -23,6 +23,7 @@ define([
"strikethrough",
"newlines",
],
intraword: true,
highlighter: "prettify"
};
@ -40,6 +41,7 @@ define([
utils.setInputChecked("#input-markdownextra-smartypants", hasExtension("smartypants"));
utils.setInputChecked("#input-markdownextra-strikethrough", hasExtension("strikethrough"));
utils.setInputChecked("#input-markdownextra-newlines", hasExtension("newlines"));
utils.setInputChecked("#input-markdownextra-intraword", markdownExtra.config.intraword);
utils.setInputValue("#input-markdownextra-highlighter", markdownExtra.config.highlighter);
};
@ -53,6 +55,7 @@ define([
utils.getInputChecked("#input-markdownextra-smartypants") && newConfig.extensions.push("smartypants");
utils.getInputChecked("#input-markdownextra-strikethrough") && newConfig.extensions.push("strikethrough");
utils.getInputChecked("#input-markdownextra-newlines") && newConfig.extensions.push("newlines");
newConfig.intraword = utils.getInputChecked("#input-markdownextra-intraword");
newConfig.highlighter = utils.getInputValue("#input-markdownextra-highlighter");
};
@ -63,11 +66,22 @@ define([
markdownExtra.onPagedownConfigure = function(editor) {
var converter = editor.getConverter();
var options = {
if(markdownExtra.config.intraword === true) {
var converterOptions = {
_DoItalicsAndBold: function(text) {
text = text.replace(/([^\w*]|^)(\*\*|__)(?=\S)(.+?[*_]*)(?=\S)\2(?=[^\w*]|$)/g, "$1<strong>$3</strong>");
text = text.replace(/([^\w*]|^)(\*|_)(?=\S)(.+?)(?=\S)\2(?=[^\w*]|$)/g, "$1<em>$3</em>");
return text;
}
};
converter.setOptions(converterOptions);
}
var extraOptions = {
extensions: markdownExtra.config.extensions
};
if(markdownExtra.config.highlighter == "highlight") {
options.highlighter = "prettify";
extraOptions.highlighter = "prettify";
var previewContentsElt = document.getElementById('preview-contents');
editor.hooks.chain("onPreviewRefresh", function() {
_.each(previewContentsElt.querySelectorAll('.prettyprint > code'), function(elt) {
@ -76,10 +90,10 @@ define([
});
}
else if(markdownExtra.config.highlighter == "prettify") {
options.highlighter = "prettify";
extraOptions.highlighter = "prettify";
editor.hooks.chain("onPreviewRefresh", prettify.prettyPrint);
}
Markdown.Extra.init(converter, options);
Markdown.Extra.init(converter, extraOptions);
};
return markdownExtra;

View File

@ -53,6 +53,15 @@
</div>
</div>
</div>
<div class="form-group">
<label class="col-lg-4 control-label"
for="input-markdownextra-intraword">GFM intra-word stars/underscores</label>
<div class="col-lg-7">
<div class="checkbox">
<input type="checkbox" id="input-markdownextra-intraword">
</div>
</div>
</div>
<div class="form-group">
<label class="col-lg-4 control-label"
for="input-markdownextra-strikethrough">GFM strikethrough</label>