Skip to content

Commit b89a9d2

Browse files
authored
Merge pull request #10 from jywarren/newline-issue
double newline fix
2 parents abf1329 + 1a142eb commit b89a9d2

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

dist/inlineMarkdownEditor.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -10238,7 +10238,9 @@ inlineMarkdownEditor = function inlineMarkdownEditor(o) {
1023810238
var el = $(o.selector);
1023910239
o.originalMarkdown = el.html();
1024010240
// split by double-newline:
10241-
var sections = o.originalMarkdown.split('\n\n');
10241+
var sections = o.originalMarkdown
10242+
.replace(/\n[\n]+/g, "\n\n")
10243+
.split('\n\n');
1024210244
var editableSections = [];
1024310245
// we also do this inside processSection, but independently track here:
1024410246
sections.forEach(function forEachSection(section, index) {

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.0",
3+
"version": "0.2.1",
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

+16-5
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,23 @@ describe("Editor", function() {
3232
});
3333

3434
it("generates the right number of sections", function() {
35-
expect(editor.sections.length).toBe(6);
36-
expect($('.inline-section').length).toBe(6);
35+
expect(editor.sections.length).toBe(8);
36+
expect($('.inline-section').length).toBe(8);
3737
expect(editor.sections[0]).toBe('');
38-
expect(editor.editableSections.length).toBe(3);
39-
expect($('.inline-edit-form').length).toBe(3);
40-
expect($('.inline-edit-form textarea').length).toBe(3);
38+
expect(editor.editableSections.length).toBe(5);
39+
expect($('.inline-edit-form').length).toBe(5);
40+
expect($('.inline-edit-form textarea').length).toBe(5);
41+
});
42+
43+
it("correctly splits up sections", function() {
44+
expect(editor.sections[0]).toBe("");
45+
expect(editor.sections[1]).toBe("### Hello, World");
46+
expect(editor.sections[2]).toBe("This is a paragraph.");
47+
expect(editor.sections[3]).toBe("* this\n* is\n* a\n* list");
48+
expect(editor.sections[4]).toBe("****");
49+
expect(editor.sections[5]).toBe("### Hello again, World");
50+
expect(editor.sections[6]).toBe("### Hello finally");
51+
expect(editor.sections[7]).toBe("");
4152
});
4253

4354
});

spec/javascripts/fixtures/index.html

+7
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,11 @@
1111

1212
****
1313

14+
15+
### Hello again, World
16+
17+
18+
19+
### Hello finally
20+
1421
</div>

src/inlineMarkdownEditor.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ inlineMarkdownEditor = function inlineMarkdownEditor(o) {
99
var el = $(o.selector);
1010
o.originalMarkdown = el.html();
1111
// split by double-newline:
12-
var sections = o.originalMarkdown.split('\n\n');
12+
var sections = o.originalMarkdown
13+
.replace(/\n[\n]+/g, "\n\n")
14+
.split('\n\n');
1315
var editableSections = [];
1416
// we also do this inside processSection, but independently track here:
1517
sections.forEach(function forEachSection(section, index) {

0 commit comments

Comments
 (0)