/** * Created with JetBrains PhpStorm. * User: luqiong * Date: 13-3-14 * Time: 下午2:31 * To change this template use File | Settings | File Templates. */ module( 'core.htmlparser' ); test( '普通标签处理', function() { var root = UE.htmlparser('sdfsdfsdfsf'); equals(root.toHtml(),'sdfsdfsdfsf','单个普通标签'); root = UE.htmlparser('sdfsdfsdsdfsdfsf'); equals(root.toHtml(),'sdfsdfsdsdfsdfsf','多个普通标签'); root = UE.htmlparser('sdf'); ua.checkSameHtml(root.toHtml(),'sdf','添加属性的标签'); root = UE.htmlparser(''); ua.checkSameHtml(root.toHtml(),'','img标签'); }); test( '特殊标签处理', function() { var root = UE.htmlparser('sdf'); ua.checkSameHtml(root.toHtml(),'sdf','包含注释'); root = UE.htmlparser(''); equals(root.toHtml().replace(/[ ]+>/g,'>'),'','script标签'); root = UE.htmlparser('


'); equals(root.toHtml().replace(/[ ]+>/g,'>'),'


','br标签'); root = UE.htmlparser('
  • sdfsdfsdf
  • sdfsdfsdfsdf'); equals(root.toHtml(),'','以文本结束的html'); }); //test( '补全不完整table', function() {//TODO 1.2.6 // var root = UE.htmlparser('

    '); // equals(root.toHtml(),'

    ','td完整,补全table'); // root = UE.htmlparser('

    sdfsdfsdf

    '); // equals(root.toHtml(),'

    sdfsdfsdf

    ','td不完整,补全table'); // root = UE.htmlparser('' + '\n\r' + ''); // equals(root.toHtml(),'
    ','包含\n,补全table'); // root = UE.htmlparser(''); // equals( root.toHtml().toLowerCase(), '
    ', '--不补孩子' ); // /*补parent*/ // root = UE.htmlparser('hello'); // equals( root.toHtml().toLowerCase(), '
    '); // equals( root.toHtml().toLowerCase(), '
    ', '
    --补父亲' ); // /*补parent和child*/ // root = UE.htmlparser('
    hello
    ', 'hello--补父亲不补孩子' ); // // root = UE.htmlparser('123'); // equals( root.toHtml().toLowerCase(), '
    123
    ', '123--文本放在table里' ); // // root = UE.htmlparser('123'); // equals( root.toHtml().toLowerCase(), '123
    ', '123' ); // // root = UE.htmlparser('123'); // equals( root.toHtml().toLowerCase(), '
    123
    ', '123' ); // // root = UE.htmlparser('123'); // equals( root.toHtml().toLowerCase(), '
    123
    ', '123' ); // // /*补充为2个td*/ //// root = UE.htmlparser('123'); //// equals( root.toHtml().toLowerCase(), '
    123
    ', '123--tr和td之间有文字' );//TODO 1.2.6 // // root = UE.htmlparser('123'); // equals( root.toHtml().toLowerCase(), '
    123
    ', '123' ); // // root = UE.htmlparser('123'); // equals( root.toHtml().toLowerCase(), '
    123
    ', '123' ); // // /*补2个table*/ //// root = UE.htmlparser('123132'); //// equals( root.toHtml().toLowerCase(), '
    123
    132
    ', '123132--补全2个table' );//TODO 1.2.6 // // /*开标签、文本与闭标签混合*/ //// root = UE.htmlparser('123'); //// equals( root.toHtml().toLowerCase(), '
    123', '123--tr和td之间有文字' );//TODO 1.2.6 // //// root = UE.htmlparser('123'); //// equals( root.toHtml().toLowerCase(), '
    123', '123--td闭标签后面有文字' );//TODO 1.2.6 // // root = UE.htmlparser('123'); // equals( root.toHtml().toLowerCase(), '123
    ', '123' ); // // root = UE.htmlparser('123'); // equals( root.toHtml().toLowerCase(), '
    123
    ', '123' ); // // root = UE.htmlparser('123'); // equals( root.toHtml().toLowerCase(), '123
    ', '123' ); // /*闭标签、文本与闭标签混合*/ // root = UE.htmlparser('123'); // equals( root.toHtml().toLowerCase(), '123', '123' ); // // root = UE.htmlparser('123'); // equals( root.toHtml().toLowerCase(), '123', '123' ); // // root = UE.htmlparser('123'); // equals( root.toHtml().toLowerCase(), '123
    ', '123', '123' ); // // /*补前面的标签*/ // root = UE.htmlparser('123'); // equals( root.toHtml().toLowerCase(), '123', '123' ); // // root = UE.htmlparser('123'); // equals( root.toHtml().toLowerCase(), '123', '123' ); // /*补全tr前面的标签*/ // root = UE.htmlparser('123'); // equals( root.toHtml().toLowerCase(), '123', '123--删除tr前后的标签,前面有文本' ); // /*补全table前面的标签*/ // root = UE.htmlparser('123'); // equals( root.toHtml().toLowerCase(), '123', '123--删除table前后的标签,前面有文本' ); // /*复杂结构*/ // root = UE.htmlparser('456'); // equals( root.toHtml().toLowerCase(), '
    123
    123
    456
    ', '456' ); // // root = UE.htmlparser(''); // equals( root.toHtml().toLowerCase(), '
    123
    hello1hello2
    hello1hello2
    ', '解析hello1hello2' ); // // root = UE.htmlparser(''); // equals( root.toHtml().toLowerCase(), '
    hello1hello2
    hello1hello2
    ', '解析' ); // // root = UE.htmlparser('
    hello1hello2
    123'); // equals( root.toHtml().toLowerCase(), '
    123', '123' ); //}); test( '补全不完整li', function() { var root = UE.htmlparser('
    1. sdf
    2. sdfsdf
    '); equals(root.toHtml().replace(/[ ]+>/g,'>'),'
    1. sdf
    2. sdfsdf
    ','补全u,em'); root = UE.htmlparser('
    1. sdf
      • a
      • b
      • c
    2. jkl
    '); equals(root.toHtml().replace(/[ ]+>/g,'>'),'
    1. sdf
      • a
      • b
      • c
    2. jkl
    ','补全li'); root = UE.htmlparser('
  • 123'); equals(root.toHtml().replace(/[ ]+>/g,'>'), '
    • 123
    ', '
  • 123--补全li的parent--ul,前面有文本' ); /*补ul的child*/ root = UE.htmlparser('
      123'); equals(root.toHtml().replace(/[ ]+>/g,'>'), '
      • 123
      ', '
        123--补全ul的child--li,前面有文本' ); /*补li开始标签*/ root = UE.htmlparser('123'); equals(root.toHtml().replace(/[ ]+>/g,'>'), '123', '123--删掉标签' ); }); test( '属性引号问题', function() { var root = UE.htmlparser(''); equals(root.toHtml().replace(/[ ]+>/g,'>'),''); root = UE.htmlparser(""); equals(root.toHtml().replace(/[ ]+>/g,'>'),''); root = UE.htmlparser(''); equals(root.toHtml().replace(/[ ]+>/g,'>'),''); }); test( '大小写', function() { var root = UE.htmlparser('

  • '); equals(root.toHtml().replace(/[ ]+>/g,'>'),'

    '); root = UE.htmlparser('
    1. sdf
    2. sdfsdf
    '); equals(root.toHtml().replace(/[ ]+>/g,'>'),'
    1. sdf
    2. sdfsdf
    ','补全u,em'); root = UE.htmlparser(''); equals(root.toHtml().replace(/[ ]+>/g,'>'),''); }); test( '裸字', function() { var root = UE.htmlparser('sdfasdfasdf'); equals(root.toHtml().replace(/[ ]+>/g,'>'),'sdfasdfasdf'); }); test( '只有结束标签的情况', function() { var root = UE.htmlparser('

    hello1

    hello2

    '); equals(root.toHtml().replace(/[ ]+>/g,'>'),'

    hello1

    hello2

    '); }); test( '开始标签与后面文本的空格过滤,其他不过滤inline节点之间的空格,过滤block节点之间的空格', function () { /*inline节点之间的空格要留着*/ var root = UE.htmlparser('baidu hello '); equals(root.toHtml().replace(/[ ]+>/g,'>'),'baidu hello '); root = UE.htmlparser(' hello he llo2 hello '); equals(root.toHtml().replace(/[ ]+>/g,'>'),' hello he llo2 hello ' ); /*block节点之间的空格不要留着 这个太纠结,不必了。会把ol拆开,后面的变成ul*/ // html = '
    1. li_test
    2. li test2
    '; // node = serialize.parseHTML( html ); // node = serialize.filter( node ); // equal( serialize.toHTML( node ), '
    1. li_test 
    2. li test2 
     ' ); } ); /*特殊字符需要转义*/ test( '文本包含特殊字符,如尖括号', function () { var root = UE.htmlparser(''); equals(root.toHtml().replace(/[ ]+>/g,'>'),'<td  hello', '字符转义' ); } ); test( 'br', function () { var root = UE.htmlparser('
    '); equals(root.toHtml().replace(/[ ]+>/g,'>'),'
    ', '对br不操作'); root = UE.htmlparser('
    '); equals(root.toHtml().replace(/[ ]+>/g,'>'),'
    ', '补充br后面的斜杠'); } ); /*考察标签之间嵌套关系*/ test( '复杂标签嵌套', function() { var root = UE.htmlparser('hello1

    hello2

    hello3

    hello4'); equals(root.toHtml().replace(/[ ]+>/g,'>'),'hello1

    hello2

    hello3

    hello4

    '); } ); test( 'trace 1727:过滤超链接后面的空格', function () { var root = UE.htmlparser('baidu ddd'); equals(root.toHtml().replace(/[ ]+>/g,'>'),'baidu  ddd','过滤超链接后面的空格'); } ); //test( '转换img标签', function () { // var root = UE.htmlparser(''); // var spa=ua.browser.ie==6?' orgSrc="'+te.obj[1].options.UEDITOR_HOME_URL+'themes/default/images/spacer.gif"':''; // equals(root.toHtml().replace(/[ ]+>/g,'>'), '' , '转换img标签'); //} );