Skip to content

Commit e57d79f

Browse files
authored
Merge pull request #15 from jywarren/history-prefix
History prefix addition
2 parents 5fb0db8 + 1abc22a commit e57d79f

6 files changed

+25
-21
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ inlineMarkdownEditor({
3737
replaceUrl: '/wiki/replace/' + wiki_id,
3838
selector: '.markdown',
3939
preProcessor: function preProcessMarkdown(markdown) {
40-
// do things to markdown here
40+
// do things to markdown here before it's used to construct the form
4141
return markdown
4242
},
4343
postProcessor: function postProcessContent(element) {
44-
// do things to element here
44+
// do things to element here after the section has been converted to HTML and displayed
4545
},
4646
defaultMarkdown: function(markdown) {}, // a markdown parser
4747
buildSectionForm: function() {}, // return a string containing the form element
4848
onComplete: function(response, markdown, html, el, uniqueId, form, o) {}, // run on completing AJAX post
4949
isEditable: function(markdown) {}, // returns boolean; whether a given subsection should get an inline form; default skips HTML and horizontal rules
5050
extraButtons: { 'fa-icon-name': function(element) {} }, // object with keys of icon names for additional buttons with associated actions for each; returns jQuery element upon construction
51-
submitSectionForm: function(event, before, after, options) {} // optional, to override the form submission handling for each subsection; before/after represent the text diff
52-
51+
submitSectionForm: function(event, before, after, options) {}, // optional, to override the form submission handling for each subsection; before/after represent the text diff
52+
editorOptions: {} // any options to pass to the built-in PublicLab.Editor instance
5353
});
5454
```
5555

dist/inlineMarkdownEditor.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -10237,14 +10237,15 @@ inlineMarkdownEditor = function inlineMarkdownEditor(o) {
1023710237
o.processSections = require('./processSections.js');
1023810238
var el = $(o.selector);
1023910239
o.originalMarkdown = el.html();
10240+
o.preProcessor = o.preProcessor || function(m) { return m; }
1024010241
// split by double-newline:
1024110242
var sections = o.originalMarkdown
1024210243
.replace(/\n[\n]+/g, "\n\n")
1024310244
.split('\n\n');
1024410245
var editableSections = [];
1024510246
// we also do this inside processSection, but independently track here:
1024610247
sections.forEach(function forEachSection(section, index) {
10247-
if (o.isEditable(section, o.originalMarkdown)) editableSections.push(section);
10248+
if (o.isEditable(section, o.preProcessor(o.originalMarkdown))) editableSections.push(section);
1024810249
});
1024910250
el.html('');
1025010251
// we might start running processSections only on editableSections...
@@ -10299,8 +10300,8 @@ module.exports = function isEditable(markdown, originalMarkdown) {
1029910300

1030010301
},{}],99:[function(require,module,exports){
1030110302
module.exports = function onComplete(response, markdown, html, el, uniqueId, form, o) {
10303+
var message = form.find('.section-message');
1030210304
if (response === 'true' || response === true) {
10303-
var message = $('#' + uniqueId + ' .section-message');
1030410305
message.html('<i class="fa fa-check" style="color:green;"></i>');
1030510306
//markdown = changes;
1030610307
$('#' + uniqueId + ' textarea').val('');
@@ -10328,7 +10329,8 @@ module.exports = function processSection(markdown, o) {
1032810329
uniqueId = "section-form-" + randomNum,
1032910330
filteredMarkdown = markdown;
1033010331

10331-
if (o.preProcessor) filteredMarkdown = o.preProcessor(markdown);
10332+
var originalSectionMarkdown = markdown;
10333+
filteredMarkdown = o.preProcessor(markdown);
1033210334
html = o.defaultMarkdown(filteredMarkdown);
1033310335

1033410336
$(o.selector).append('<div class="inline-section inline-section-' + uniqueId + '"></div>');
@@ -10341,7 +10343,7 @@ module.exports = function processSection(markdown, o) {
1034110343
var message = $('#' + uniqueId + ' .section-message');
1034210344

1034310345
function insertFormIfMarkdown(_markdown, el, uniqueId) {
10344-
if (o.isEditable(_markdown, o.originalMarkdown)) {
10346+
if (o.isEditable(_markdown, o.preProcessor(o.originalMarkdown))) {
1034510347
var formHtml = o.buildSectionForm(uniqueId, _markdown);
1034610348
el.after(formHtml);
1034710349
var _form = $('#' + uniqueId);
@@ -10351,16 +10353,16 @@ module.exports = function processSection(markdown, o) {
1035110353
var editor;
1035210354
if (o.wysiwyg && $('#' + uniqueId).find('.wk-container').length === 0) {
1035310355
// insert rich editor
10354-
editor = new PL.Editor({
10355-
textarea: $('#' + uniqueId + ' textarea')[0]
10356-
});
10356+
var editorOptions = o.editorOptions || {};
10357+
editorOptions.textarea = $('#' + uniqueId + ' textarea')[0];
10358+
editor = new PL.Editor(editorOptions);
1035710359
}
1035810360
_form.find('.cancel').click(function inlineEditCancelClick(e) {
1035910361
e.preventDefault();
1036010362
_form.hide();
1036110363
});
1036210364
_form.find('button.submit').click(function(e) {
10363-
prepareAndSendSectionForm(e, _form, editor, _markdown);
10365+
prepareAndSendSectionForm(e, _form, editor, originalSectionMarkdown);
1036410366
});
1036510367
}
1036610368
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "inline-markdown-editor",
3-
"version": "0.2.3",
3+
"version": "0.3.0",
44
"description": "An inline wysiwyg markdown document editor based on replacing string subsections. WYSIWYG possible via woofmark.",
55
"main": "dist/inlineMarkdownEditor.js",
66
"scripts": {

src/inlineMarkdownEditor.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ inlineMarkdownEditor = function inlineMarkdownEditor(o) {
88
o.processSections = require('./processSections.js');
99
var el = $(o.selector);
1010
o.originalMarkdown = el.html();
11+
o.preProcessor = o.preProcessor || function(m) { return m; }
1112
// split by double-newline:
1213
var sections = o.originalMarkdown
1314
.replace(/\n[\n]+/g, "\n\n")
1415
.split('\n\n');
1516
var editableSections = [];
1617
// we also do this inside processSection, but independently track here:
1718
sections.forEach(function forEachSection(section, index) {
18-
if (o.isEditable(section, o.originalMarkdown)) editableSections.push(section);
19+
if (o.isEditable(section, o.preProcessor(o.originalMarkdown))) editableSections.push(section);
1920
});
2021
el.html('');
2122
// we might start running processSections only on editableSections...

src/onComplete.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = function onComplete(response, markdown, html, el, uniqueId, form, o) {
2+
var message = form.find('.section-message');
23
if (response === 'true' || response === true) {
3-
var message = $('#' + uniqueId + ' .section-message');
44
message.html('<i class="fa fa-check" style="color:green;"></i>');
55
//markdown = changes;
66
$('#' + uniqueId + ' textarea').val('');

src/processSection.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ module.exports = function processSection(markdown, o) {
44
uniqueId = "section-form-" + randomNum,
55
filteredMarkdown = markdown;
66

7-
if (o.preProcessor) filteredMarkdown = o.preProcessor(markdown);
7+
var originalSectionMarkdown = markdown;
8+
filteredMarkdown = o.preProcessor(markdown);
89
html = o.defaultMarkdown(filteredMarkdown);
910

1011
$(o.selector).append('<div class="inline-section inline-section-' + uniqueId + '"></div>');
@@ -17,7 +18,7 @@ module.exports = function processSection(markdown, o) {
1718
var message = $('#' + uniqueId + ' .section-message');
1819

1920
function insertFormIfMarkdown(_markdown, el, uniqueId) {
20-
if (o.isEditable(_markdown, o.originalMarkdown)) {
21+
if (o.isEditable(_markdown, o.preProcessor(o.originalMarkdown))) {
2122
var formHtml = o.buildSectionForm(uniqueId, _markdown);
2223
el.after(formHtml);
2324
var _form = $('#' + uniqueId);
@@ -27,16 +28,16 @@ module.exports = function processSection(markdown, o) {
2728
var editor;
2829
if (o.wysiwyg && $('#' + uniqueId).find('.wk-container').length === 0) {
2930
// insert rich editor
30-
editor = new PL.Editor({
31-
textarea: $('#' + uniqueId + ' textarea')[0]
32-
});
31+
var editorOptions = o.editorOptions || {};
32+
editorOptions.textarea = $('#' + uniqueId + ' textarea')[0];
33+
editor = new PL.Editor(editorOptions);
3334
}
3435
_form.find('.cancel').click(function inlineEditCancelClick(e) {
3536
e.preventDefault();
3637
_form.hide();
3738
});
3839
_form.find('button.submit').click(function(e) {
39-
prepareAndSendSectionForm(e, _form, editor, _markdown);
40+
prepareAndSendSectionForm(e, _form, editor, originalSectionMarkdown);
4041
});
4142
}
4243
}

0 commit comments

Comments
 (0)