Skip to content

Commit 1f30d5c

Browse files
committed
v0.0.5, no ambiguous replaces, message fix
1 parent e62fd40 commit 1f30d5c

8 files changed

+39
-7
lines changed

dist/inlineMarkdownEditor.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -10236,8 +10236,9 @@ inlineMarkdownEditor = function inlineMarkdownEditor(o) {
1023610236
o.isEditable = o.isEditable || require('./isEditable.js');
1023710237
o.processSections = require('./processSections.js');
1023810238
var el = $(o.selector);
10239+
o.originalMarkdown = el.html();
1023910240
// split by double-newline:
10240-
var sections = el.html().split('\n\n');
10241+
var sections = o.originalMarkdown.split('\n\n');
1024110242
el.html('');
1024210243
o.processSections(sections, o);
1024310244
el.show();
@@ -10266,18 +10267,22 @@ module.exports = function insertEditLink(uniqueId, el, form, onEdit, editor) {
1026610267
}
1026710268

1026810269
},{}],98:[function(require,module,exports){
10269-
module.exports = function isEditable(markdown) {
10270+
module.exports = function isEditable(markdown, originalMarkdown) {
10271+
originalMarkdown = originalMarkdown || markdown; // optional parameter for checking against original complete text
1027010272
// filter? Only p,h1-5,ul?
1027110273
var editable = markdown.match(/</) === null; // has tags; exclueds HTML
1027210274
editable = editable && markdown.match(/\*\*\*\*/) === null; // no horizontal rules: ****
1027310275
editable = editable && markdown.match(/\-\-\-\-/) === null; // no horizontal rules: ----
1027410276
editable = editable && markdown !== ''; // no blanks
10277+
// here we disallow if more than one instance in original string:
10278+
editable = editable && originalMarkdown.split(markdown).length === 2 // couldn't get match options to work with string
1027510279
return editable;
1027610280
}
1027710281

1027810282
},{}],99:[function(require,module,exports){
1027910283
module.exports = function onComplete(response, markdown, html, el, uniqueId, form, o) {
1028010284
if (response === 'true' || response === true) {
10285+
var message = $('#' + uniqueId + ' .section-message');
1028110286
message.html('<i class="fa fa-check" style="color:green;"></i>');
1028210287
markdown = changes;
1028310288
$('#' + uniqueId + ' textarea').val('');
@@ -10318,7 +10323,7 @@ module.exports = function processSection(markdown, o) {
1031810323
var message = $('#' + uniqueId + ' .section-message');
1031910324

1032010325
function insertFormIfMarkdown(_markdown, el, uniqueId) {
10321-
if (o.isEditable(_markdown)) {
10326+
if (o.isEditable(_markdown, o.originalMarkdown)) {
1032210327
var formHtml = o.buildSectionForm(uniqueId, _markdown);
1032310328
el.after(formHtml);
1032410329
var form = $('#' + uniqueId);

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.0.4",
3+
"version": "0.0.5",
44
"description": "An inline wysiwyg markdown document editor based on replacing string subsections. WYSIWYG possible via woofmark.",
55
"main": "dist/inlineMarkdownEditor.js",
66
"scripts": {

spec/javascripts/editor_spec.js

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ describe("Editor", function() {
2525
expect(isEditable('Just a simple string.')).toBe(true);
2626
});
2727

28+
it("correctly assesses isEditable when comparing to original full text; no duplicates", function() {
29+
var isEditable = editor.options.isEditable
30+
expect(isEditable('phrase', 'One phrase, two phrase.')).toBe(false);
31+
expect(isEditable('One', 'One phrase, two phrase.')).toBe(true);
32+
});
33+
2834
it("generates the right number of sections", function() {
2935
expect(editor.sections.length).toBe(6);
3036
expect($('.inline-section').length).toBe(6);

spec/javascripts/replacement_spec.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
describe("Replacement functions", function() {
2+
3+
var editor;
4+
5+
it("won't generate an editor for an ambiguous (duplicated) section, where replacement server side could apply to the wrong section", function() {
6+
fixture = loadFixtures('index.html');
7+
var html = "Unique text.\n\nDuplicated text.\n\nDuplicated text."
8+
$('.markdown').html(html);
9+
editor = inlineMarkdownEditor({
10+
replaceUrl: '/wiki/replace/',
11+
selector: '.markdown'
12+
});
13+
expect($('.inline-edit-form textarea').length).toBe(1);
14+
});
15+
16+
});

src/inlineMarkdownEditor.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ inlineMarkdownEditor = function inlineMarkdownEditor(o) {
77
o.isEditable = o.isEditable || require('./isEditable.js');
88
o.processSections = require('./processSections.js');
99
var el = $(o.selector);
10+
o.originalMarkdown = el.html();
1011
// split by double-newline:
11-
var sections = el.html().split('\n\n');
12+
var sections = o.originalMarkdown.split('\n\n');
1213
el.html('');
1314
o.processSections(sections, o);
1415
el.show();

src/isEditable.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
module.exports = function isEditable(markdown) {
1+
module.exports = function isEditable(markdown, originalMarkdown) {
2+
originalMarkdown = originalMarkdown || markdown; // optional parameter for checking against original complete text
23
// filter? Only p,h1-5,ul?
34
var editable = markdown.match(/</) === null; // has tags; exclueds HTML
45
editable = editable && markdown.match(/\*\*\*\*/) === null; // no horizontal rules: ****
56
editable = editable && markdown.match(/\-\-\-\-/) === null; // no horizontal rules: ----
67
editable = editable && markdown !== ''; // no blanks
8+
// here we disallow if more than one instance in original string:
9+
editable = editable && originalMarkdown.split(markdown).length === 2 // couldn't get match options to work with string
710
return editable;
811
}

src/onComplete.js

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

src/processSection.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = function processSection(markdown, o) {
1717
var message = $('#' + uniqueId + ' .section-message');
1818

1919
function insertFormIfMarkdown(_markdown, el, uniqueId) {
20-
if (o.isEditable(_markdown)) {
20+
if (o.isEditable(_markdown, o.originalMarkdown)) {
2121
var formHtml = o.buildSectionForm(uniqueId, _markdown);
2222
el.after(formHtml);
2323
var form = $('#' + uniqueId);

0 commit comments

Comments
 (0)