@@ -16,7 +16,9 @@ def initialize(
1616 . lines
1717 . each
1818 . 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
2022 end
2123
2224 super ( source , *rest , options : options )
@@ -384,8 +386,12 @@ def visit_tag(node)
384386 # tag.
385387 q . breakable_empty
386388
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 )
389395 else
390396 q . if_break { q . text ( "" ) } . if_flat { q . text ( " " ) }
391397 q . text ( value )
@@ -399,10 +405,10 @@ def visit_tag(node)
399405
400406 private
401407
402- def format_tag_value ( q , value )
408+ def format_tag_value ( q , prefix , value )
403409 program = SyntaxTree . parse ( value )
404410 if !program || program . statements . body . length > 1
405- return q . text ( "= #{ value } " )
411+ return q . text ( "#{ prefix } #{ value } " )
406412 end
407413
408414 statement = program . statements . body . first
@@ -418,10 +424,10 @@ def format_tag_value(q, value)
418424 q . if_break { q . text ( "" ) } . if_flat { q . text ( " " ) }
419425 q . text ( formatted [ 1 ...-1 ] . gsub ( /\\ "/ , "\" " ) )
420426 else
421- q . text ( "= #{ formatted } " )
427+ q . text ( "#{ prefix } #{ formatted } " )
422428 end
423429 rescue Parser ::ParseError
424- q . text ( "= #{ value } " )
430+ q . text ( "#{ prefix } #{ value } " )
425431 end
426432
427433 # When printing out sequences of silent scripts, sometimes subsequent nodes
0 commit comments