@@ -1510,32 +1510,25 @@ sub Indent {
15101510 $bottom = '1em' ;
15111511 $state ->{i }++;
15121512 }
1513- return $ self -> nl . "< div style=\ "margin:0 0 $bottom ${em}em\">\n" . $self->string($item) . $self->nl . "</div>\n" ;
1513+ return main ::tag( ' div' , style => "margin:0 0 $bottom ${em}em" , $self ->string($item )) ;
15141514}
15151515
15161516sub Align {
15171517 my ($self , $state ) = @_ ;
15181518 my $item = $state ->{item };
1519- return
1520- $self ->nl
1521- . '<div style="text-align:'
1522- . $item->{align}
1523- . '; margin:0">' . "\n"
1524- . $self->string($item)
1525- . $self->nl
1526- . "</div>\n";
1519+ return main ::tag('div' , style => "text-align:$item->{align};margin:0" , $self ->string($item ));
15271520}
15281521
15291522our %bullet = (
1530- bullet => [ 'ul' , 'list-style-type: disc;' ],
1531- numeric => [ 'ol' , 'list-style-type: decimal;' ],
1532- alpha => [ 'ol' , 'list-style-type: lower-alpha;' ],
1533- Alpha => [ 'ol' , 'list-style-type: upper-alpha;' ],
1534- roman => [ 'ol' , 'list-style-type: lower-roman;' ],
1535- Roman => [ 'ol' , 'list-style-type: upper-roman;' ],
1536- disc => [ 'ul' , 'list-style-type: disc;' ],
1537- circle => [ 'ul' , 'list-style-type: circle;' ],
1538- square => [ 'ul' , 'list-style-type: square;' ],
1523+ bullet => [ 'ul' , 'list-style-type:disc;' ],
1524+ numeric => [ 'ol' , 'list-style-type:decimal;' ],
1525+ alpha => [ 'ol' , 'list-style-type:lower-alpha;' ],
1526+ Alpha => [ 'ol' , 'list-style-type:upper-alpha;' ],
1527+ roman => [ 'ol' , 'list-style-type:lower-roman;' ],
1528+ Roman => [ 'ol' , 'list-style-type:upper-roman;' ],
1529+ disc => [ 'ul' , 'list-style-type:disc;' ],
1530+ circle => [ 'ul' , 'list-style-type:circle;' ],
1531+ square => [ 'ul' , 'list-style-type:square;' ],
15391532);
15401533
15411534sub List {
@@ -1548,34 +1541,33 @@ sub List {
15481541 $margin = '0 0 1em' ;
15491542 $state ->{i }++;
15501543 }
1551- return $self ->nl
1552- . main::tag(
1553- $list->[0],
1554- style => "margin:$margin;padding-left:2.25em;$list->[1]" ,
1555- $self ->string($item ) . $self->nl
1556- );
1544+ return main ::tag($list ->[0 ], style => "margin:$margin;padding-left:2.25em;$list->[1]" , $self ->string($item ));
15571545}
15581546
15591547sub Bullet {
15601548 my ($self , $state ) = @_ ;
15611549 my $next = $state ->{block }{stack }[ $state ->{i } ];
1550+ my $style ;
15621551 if (defined $next && $next ->{type } eq 'par' ) {
15631552 $state ->{i }++;
1564- return $ self -> nl . '<li style=" margin-bottom:1em">' . $self->string($state->{item}) . "</li>\n" ;
1553+ $ style = ' margin-bottom:1em' ;
15651554 }
1566- return $ self -> nl . '<li>' . $self->string($state->{item}) . "</li>\n" ;
1555+ return main ::tag( 'li' , $ style ? ( style => $ style ) : (), $self ->string($state ->{item })) ;
15671556}
15681557
15691558sub Code {
15701559 my ($self , $state ) = @_ ;
1571- my $item = $state ->{item };
1572- my $class = ($item ->{class } ? ' class="' . $item->{class} . '"' : "");
1573- return $self ->nl . '<pre style="margin:0"><code' . $class . '>' . $self->string($item) . "</code></pre>\n";
1560+ my $item = $state ->{item };
1561+ return main ::tag(
1562+ 'pre' ,
1563+ style => 'margin:0' ,
1564+ main ::tag('code' , $item ->{class } ? (class => $item ->{class }) : (), $self ->string($item ))
1565+ );
15741566}
15751567
15761568sub Pre {
15771569 my ($self , $state ) = @_ ;
1578- return $ self -> nl . '< pre style=" margin:0">< code>' . $self->string($state->{item}) . "</code></pre>\n" ;
1570+ return main ::tag( ' pre' , style => ' margin:0' , main ::tag( ' code' , $self ->string($state ->{item }))) ;
15791571}
15801572
15811573sub Heading {
@@ -1585,24 +1577,24 @@ sub Heading {
15851577 my $text = $self ->string($item );
15861578 $text =~ s /^ +| +$//gm ;
15871579 $text =~ s ! +(<br />)!$1 !g ;
1588- return '<h' . $n . ' style=" margin:0">' . $text . "</h$n>\n" ;
1580+ return main ::tag( "h$n" , style => ' margin:0' , $text ) ;
15891581}
15901582
15911583sub Par {
15921584 my ($self , $state ) = @_ ;
1593- return $ self -> nl . '< div style=" margin-top:1em"></div>' . "\n" ;
1585+ return main ::tag( ' div' , style => ' margin-top:1em' , '' ) ;
15941586}
15951587
1596- sub Break {" <br />\n" }
1588+ sub Break {' <br />' }
15971589
15981590sub Bold {
15991591 my ($self , $state ) = @_ ;
1600- return '<strong>' . $self->string($state->{item}) . '</strong>' ;
1592+ return main ::tag( 'string' , $self ->string($state ->{item })) ;
16011593}
16021594
16031595sub Italic {
16041596 my ($self , $state ) = @_ ;
1605- return '<em>' . $self->string($state->{item}) . '</em>' ;
1597+ return main ::tag( 'em' , $self ->string($state ->{item })) ;
16061598}
16071599
16081600our %openQuote = ('"' => "“" , "'" => "‘" );
@@ -1631,24 +1623,23 @@ sub Rule {
16311623 $height = $item->{size};
16321624 $height .= 'px' if ($height =~ /^\d*\.?\d+$/);
16331625 }
1634- return $self ->nl
1635- . main::tag(
1626+ return main ::tag(
1627+ 'div' ,
1628+ main ::tag(
16361629 'div' ,
1630+ style => "width:$width;display:inline-block;margin:0.3em auto" ,
16371631 main ::tag(
1638- 'div' ,
1639- style => "width:$width; display:inline-block; margin:0.3em auto" ,
1640- main ::tag(
1641- 'hr' , style => "width:$width; height:$height; background-color:currentColor; margin:0.3em auto;"
1642- )
1632+ 'hr' , style => "width:$width;height:$height;background-color:currentColor;margin:0.3em auto;"
16431633 )
1644- );
1634+ )
1635+ );
16451636}
16461637
16471638sub Verbatim {
16481639 my ($self , $state ) = @_ ;
16491640 my $item = $state ->{item };
16501641 my $text = $self ->escape($item ->{text });
1651- $text = "< code> $text</code>" if $item ->{hasStar };
1642+ $text = main ::tag( ' code' , $text ) if $item ->{hasStar };
16521643 return $text ;
16531644}
16541645
0 commit comments