File tree 2 files changed +48
-7
lines changed
2 files changed +48
-7
lines changed Original file line number Diff line number Diff line change 2437
2437
* @memberOf SCEditor.plugins.bbcode.prototype
2438
2438
*/
2439
2439
function elementToBbcode ( element ) {
2440
- var toBBCode = function ( node , vChildren ) {
2440
+ var toBBCode = function ( node , vChildren , hasCodeParent ) {
2441
2441
var ret = '' ;
2442
2442
2443
2443
dom . traverse ( node , function ( node ) {
2478
2478
2479
2479
// don't convert iframe contents
2480
2480
if ( tag !== 'iframe' ) {
2481
- content = toBBCode ( node , vChild ) ;
2481
+ content = toBBCode ( node , vChild ,
2482
+ hasCodeParent || tag === 'code' ) ;
2482
2483
}
2483
2484
2484
2485
// TODO: isValidChild is no longer needed. Should use
2485
2486
// valid children bbcodes instead by creating BBCode
2486
2487
// tokens like the parser.
2487
2488
if ( isValidChild ) {
2488
- // code tags should skip most styles
2489
- if ( tag !== 'code' ) {
2490
- // First parse inline codes
2489
+ if ( ! hasCodeParent ) {
2490
+ // Parse inline codes first so they don't
2491
+ // contain block level codes
2491
2492
content = handleTags ( node , content , false ) ;
2493
+ content = handleTags ( node , content , true ) ;
2492
2494
}
2493
-
2494
- content = handleTags ( node , content , true ) ;
2495
2495
ret += handleBlockNewlines ( node , content ) ;
2496
2496
} else {
2497
2497
ret += content ;
Original file line number Diff line number Diff line change @@ -784,6 +784,47 @@ QUnit.test('Code', function (assert) {
784
784
'[code]ignore this Testing 1.2.3....[/code]\n' ,
785
785
'Code with styling'
786
786
) ;
787
+
788
+ assert . equal (
789
+ this . htmlToBBCode (
790
+ '<code><span style="color:#ff0000">test</span></code>'
791
+ ) ,
792
+ '[code]test[/code]\n' ,
793
+ 'Code with inline styling'
794
+ ) ;
795
+
796
+ assert . equal (
797
+ this . htmlToBBCode (
798
+ '<code><div style="color:#ff0000">test</div></code>'
799
+ ) ,
800
+ '[code]test[/code]\n' ,
801
+ 'Code with block styling'
802
+ ) ;
803
+
804
+
805
+ assert . equal (
806
+ this . htmlToBBCode (
807
+ '<code><div><div style="color:#ff0000">test</div></div></code>'
808
+ ) ,
809
+ '[code]test[/code]\n' ,
810
+ 'Code with nested block styling'
811
+ ) ;
812
+
813
+ assert . equal (
814
+ this . htmlToBBCode (
815
+ '<code><div>line 1</div><div>line 2</div></code>'
816
+ ) ,
817
+ '[code]line 1\nline 2[/code]\n' ,
818
+ 'Code with block lines'
819
+ ) ;
820
+
821
+ assert . equal (
822
+ this . htmlToBBCode (
823
+ '<code style="font-weight:bold">test</code>'
824
+ ) ,
825
+ '[code]test[/code]\n' ,
826
+ 'Code with styling'
827
+ ) ;
787
828
} ) ;
788
829
789
830
You can’t perform that action at this time.
0 commit comments