Changeset 2819

Show
Ignore:
Timestamp:
11/24/07 20:41:32 (1 year ago)
Author:
jun66j5
Message:

fixed #2119, #2198 - a problem with assigning "code block" style.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tracwysiwygplugin/0.10/tests/testcase.js

    r2816 r2819  
    599599                ">This is the quoted text continued", 
    600600                ">>a nested quote", 
     601                "", 
    601602                "A comment on the above", 
    602603                "", 
     
    10541055                ' </tr>', 
    10551056                '</tbody></table>', 
    1056                 '' ].join(""); 
     1057                '' ].join("\n"); 
    10571058            generateWikitext.call(this, dom, [ 
    10581059                "||a[[BR]][[BR]]b||b||", 
    10591060                "||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); 
    10601116        }); 
    10611117 
  • tracwysiwygplugin/0.10/tests/testunit.js

    r2794 r2819  
    1111        switch (type) { 
    1212        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) { 
    1414                var code = m.charCodeAt(0); 
    1515                switch (code) { 
     
    1919                case 12: return "\\f"; 
    2020                case 13: return "\\r"; 
     21                case 92: return "\\\\"; 
    2122                } 
    22                 return "\\" + (0x10000 + code).toString(16).substring(1); 
     23                return "\\u" + (0x10000 + code).toString(16).substring(1); 
    2324            }); 
    2425            break; 
  • tracwysiwygplugin/0.10/tracwysiwyg/htdocs/wysiwyg.js

    r2816 r2819  
    682682 
    683683    var fragment = this.getSelectionFragment(); 
    684     text = this.domToWikitext(fragment).replace(/\s+$/, ""); 
     684    text = this.domToWikitext(fragment, { formatCodeBlock: true }).replace(/\s+$/, ""); 
    685685 
    686686    var d = this.contentDocument; 
     
    17571757    "span": true }; 
    17581758 
    1759 TracWysiwyg.prototype.domToWikitext = function(root) { 
     1759TracWysiwyg.prototype.domToWikitext = function(root, options) { 
     1760    options = options || {}; 
     1761    var formatCodeBlock = !!options.formatCodeBlock; 
     1762 
    17601763    var self = this; 
    17611764    var getTextContent = TracWysiwyg.getTextContent; 
     
    17741777    var quoteDepth = 0; 
    17751778    var quoteCitation = false; 
    1776     var needEscape = true; 
    17771779    var inCodeBlock = false; 
    17781780    var skipNode = null; 
     
    20352037                        } 
    20362038                        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                        } 
    20402042                    } 
    20412043                    if (value) { 
     
    21022104                        value = "\n"; 
    21032105                    } 
     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                    } 
    21042129                    else if (isTailEscape()) { 
    21052130                        value = " [[BR]]"; 
     
    21152140                    /^(?:li|dd)$/i.test(node.parentNode.tagName) || self.isInlineNode(node.previousSibling) 
    21162141                    ? "\n{{{\n" : "{{{\n"); 
    2117                 needEscape = false; 
    21182142                inCodeBlock = true; 
    21192143                break; 
     
    22372261                } 
    22382262                texts.push(text); 
    2239                 needEscape = true; 
    22402263                inCodeBlock = false; 
    22412264                break; 
    22422265            case "blockquote": 
    22432266                quoteDepth--; 
    2244                 if (quoteDepth == 0 && !quoteCitation) { 
     2267                if (quoteDepth == 0) { 
    22452268                    texts.push("\n"); 
    22462269                } 
  • tracwysiwygplugin/0.11/tests/testcase.js

    r2816 r2819  
    599599                ">This is the quoted text continued", 
    600600                ">>a nested quote", 
     601                "", 
    601602                "A comment on the above", 
    602603                "", 
     
    10541055                ' </tr>', 
    10551056                '</tbody></table>', 
    1056                 '' ].join(""); 
     1057                '' ].join("\n"); 
    10571058            generateWikitext.call(this, dom, [ 
    10581059                "||a[[BR]][[BR]]b||b||", 
    10591060                "||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); 
    10601116        }); 
    10611117 
  • tracwysiwygplugin/0.11/tests/testunit.js

    r2794 r2819  
    1111        switch (type) { 
    1212        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) { 
    1414                var code = m.charCodeAt(0); 
    1515                switch (code) { 
     
    1919                case 12: return "\\f"; 
    2020                case 13: return "\\r"; 
     21                case 92: return "\\\\"; 
    2122                } 
    22                 return "\\" + (0x10000 + code).toString(16).substring(1); 
     23                return "\\u" + (0x10000 + code).toString(16).substring(1); 
    2324            }); 
    2425            break; 
  • tracwysiwygplugin/0.11/tracwysiwyg/htdocs/wysiwyg.js

    r2816 r2819  
    682682 
    683683    var fragment = this.getSelectionFragment(); 
    684     text = this.domToWikitext(fragment).replace(/\s+$/, ""); 
     684    text = this.domToWikitext(fragment, { formatCodeBlock: true }).replace(/\s+$/, ""); 
    685685 
    686686    var d = this.contentDocument; 
     
    17571757    "span": true }; 
    17581758 
    1759 TracWysiwyg.prototype.domToWikitext = function(root) { 
     1759TracWysiwyg.prototype.domToWikitext = function(root, options) { 
     1760    options = options || {}; 
     1761    var formatCodeBlock = !!options.formatCodeBlock; 
     1762 
    17601763    var self = this; 
    17611764    var getTextContent = TracWysiwyg.getTextContent; 
     
    17741777    var quoteDepth = 0; 
    17751778    var quoteCitation = false; 
    1776     var needEscape = true; 
    17771779    var inCodeBlock = false; 
    17781780    var skipNode = null; 
     
    20352037                        } 
    20362038                        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                        } 
    20402042                    } 
    20412043                    if (value) { 
     
    21022104                        value = "\n"; 
    21032105                    } 
     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                    } 
    21042129                    else if (isTailEscape()) { 
    21052130                        value = " [[BR]]"; 
     
    21152140                    /^(?:li|dd)$/i.test(node.parentNode.tagName) || self.isInlineNode(node.previousSibling) 
    21162141                    ? "\n{{{\n" : "{{{\n"); 
    2117                 needEscape = false; 
    21182142                inCodeBlock = true; 
    21192143                break; 
     
    22372261                } 
    22382262                texts.push(text); 
    2239                 needEscape = true; 
    22402263                inCodeBlock = false; 
    22412264                break; 
    22422265            case "blockquote": 
    22432266                quoteDepth--; 
    2244                 if (quoteDepth == 0 && !quoteCitation) { 
     2267                if (quoteDepth == 0) { 
    22452268                    texts.push("\n"); 
    22462269                }