@@ -16,7 +16,9 @@ def initialize(
16
16
. lines
17
17
. each
18
18
. with_index ( 1 ) do |line , index |
19
- @literal_lines [ index ] = line . strip if line . lstrip . start_with? ( "!" )
19
+ if ( literal_line = line [ /\A \s *(?:%[a-z]+)?(!.*)\s *\z / , 1 ] )
20
+ @literal_lines [ index ] = literal_line
21
+ end
20
22
end
21
23
22
24
super ( source , *rest , options : options )
@@ -384,8 +386,12 @@ def visit_tag(node)
384
386
# tag.
385
387
q . breakable_empty
386
388
387
- if node . value [ :parse ]
388
- format_tag_value ( q , value )
389
+ if line = q . literal_lines [ node . line ]
390
+ q . text ( line )
391
+ elsif node . value [ :parse ]
392
+ prefix = node . value [ :preserve_script ] ? "~" : "="
393
+ prefix = "&#{ prefix } " if node . value [ :escape_html ]
394
+ format_tag_value ( q , prefix , value )
389
395
else
390
396
q . if_break { q . text ( "" ) } . if_flat { q . text ( " " ) }
391
397
q . text ( value )
@@ -399,10 +405,10 @@ def visit_tag(node)
399
405
400
406
private
401
407
402
- def format_tag_value ( q , value )
408
+ def format_tag_value ( q , prefix , value )
403
409
program = SyntaxTree . parse ( value )
404
410
if !program || program . statements . body . length > 1
405
- return q . text ( "= #{ value } " )
411
+ return q . text ( "#{ prefix } #{ value } " )
406
412
end
407
413
408
414
statement = program . statements . body . first
@@ -418,10 +424,10 @@ def format_tag_value(q, value)
418
424
q . if_break { q . text ( "" ) } . if_flat { q . text ( " " ) }
419
425
q . text ( formatted [ 1 ...-1 ] . gsub ( /\\ "/ , "\" " ) )
420
426
else
421
- q . text ( "= #{ formatted } " )
427
+ q . text ( "#{ prefix } #{ formatted } " )
422
428
end
423
429
rescue Parser ::ParseError
424
- q . text ( "= #{ value } " )
430
+ q . text ( "#{ prefix } #{ value } " )
425
431
end
426
432
427
433
# When printing out sequences of silent scripts, sometimes subsequent nodes
0 commit comments