Changeset 2759

Show
Ignore:
Timestamp:
11/08/07 04:27:23 (1 year ago)
Author:
jun66j5
Message:
  • added unit tests.
  • fixed #2118
  • fixed some bugs in wikitext-generation.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tracwysiwygplugin/0.10/tracwysiwyg/htdocs/wysiwyg.js

    r2732 r2759  
    55    this.textarea = textarea; 
    66    var wikitextToolbar = textarea.previousSibling; 
    7     if (wikitextToolbar.nodeType != 1 || wikitextToolbar.className != "wikitoolbar") { 
     7    if (wikitextToolbar && (wikitextToolbar.nodeType != 1 || wikitextToolbar.className != "wikitoolbar")) { 
    88        wikitextToolbar = null; 
    99    } 
     
    12001200    } 
    12011201 
    1202     function handleWikiPageName(value) { 
    1203         createAnchor("wiki:" + value, value); 
     1202    function handleWikiPageName(name, label) { 
     1203        createAnchor("wiki:" + name, label || name); 
    12041204    } 
    12051205 
     
    16081608                    continue; 
    16091609                case 18:    // ["internal free link"] 
    1610                     handleWikiPageName(matchText.slice(1, -1)); 
     1610                    handleWikiPageName(matchText.slice(1, -1), matchText.slice(2, -2)); 
    16111611                    continue; 
    16121612                case 19:    // citation 
     
    16321632                        continue; 
    16331633                    } 
     1634                    matchText = matchText.replace(/^\s+/, " "); 
    16341635                    break; 
    16351636                case 24:    // opening table row 
     
    16571658                var tmp; 
    16581659                if (matchFirstIndex == 16) { 
    1659                     tmp = matchText.toLowerCase() == "[[br]]" 
    1660                         ? contentDocument.createElement("br") 
     1660                    tmp = /^!?\[\[br\]\]$/i.test(matchText) 
     1661                        ? (matchText.charCodeAt(0) == 0x21 
     1662                            ? contentDocument.createTextNode(matchText.substring(1)) 
     1663                            : contentDocument.createElement("br")) 
    16611664                        : contentDocument.createTextNode(matchText); 
    16621665                } 
     
    16961699    "dl": true, 
    16971700    "dt": " ", 
    1698     "dd": "   ", 
     1701    "dd": " ", 
    16991702    "table": true, 
    17001703    "tbody": true, 
     
    17161719    "hr": true, 
    17171720    "dl": "\n", 
    1718     "dt": "::\n", 
     1721    "dt": "::", 
    17191722    "dd": "\n", 
    17201723    "table": "\n", 
     
    17541757 
    17551758    function escapeText(s) { 
    1756         if (/^!?\[\[/.test(s) && /\]\]$/.test(s)) { 
    1757             return s != "[[BR]]" ? s : "!" + s; 
     1759        var match = /^!?\[\[(.+)\]\]$/.exec(s); 
     1760        if (match) { 
     1761            return match[1].toLowerCase() != "br" ? s : "!" + s; 
    17581762        } 
    17591763        if (/^&#\d+/.test(s)) { 
     
    19271931                switch (match[1]) { 
    19281932                case "changeset": 
    1929                     usingValue = value == "[" + match[2] + "]" 
    1930                         || /^\d+$/.test(match[2]) && value == "r" + match[2]; 
     1933                    usingValue = value == "[" + match[2] + "]"; 
    19311934                    break; 
    19321935                case "log": 
    1933                     usingValue = value == "[" + match[3] + "]" || value == "r" + match[3]
     1936                    usingValue = value == "[" + match[3] + "]"
    19341937                    break; 
    19351938                case "report": 
     
    19491952        } 
    19501953        if (text === null) { 
    1951             if (!/[\]\"\']/.test(value)) { 
     1954            if (!/\]/.test(value) && !/^[\"\']/.test(value)) { 
    19521955                text = "[" + link + " " + value + "]"; 
    19531956            } 
     
    20192022                if ((container.tagName || "").toLowerCase() == "ol") { 
    20202023                    var start = container.getAttribute("start") || ""; 
    2021                     if (/^(?:[0-9]+|[a-zA-Z]|[ivxIVX]{1,5})$/.test(start)) { 
     2024                    if (start != "1" && /^(?:[0-9]+|[a-zA-Z]|[ivxIVX]{1,5})$/.test(start)) { 
    20222025                        texts.push(start, ". "); 
    20232026                    } 
     
    20662069                break; 
    20672070            case "pre": 
    2068                 if (isInlineNode(node.previousSibling)) { 
    2069                     texts.push("\n"); 
    2070                 } 
    2071                 texts.push(/^(?:li|dd)$/i.test(node.parentNode.tagName) ? "\n{{{\n" : "{{{\n"); 
     2071                texts.push( 
     2072                    /^(?:li|dd)$/i.test(node.parentNode.tagName) || isInlineNode(node.previousSibling) 
     2073                    ? "\n{{{\n" : "{{{\n"); 
    20722074                needEscape = false; 
    20732075                inCodeBlock = true; 
     
    21722174                    } 
    21732175                    if (text.slice(-1) == "\n") { 
    2174                         text += listDepth > 0 ? string("  ", listDepth + 1) : "    "; 
     2176                        text += listDepth > 0 ? string("  ", listDepth) : "    "; 
    21752177                    } 
    21762178                }