@@ -6,6 +6,8 @@ import Element from '../../nodes/Element';
6
6
import { x } from 'code-red' ;
7
7
import Expression from '../../nodes/shared/Expression' ;
8
8
import remove_whitespace_children from './utils/remove_whitespace_children' ;
9
+ import fix_attribute_casing from '../../render_dom/wrappers/Element/fix_attribute_casing' ;
10
+ import { namespaces } from '../../../utils/namespaces' ;
9
11
10
12
export default function ( node : Element , renderer : Renderer , options : RenderOptions ) {
11
13
@@ -41,20 +43,21 @@ export default function(node: Element, renderer: Renderer, options: RenderOption
41
43
if ( attribute . is_spread ) {
42
44
args . push ( attribute . expression . node ) ;
43
45
} else {
46
+ const attr_name = node . namespace === namespaces . foreign ? attribute . name : fix_attribute_casing ( attribute . name ) ;
44
47
const name = attribute . name . toLowerCase ( ) ;
45
48
if ( name === 'value' && node . name . toLowerCase ( ) === 'textarea' ) {
46
49
node_contents = get_attribute_value ( attribute ) ;
47
50
} else if ( attribute . is_true ) {
48
- args . push ( x `{ ${ attribute . name } : true }` ) ;
51
+ args . push ( x `{ ${ attr_name } : true }` ) ;
49
52
} else if (
50
53
boolean_attributes . has ( name ) &&
51
54
attribute . chunks . length === 1 &&
52
55
attribute . chunks [ 0 ] . type !== 'Text'
53
56
) {
54
57
// a boolean attribute with one non-Text chunk
55
- args . push ( x `{ ${ attribute . name } : ${ ( attribute . chunks [ 0 ] as Expression ) . node } || null }` ) ;
58
+ args . push ( x `{ ${ attr_name } : ${ ( attribute . chunks [ 0 ] as Expression ) . node } || null }` ) ;
56
59
} else {
57
- args . push ( x `{ ${ attribute . name } : ${ get_attribute_value ( attribute ) } }` ) ;
60
+ args . push ( x `{ ${ attr_name } : ${ get_attribute_value ( attribute ) } }` ) ;
58
61
}
59
62
}
60
63
} ) ;
@@ -64,28 +67,29 @@ export default function(node: Element, renderer: Renderer, options: RenderOption
64
67
let add_class_attribute = ! ! class_expression ;
65
68
node . attributes . forEach ( attribute => {
66
69
const name = attribute . name . toLowerCase ( ) ;
70
+ const attr_name = node . namespace === namespaces . foreign ? attribute . name : fix_attribute_casing ( attribute . name ) ;
67
71
if ( name === 'value' && node . name . toLowerCase ( ) === 'textarea' ) {
68
72
node_contents = get_attribute_value ( attribute ) ;
69
73
} else if ( attribute . is_true ) {
70
- renderer . add_string ( ` ${ attribute . name } ` ) ;
74
+ renderer . add_string ( ` ${ attr_name } ` ) ;
71
75
} else if (
72
76
boolean_attributes . has ( name ) &&
73
77
attribute . chunks . length === 1 &&
74
78
attribute . chunks [ 0 ] . type !== 'Text'
75
79
) {
76
80
// a boolean attribute with one non-Text chunk
77
81
renderer . add_string ( ' ' ) ;
78
- renderer . add_expression ( x `${ ( attribute . chunks [ 0 ] as Expression ) . node } ? "${ attribute . name } " : ""` ) ;
82
+ renderer . add_expression ( x `${ ( attribute . chunks [ 0 ] as Expression ) . node } ? "${ attr_name } " : ""` ) ;
79
83
} else if ( name === 'class' && class_expression ) {
80
84
add_class_attribute = false ;
81
- renderer . add_string ( ` ${ attribute . name } ="` ) ;
85
+ renderer . add_string ( ` ${ attr_name } ="` ) ;
82
86
renderer . add_expression ( x `[${ get_class_attribute_value ( attribute ) } , ${ class_expression } ].join(' ').trim()` ) ;
83
87
renderer . add_string ( '"' ) ;
84
88
} else if ( attribute . chunks . length === 1 && attribute . chunks [ 0 ] . type !== 'Text' ) {
85
89
const snippet = ( attribute . chunks [ 0 ] as Expression ) . node ;
86
- renderer . add_expression ( x `@add_attribute("${ attribute . name } ", ${ snippet } , ${ boolean_attributes . has ( name ) ? 1 : 0 } )` ) ;
90
+ renderer . add_expression ( x `@add_attribute("${ attr_name } ", ${ snippet } , ${ boolean_attributes . has ( name ) ? 1 : 0 } )` ) ;
87
91
} else {
88
- renderer . add_string ( ` ${ attribute . name } ="` ) ;
92
+ renderer . add_string ( ` ${ attr_name } ="` ) ;
89
93
renderer . add_expression ( ( name === 'class' ? get_class_attribute_value : get_attribute_value ) ( attribute ) ) ;
90
94
renderer . add_string ( '"' ) ;
91
95
}
0 commit comments