Changeset 2819
- Timestamp:
- 11/24/07 20:41:32 (1 year ago)
- Files:
-
- tracwysiwygplugin/0.10/tests/testcase.js (modified) (2 diffs)
- tracwysiwygplugin/0.10/tests/testunit.js (modified) (2 diffs)
- tracwysiwygplugin/0.10/tracwysiwyg/htdocs/wysiwyg.js (modified) (7 diffs)
- tracwysiwygplugin/0.11/tests/testcase.js (modified) (2 diffs)
- tracwysiwygplugin/0.11/tests/testunit.js (modified) (2 diffs)
- tracwysiwygplugin/0.11/tracwysiwyg/htdocs/wysiwyg.js (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
tracwysiwygplugin/0.10/tests/testcase.js
r2816 r2819 599 599 ">This is the quoted text continued", 600 600 ">>a nested quote", 601 "", 601 602 "A comment on the above", 602 603 "", … … 1054 1055 ' </tr>', 1055 1056 '</tbody></table>', 1056 '' ].join(" ");1057 '' ].join("\n"); 1057 1058 generateWikitext.call(this, dom, [ 1058 1059 "||a[[BR]][[BR]]b||b||", 1059 1060 "||c||d||" ].join("\n")); 1061 }); 1062 1063 unit.add("domToWikitext for code block", function() { 1064 var br = function() { return element("br") }; 1065 var dom = fragment( 1066 element("h1", "Heading", br(), "1"), 1067 element("h2", "Heading", br(), "2"), 1068 element("h3", "Heading", br(), "3"), 1069 element("h4", "Heading", br(), "4"), 1070 element("h5", "Heading", br(), "5"), 1071 element("h6", "Heading", br(), "6"), 1072 element("p", 1073 "var TracWysiwyg = function(textarea) {", br(), 1074 "...", br(), 1075 "}"), 1076 element("blockquote", { "class": "citation" }, element("p", "citation", br(), "continued")), 1077 element("blockquote", element("p", "quote", br(), "continued")), 1078 element("ul", 1079 element("li", "item 1", br(), "continued"), 1080 element("ol", element("li", "item", br(), "1.1"))), 1081 element("dl", 1082 element("dt", "def to_s(", br(), ")"), 1083 element("dd", "dt", br(), "dd")), 1084 element("table", 1085 element("tbody", 1086 element("tr", 1087 element("td", "cell", br(), "1"), 1088 element("th", "cell", br(), "2"))))); 1089 var wikitext = instance.domToWikitext(dom, { formatCodeBlock: true }); 1090 this.assertEqual([ 1091 "= Heading 1 =", 1092 "== Heading 2 ==", 1093 "=== Heading 3 ===", 1094 "==== Heading 4 ====", 1095 "===== Heading 5 =====", 1096 "====== Heading 6 ======", 1097 "var TracWysiwyg = function(textarea) {", 1098 "...", 1099 "}", 1100 "", 1101 ">citation", 1102 ">continued", 1103 "", 1104 " quote", 1105 " continued", 1106 "", 1107 " * item 1", 1108 " continued", 1109 " 1. item", 1110 " 1.1", 1111 "", 1112 " def to_s( ):: dt", 1113 " dd", 1114 "", 1115 "||cell[[BR]]1||cell[[BR]]2||" ].join("\n"), wikitext); 1060 1116 }); 1061 1117 tracwysiwygplugin/0.10/tests/testunit.js
r2794 r2819 11 11 switch (type) { 12 12 case "string": 13 return value.replace(/[\u0000-\u001f\ u007f\ufffe\uffff]/g, function(m) {13 return value.replace(/[\u0000-\u001f\\\u007f\ufffe\uffff]/g, function(m) { 14 14 var code = m.charCodeAt(0); 15 15 switch (code) { … … 19 19 case 12: return "\\f"; 20 20 case 13: return "\\r"; 21 case 92: return "\\\\"; 21 22 } 22 return "\\ " + (0x10000 + code).toString(16).substring(1);23 return "\\u" + (0x10000 + code).toString(16).substring(1); 23 24 }); 24 25 break; tracwysiwygplugin/0.10/tracwysiwyg/htdocs/wysiwyg.js
r2816 r2819 682 682 683 683 var fragment = this.getSelectionFragment(); 684 text = this.domToWikitext(fragment ).replace(/\s+$/, "");684 text = this.domToWikitext(fragment, { formatCodeBlock: true }).replace(/\s+$/, ""); 685 685 686 686 var d = this.contentDocument; … … 1757 1757 "span": true }; 1758 1758 1759 TracWysiwyg.prototype.domToWikitext = function(root) { 1759 TracWysiwyg.prototype.domToWikitext = function(root, options) { 1760 options = options || {}; 1761 var formatCodeBlock = !!options.formatCodeBlock; 1762 1760 1763 var self = this; 1761 1764 var getTextContent = TracWysiwyg.getTextContent; … … 1774 1777 var quoteDepth = 0; 1775 1778 var quoteCitation = false; 1776 var needEscape = true;1777 1779 var inCodeBlock = false; 1778 1780 var skipNode = null; … … 2035 2037 } 2036 2038 value = value.replace(/\r?\n/g, " "); 2037 }2038 if (needEscape) {2039 value = value.replace(wikiInlineRulesPattern, escapeText);2039 if (!formatCodeBlock) { 2040 value = value.replace(wikiInlineRulesPattern, escapeText); 2041 } 2040 2042 } 2041 2043 if (value) { … … 2102 2104 value = "\n"; 2103 2105 } 2106 else if (formatCodeBlock) { 2107 switch (((node.parentNode || {}).tagName || "").toLowerCase()) { 2108 case "li": 2109 value = "\n " + string(" ", listDepth); 2110 break; 2111 case "p": case "blockquote": 2112 value = "\n"; 2113 if (quoteDepth > 0) { 2114 value += string(quoteCitation ? ">" : " ", quoteDepth); 2115 } 2116 break; 2117 case "dd": 2118 value = "\n "; 2119 break; 2120 case "dt": 2121 case "h1": case "h2": case "h3": case "h4": case "h5": case "h6": 2122 value = " "; 2123 break; 2124 default: 2125 value = "\n"; 2126 break; 2127 } 2128 } 2104 2129 else if (isTailEscape()) { 2105 2130 value = " [[BR]]"; … … 2115 2140 /^(?:li|dd)$/i.test(node.parentNode.tagName) || self.isInlineNode(node.previousSibling) 2116 2141 ? "\n{{{\n" : "{{{\n"); 2117 needEscape = false;2118 2142 inCodeBlock = true; 2119 2143 break; … … 2237 2261 } 2238 2262 texts.push(text); 2239 needEscape = true;2240 2263 inCodeBlock = false; 2241 2264 break; 2242 2265 case "blockquote": 2243 2266 quoteDepth--; 2244 if (quoteDepth == 0 && !quoteCitation) {2267 if (quoteDepth == 0) { 2245 2268 texts.push("\n"); 2246 2269 } tracwysiwygplugin/0.11/tests/testcase.js
r2816 r2819 599 599 ">This is the quoted text continued", 600 600 ">>a nested quote", 601 "", 601 602 "A comment on the above", 602 603 "", … … 1054 1055 ' </tr>', 1055 1056 '</tbody></table>', 1056 '' ].join(" ");1057 '' ].join("\n"); 1057 1058 generateWikitext.call(this, dom, [ 1058 1059 "||a[[BR]][[BR]]b||b||", 1059 1060 "||c||d||" ].join("\n")); 1061 }); 1062 1063 unit.add("domToWikitext for code block", function() { 1064 var br = function() { return element("br") }; 1065 var dom = fragment( 1066 element("h1", "Heading", br(), "1"), 1067 element("h2", "Heading", br(), "2"), 1068 element("h3", "Heading", br(), "3"), 1069 element("h4", "Heading", br(), "4"), 1070 element("h5", "Heading", br(), "5"), 1071 element("h6", "Heading", br(), "6"), 1072 element("p", 1073 "var TracWysiwyg = function(textarea) {", br(), 1074 "...", br(), 1075 "}"), 1076 element("blockquote", { "class": "citation" }, element("p", "citation", br(), "continued")), 1077 element("blockquote", element("p", "quote", br(), "continued")), 1078 element("ul", 1079 element("li", "item 1", br(), "continued"), 1080 element("ol", element("li", "item", br(), "1.1"))), 1081 element("dl", 1082 element("dt", "def to_s(", br(), ")"), 1083 element("dd", "dt", br(), "dd")), 1084 element("table", 1085 element("tbody", 1086 element("tr", 1087 element("td", "cell", br(), "1"), 1088 element("th", "cell", br(), "2"))))); 1089 var wikitext = instance.domToWikitext(dom, { formatCodeBlock: true }); 1090 this.assertEqual([ 1091 "= Heading 1 =", 1092 "== Heading 2 ==", 1093 "=== Heading 3 ===", 1094 "==== Heading 4 ====", 1095 "===== Heading 5 =====", 1096 "====== Heading 6 ======", 1097 "var TracWysiwyg = function(textarea) {", 1098 "...", 1099 "}", 1100 "", 1101 ">citation", 1102 ">continued", 1103 "", 1104 " quote", 1105 " continued", 1106 "", 1107 " * item 1", 1108 " continued", 1109 " 1. item", 1110 " 1.1", 1111 "", 1112 " def to_s( ):: dt", 1113 " dd", 1114 "", 1115 "||cell[[BR]]1||cell[[BR]]2||" ].join("\n"), wikitext); 1060 1116 }); 1061 1117 tracwysiwygplugin/0.11/tests/testunit.js
r2794 r2819 11 11 switch (type) { 12 12 case "string": 13 return value.replace(/[\u0000-\u001f\ u007f\ufffe\uffff]/g, function(m) {13 return value.replace(/[\u0000-\u001f\\\u007f\ufffe\uffff]/g, function(m) { 14 14 var code = m.charCodeAt(0); 15 15 switch (code) { … … 19 19 case 12: return "\\f"; 20 20 case 13: return "\\r"; 21 case 92: return "\\\\"; 21 22 } 22 return "\\ " + (0x10000 + code).toString(16).substring(1);23 return "\\u" + (0x10000 + code).toString(16).substring(1); 23 24 }); 24 25 break; tracwysiwygplugin/0.11/tracwysiwyg/htdocs/wysiwyg.js
r2816 r2819 682 682 683 683 var fragment = this.getSelectionFragment(); 684 text = this.domToWikitext(fragment ).replace(/\s+$/, "");684 text = this.domToWikitext(fragment, { formatCodeBlock: true }).replace(/\s+$/, ""); 685 685 686 686 var d = this.contentDocument; … … 1757 1757 "span": true }; 1758 1758 1759 TracWysiwyg.prototype.domToWikitext = function(root) { 1759 TracWysiwyg.prototype.domToWikitext = function(root, options) { 1760 options = options || {}; 1761 var formatCodeBlock = !!options.formatCodeBlock; 1762 1760 1763 var self = this; 1761 1764 var getTextContent = TracWysiwyg.getTextContent; … … 1774 1777 var quoteDepth = 0; 1775 1778 var quoteCitation = false; 1776 var needEscape = true;1777 1779 var inCodeBlock = false; 1778 1780 var skipNode = null; … … 2035 2037 } 2036 2038 value = value.replace(/\r?\n/g, " "); 2037 }2038 if (needEscape) {2039 value = value.replace(wikiInlineRulesPattern, escapeText);2039 if (!formatCodeBlock) { 2040 value = value.replace(wikiInlineRulesPattern, escapeText); 2041 } 2040 2042 } 2041 2043 if (value) { … … 2102 2104 value = "\n"; 2103 2105 } 2106 else if (formatCodeBlock) { 2107 switch (((node.parentNode || {}).tagName || "").toLowerCase()) { 2108 case "li": 2109 value = "\n " + string(" ", listDepth); 2110 break; 2111 case "p": case "blockquote": 2112 value = "\n"; 2113 if (quoteDepth > 0) { 2114 value += string(quoteCitation ? ">" : " ", quoteDepth); 2115 } 2116 break; 2117 case "dd": 2118 value = "\n "; 2119 break; 2120 case "dt": 2121 case "h1": case "h2": case "h3": case "h4": case "h5": case "h6": 2122 value = " "; 2123 break; 2124 default: 2125 value = "\n"; 2126 break; 2127 } 2128 } 2104 2129 else if (isTailEscape()) { 2105 2130 value = " [[BR]]"; … … 2115 2140 /^(?:li|dd)$/i.test(node.parentNode.tagName) || self.isInlineNode(node.previousSibling) 2116 2141 ? "\n{{{\n" : "{{{\n"); 2117 needEscape = false;2118 2142 inCodeBlock = true; 2119 2143 break; … … 2237 2261 } 2238 2262 texts.push(text); 2239 needEscape = true;2240 2263 inCodeBlock = false; 2241 2264 break; 2242 2265 case "blockquote": 2243 2266 quoteDepth--; 2244 if (quoteDepth == 0 && !quoteCitation) {2267 if (quoteDepth == 0) { 2245 2268 texts.push("\n"); 2246 2269 }
