Skip to content

Commit

Permalink
Retain new lines in wysiwyg editor.
Browse files Browse the repository at this point in the history
  • Loading branch information
amolenaar committed Jul 30, 2015
1 parent 2f5c596 commit d30d4ef
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
53 changes: 29 additions & 24 deletions src/fitnesse/resources/wysiwyg/wikitext-spec.js
Expand Up @@ -216,24 +216,24 @@ describe("parser and formatter", function () {

it("should ignore nested code blocks", function() {
var dom = fragment(
element("p", element("pre", br(), "#!python", br(), "= level 1", br(), "{{{", br(), "= level 2", br()), " = level 1}}}"));
var wikitext = [
element("p", element("pre", br(), "#!python", br(), "= level 1", br(), "{{{", br(), "= level 2", br()), br(), "= level 1}}}"));
generateFragment(dom, [
"{{{",
"#!python",
"= level 1",
"{{{",
"= level 2",
"}}}",
"= level 1",
"}}}" ].join("\n");
generateFragment(dom, wikitext);
"}}}" ].join("\n"));
generateWikitext(dom, [
"{{{",
"#!python",
"= level 1",
"{{{",
"= level 2",
"}}}= level 1}}}" ].join("\n"));
"}}}",
"= level 1}}}" ].join("\n"));
});


Expand All @@ -251,19 +251,14 @@ describe("parser and formatter", function () {

it("paragraph", function() {
var dom = fragment(
element("p", "Paragraph continued..."),
element("p", "Second paragraph continued..."));
generateFragment(dom, [
element("p", "Paragraph", br(), "continued..."),
element("p", "Second paragraph", br(), "continued..."));
generate(dom, [
"Paragraph",
"continued...",
"",
"Second paragraph",
"continued...",
"" ].join("\n"));
generate(dom, [
"Paragraph continued...",
"",
"Second paragraph continued..." ].join("\n"));
"continued..." ].join("\n"));
});

it("link", function() {
Expand Down Expand Up @@ -817,7 +812,7 @@ describe("parser and formatter", function () {
element("ul",
element("li", "sub 2.1"),
element("li", "sub 2.2"))),
element("p", "a. item A b. item B Paragraph"));
element("p", "a. item A", br(), "b. item B", br(), "Paragraph"));
generateFragment(dom, [
"- item 1",
"- item 2",
Expand All @@ -832,7 +827,9 @@ describe("parser and formatter", function () {
" * sub 2.1",
" * sub 2.2",
"",
"a. item A b. item B Paragraph" ].join("\n"));
"a. item A",
"b. item B",
"Paragraph" ].join("\n"));
});

it("list + code block", function() {
Expand Down Expand Up @@ -1240,20 +1237,28 @@ describe("parser and formatter", function () {
element("th", "cell", br(), "2")))));
var wikitext = editor.domToWikitext(dom, { formatCodeBlock: true });
expect(wikitext).toBe([
"!1 Heading 1",
"!2 Heading 2",
"!3 Heading 3",
"!4 Heading 4",
"!5 Heading 5",
"!6 Heading 6",
"!1 Heading",
"1",
"!2 Heading",
"2",
"!3 Heading",
"3",
"!4 Heading",
"4",
"!5 Heading",
"5",
"!6 Heading",
"6",
"var Wysiwyg = function(textarea) { ... }",
"",
"> citation continued",
"",
"quote continued",
"",
" * item 1 continued",
" 1 item 1.1",
" * item 1",
"continued",
" 1 item",
"1.1",
"",
"!define def {dt dd}",
"| cell!-",
Expand Down
6 changes: 4 additions & 2 deletions src/fitnesse/resources/wysiwyg/wysiwyg.js
Expand Up @@ -2267,7 +2267,9 @@ Wysiwyg.prototype.wikitextToFragment = function (wikitext, contentDocument) {

if (text || (match && matchNumber > 0)) {
if (inParagraph() && (prevIndex === 0)) {
text = text ? ((holder.hasChildNodes() && holder.lastChild.tagName !== 'BR' ? " " : "") + text) : "";
if (text && holder.hasChildNodes() && holder.lastChild.tagName !== 'BR') {
holder.appendChild(contentDocument.createElement("br"));
}
}
if ((listDepth.length === 0 && !inTable() && !currentHeader) || holder === fragment) {
openParagraph();
Expand Down Expand Up @@ -2788,7 +2790,7 @@ Wysiwyg.prototype.domToWikitext = function (root, options) {
} else if (escapeNewLines && node.nextSibling) {
_texts.push("!-\n-!");
} else if (!self.isBogusLineBreak(node)) {
_texts.push(" ");
_texts.push("\n");
}
break;
case "pre":
Expand Down

0 comments on commit d30d4ef

Please sign in to comment.