Skip to content

Commit

Permalink
Merge pull request #15 from jywarren/history-prefix
Browse files Browse the repository at this point in the history
History prefix addition
  • Loading branch information
jywarren authored Aug 8, 2017
2 parents 5fb0db8 + 1abc22a commit e57d79f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 21 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ inlineMarkdownEditor({
replaceUrl: '/wiki/replace/' + wiki_id,
selector: '.markdown',
preProcessor: function preProcessMarkdown(markdown) {
// do things to markdown here
// do things to markdown here before it's used to construct the form
return markdown
},
postProcessor: function postProcessContent(element) {
// do things to element here
// do things to element here after the section has been converted to HTML and displayed
},
defaultMarkdown: function(markdown) {}, // a markdown parser
buildSectionForm: function() {}, // return a string containing the form element
onComplete: function(response, markdown, html, el, uniqueId, form, o) {}, // run on completing AJAX post
isEditable: function(markdown) {}, // returns boolean; whether a given subsection should get an inline form; default skips HTML and horizontal rules
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
submitSectionForm: function(event, before, after, options) {} // optional, to override the form submission handling for each subsection; before/after represent the text diff

submitSectionForm: function(event, before, after, options) {}, // optional, to override the form submission handling for each subsection; before/after represent the text diff
editorOptions: {} // any options to pass to the built-in PublicLab.Editor instance
});
```

Expand Down
18 changes: 10 additions & 8 deletions dist/inlineMarkdownEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10237,14 +10237,15 @@ inlineMarkdownEditor = function inlineMarkdownEditor(o) {
o.processSections = require('./processSections.js');
var el = $(o.selector);
o.originalMarkdown = el.html();
o.preProcessor = o.preProcessor || function(m) { return m; }
// split by double-newline:
var sections = o.originalMarkdown
.replace(/\n[\n]+/g, "\n\n")
.split('\n\n');
var editableSections = [];
// we also do this inside processSection, but independently track here:
sections.forEach(function forEachSection(section, index) {
if (o.isEditable(section, o.originalMarkdown)) editableSections.push(section);
if (o.isEditable(section, o.preProcessor(o.originalMarkdown))) editableSections.push(section);
});
el.html('');
// we might start running processSections only on editableSections...
Expand Down Expand Up @@ -10299,8 +10300,8 @@ module.exports = function isEditable(markdown, originalMarkdown) {

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

if (o.preProcessor) filteredMarkdown = o.preProcessor(markdown);
var originalSectionMarkdown = markdown;
filteredMarkdown = o.preProcessor(markdown);
html = o.defaultMarkdown(filteredMarkdown);

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

function insertFormIfMarkdown(_markdown, el, uniqueId) {
if (o.isEditable(_markdown, o.originalMarkdown)) {
if (o.isEditable(_markdown, o.preProcessor(o.originalMarkdown))) {
var formHtml = o.buildSectionForm(uniqueId, _markdown);
el.after(formHtml);
var _form = $('#' + uniqueId);
Expand All @@ -10351,16 +10353,16 @@ module.exports = function processSection(markdown, o) {
var editor;
if (o.wysiwyg && $('#' + uniqueId).find('.wk-container').length === 0) {
// insert rich editor
editor = new PL.Editor({
textarea: $('#' + uniqueId + ' textarea')[0]
});
var editorOptions = o.editorOptions || {};
editorOptions.textarea = $('#' + uniqueId + ' textarea')[0];
editor = new PL.Editor(editorOptions);
}
_form.find('.cancel').click(function inlineEditCancelClick(e) {
e.preventDefault();
_form.hide();
});
_form.find('button.submit').click(function(e) {
prepareAndSendSectionForm(e, _form, editor, _markdown);
prepareAndSendSectionForm(e, _form, editor, originalSectionMarkdown);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "inline-markdown-editor",
"version": "0.2.3",
"version": "0.3.0",
"description": "An inline wysiwyg markdown document editor based on replacing string subsections. WYSIWYG possible via woofmark.",
"main": "dist/inlineMarkdownEditor.js",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion src/inlineMarkdownEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ inlineMarkdownEditor = function inlineMarkdownEditor(o) {
o.processSections = require('./processSections.js');
var el = $(o.selector);
o.originalMarkdown = el.html();
o.preProcessor = o.preProcessor || function(m) { return m; }
// split by double-newline:
var sections = o.originalMarkdown
.replace(/\n[\n]+/g, "\n\n")
.split('\n\n');
var editableSections = [];
// we also do this inside processSection, but independently track here:
sections.forEach(function forEachSection(section, index) {
if (o.isEditable(section, o.originalMarkdown)) editableSections.push(section);
if (o.isEditable(section, o.preProcessor(o.originalMarkdown))) editableSections.push(section);
});
el.html('');
// we might start running processSections only on editableSections...
Expand Down
2 changes: 1 addition & 1 deletion src/onComplete.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = function onComplete(response, markdown, html, el, uniqueId, form, o) {
var message = form.find('.section-message');
if (response === 'true' || response === true) {
var message = $('#' + uniqueId + ' .section-message');
message.html('<i class="fa fa-check" style="color:green;"></i>');
//markdown = changes;
$('#' + uniqueId + ' textarea').val('');
Expand Down
13 changes: 7 additions & 6 deletions src/processSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module.exports = function processSection(markdown, o) {
uniqueId = "section-form-" + randomNum,
filteredMarkdown = markdown;

if (o.preProcessor) filteredMarkdown = o.preProcessor(markdown);
var originalSectionMarkdown = markdown;
filteredMarkdown = o.preProcessor(markdown);
html = o.defaultMarkdown(filteredMarkdown);

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

function insertFormIfMarkdown(_markdown, el, uniqueId) {
if (o.isEditable(_markdown, o.originalMarkdown)) {
if (o.isEditable(_markdown, o.preProcessor(o.originalMarkdown))) {
var formHtml = o.buildSectionForm(uniqueId, _markdown);
el.after(formHtml);
var _form = $('#' + uniqueId);
Expand All @@ -27,16 +28,16 @@ module.exports = function processSection(markdown, o) {
var editor;
if (o.wysiwyg && $('#' + uniqueId).find('.wk-container').length === 0) {
// insert rich editor
editor = new PL.Editor({
textarea: $('#' + uniqueId + ' textarea')[0]
});
var editorOptions = o.editorOptions || {};
editorOptions.textarea = $('#' + uniqueId + ' textarea')[0];
editor = new PL.Editor(editorOptions);
}
_form.find('.cancel').click(function inlineEditCancelClick(e) {
e.preventDefault();
_form.hide();
});
_form.find('button.submit').click(function(e) {
prepareAndSendSectionForm(e, _form, editor, _markdown);
prepareAndSendSectionForm(e, _form, editor, originalSectionMarkdown);
});
}
}
Expand Down

0 comments on commit e57d79f

Please sign in to comment.