Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Panel #94

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
50 changes: 39 additions & 11 deletions dist/inlineMarkdownEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10227,6 +10227,28 @@ module.exports = function defaultMarkdown(element) {
}

},{"megamark":91}],96:[function(require,module,exports){
// split by double-newline, but preserve HTML blocks as single sections:
module.exports = function divideIntoSections(content) {
var sections = [];
content = content.replace(/[\n]{2,}/g, "\n\n"); // manage double newlines (not sure exactly?)
chunkArray = content.replace(/(<(.+).*>.+<\/\2>)/g,"@@@@@@$1").split(/@@@@@@|\n\n/);

chunkArray = chunkArray.filter(function (x) {
return (x !== undefined && x !== '' && x.match(/\S/) !== null); // probably overzealous filtering of "empty" sections
});

chunkArray.forEach(function(chunk) {
if (chunk.match(/<\w>/)) {
sections.push(chunk); // it's an HTML chunk
} else {
sections = sections.concat(chunk.split("\n\n")); // split by double newline and add
}
});

return sections;
}

},{}],97:[function(require,module,exports){
inlineMarkdownEditor = function inlineMarkdownEditor(o) {
o.defaultMarkdown = o.defaultMarkdown || require('./defaultMarkdown.js');
o.buildSectionForm = o.buildSectionForm || require('./buildSectionForm.js');
Expand All @@ -10239,7 +10261,8 @@ inlineMarkdownEditor = function inlineMarkdownEditor(o) {
o.originalMarkdown = el.html();
o.preProcessor = o.preProcessor || function(m) { return m; }
// split by double-newline:
var sections = o.originalMarkdown.replace(/[\n]{2,}/g, "\n\n").split("\n\n");
o.divideIntoSections = o.divideIntoSections || require('./divideIntoSections.js');
var sections = o.divideIntoSections(o.originalMarkdown);
var editableSections = [];
// we also do this inside processSection, but independently track here:
sections.forEach(function forEachSection(section, index) {
Expand All @@ -10258,7 +10281,7 @@ inlineMarkdownEditor = function inlineMarkdownEditor(o) {
}
module.exports = inlineMarkdownEditor;

},{"./buildSectionForm.js":94,"./defaultMarkdown.js":95,"./insertEditLink.js":97,"./isEditable.js":98,"./onComplete.js":99,"./onFail.js":100,"./processSections.js":102}],97:[function(require,module,exports){
},{"./buildSectionForm.js":94,"./defaultMarkdown.js":95,"./divideIntoSections.js":96,"./insertEditLink.js":98,"./isEditable.js":99,"./onComplete.js":100,"./onFail.js":101,"./processSections.js":103}],98:[function(require,module,exports){
module.exports = function insertEditLink(uniqueId, el, form, onEdit, editor, o) {
var editBtns = "";
editBtns += "<span class='inline-edit-btns inline-edit-btns-" + uniqueId + "'>";
Expand All @@ -10283,11 +10306,11 @@ module.exports = function insertEditLink(uniqueId, el, form, onEdit, editor, o)
});
}

},{}],98:[function(require,module,exports){
},{}],99:[function(require,module,exports){
module.exports = function isEditable(markdown, originalMarkdown) {
originalMarkdown = originalMarkdown || markdown; // optional parameter for checking against original complete text
// filter? Only p,h1-5,ul?
var editable = markdown.match(/</) === null; // has tags; exclueds HTML
var editable = markdown.match(/</) === null; // has tags; excludes HTML
editable = editable && markdown.match(/\*\*\*\*/) === null; // no horizontal rules: ****
editable = editable && markdown.match(/\-\-\-\-/) === null; // no horizontal rules: ----
editable = editable && markdown !== ''; // no blanks
Expand All @@ -10296,7 +10319,7 @@ module.exports = function isEditable(markdown, originalMarkdown) {
return editable;
}

},{}],99:[function(require,module,exports){
},{}],100:[function(require,module,exports){
module.exports = function onComplete(response, markdown, html, el, uniqueId, form, o) {
var message = form.find('.section-message');
if (response === 200) {
Expand All @@ -10314,13 +10337,13 @@ module.exports = function onComplete(response, markdown, html, el, uniqueId, for
}
}

},{}],100:[function(require,module,exports){
},{}],101:[function(require,module,exports){
module.exports = function onFail(response, uniqueId) {
var message = $('#' + uniqueId + ' .section-message');
message.html('There was an error -- the wiki page may have changed while you were editing; save your content in the clipboard and try refreshing the page.');
}

},{}],101:[function(require,module,exports){
},{}],102:[function(require,module,exports){
module.exports = function processSection(markdown, o) {
var html,
randomNum = parseInt(Math.random() * 10000),
Expand Down Expand Up @@ -10353,6 +10376,7 @@ module.exports = function processSection(markdown, o) {
// insert rich editor
var editorOptions = o.editorOptions || {};
editorOptions.textarea = $('#' + uniqueId + ' textarea')[0];
editorOptions.tagsModule = (editorOptions.tagsModule === true); // disable this to not require Bloodhound, unless overridden
editor = new PL.Editor(editorOptions);
}
_form.find('.cancel').click(function inlineEditCancelClick(e) {
Expand Down Expand Up @@ -10380,8 +10404,12 @@ module.exports = function processSection(markdown, o) {
after: after // encodeURI(after)
})
.done(function onComplete(result, success, xhr) {
// we should need fewer things here:
o.onComplete(xhr.status, after, html, _el, uniqueId, __form, o);
if (result == "false") {
o.onFail(result, uniqueId);
} else {
// we should need fewer things here:
o.onComplete(xhr.status, after, html, _el, uniqueId, __form, o);
}
}).fail(function onFail(response) {
o.onFail(response, uniqueId);
}); // these don't work?
Expand All @@ -10391,12 +10419,12 @@ module.exports = function processSection(markdown, o) {
}
}

},{}],102:[function(require,module,exports){
},{}],103:[function(require,module,exports){
module.exports = function processSections(sections, o) {
sections.forEach(function(markdown) {
processSection = require('./processSection.js');
processSection(markdown, o);
});
}

},{"./processSection.js":101}]},{},[96]);
},{"./processSection.js":102}]},{},[97]);
11 changes: 10 additions & 1 deletion examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<title>inline-markdown-editor</title>

<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#000"/>
<meta http-equiv="content-type" content="text/html; charset=UTF8">

<link href="../node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
Expand Down Expand Up @@ -40,7 +41,15 @@ <h3>
* this
* is
* a
* list</div>
* list

<p>
<input type="text" />
</p>

(above, raw HTML blocks should be undisturbed)

</div>

<script>

Expand Down
1 change: 0 additions & 1 deletion examples/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
}

body {
padding: 20px;
margin: 0 auto;
max-width: 700px;
background: #f8f8fa;
Expand Down
1 change: 1 addition & 0 deletions examples/wysiwyg.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<title>inline-markdown-editor</title>

<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#000"/>
<meta http-equiv="content-type" content="text/html; charset=UTF8">

<link href="../node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
Expand Down
Loading