#!/usr/bin/perl use strict; #use warnings; my $pipe = ''; my $pipe_content= ''; my $pipe_close = ''; my $tag = { K => { open => '%', close => '', block => 1, block_open => "<c>\n".'<p>', block_close => '</p>'."\n<t>" }, R => { open => '<li>', close => '</li>'."\n", block => 1, block_open => '<r>'."\n", block_close => '</r>'."\n</t>\n< +/c>" }, S => { open => '<set name="temant">', close => '</set>', block => 0 }, F => { open => '<setflag param="', close => '"/>', block => 0, }, '#' => { open => '<!-- ', close => ' -->', block => 0 } }; my $block_flag = 0; my $line_out = ''; my $output = ''; open(DATA,"file"); while (my $line_in = <DATA>) { chomp($line_in); next if $line_in =~ /^C/; next if $line_in =~ /^M/; $line_in =~ s/?/\á\;/g; #standard substitute á to + "&aacute;", just ignore these lines $line_in =~ s/?/\Á\;/g; $line_in =~ s/?/\é\;/g; $line_in =~ s/?/\É\;/g; $line_in =~ s/?/\í\;/g; $line_in =~ s/?/\Í\;/g; $line_in =~ s/?/\ó\;/g; $line_in =~ s/?/\Ó\;/g; $line_in =~ s/?/\ú\;/g; $line_in =~ s/?/\Ú\;/g; $line_in =~ s/?/\ñ\;/g; $line_in =~ s/?/\¿\;/g; my ( $style, $content ) = $line_in =~ /^(\w|\#)\s+(.*)$/; # next if $style eq '#' and $content eq ''; do not enable, brings up +even more problems if ($style eq "I") { $pipe = 'yes'; $pipe_content = $content; } next if $line_in =~ /^I/; if ($style eq 'F' and $pipe eq 'yes') { $output = join( '', $output, $tag->{ $block_flag }->{ block_close }, "\n".'<ifflag param="'.$pip +e_content.'">'."\n", '<then>'."\n", '<setflag param="'.$content +.'"/>'."\n"); $pipe = ''; $pipe_content = ''; $pipe_close = 'yes'; #controls when should the </then>&l +t;/ifflag> should be added (this is what isn't working properly) } elsif ($style eq 'K' and $pipe eq 'yes') { $output = join( '', '<c>'."\n", '<p>'.$content, $output, $tag->{ $block_flag }->{ + block_close }, "</p>\n".'<ifflag par +am="'.$pipe_content.'">'."\n", '<then>'."\n"); $pipe = ''; $pipe_content = ''; $pipe_close = 'yes'; #controls when should the </then>&l +t;/ifflag> should be added (this is what isn't working properly) } else { if ($pipe_close eq 'yes') { #this whole procedure is to basically change the block_close for R... +i hope there is a better and easier way my $tag = { K => { open => '%', close => '', block => 1, block_open => "<c>\n".'<p>', block_close => '</p>'."\n<t>" }, R => { open => '<li>', close => '</li>'."\n", block => 1, block_open => '<r>'."\n", block_close => '</then>'."\n".'</iffla +g>'."\n".'</r>'."\n</t>\n</c>" }, S => { open => '<set name="temant">', close => '</set>', block => 0 }, F => { open => '<setflag param="', close => '"/>', block => 0, }, '#' => { open => '<!-- ', close => ' -->', block => 0 } }; $pipe_close = ''; } $line_out = join( '', $tag->{ $style }->{ open }, $content, $tag->{ $style }->{ close } ); if ( $tag->{ $style }->{ block } and ! $block_flag ){ $output = join( '', $output, $tag->{ $style }->{ block_open }, $line_out ); $block_flag = $style; } elsif ( ! $tag->{ $style }->{ block } and $block_flag){ $output = join( '', $output, $tag->{ $block_flag }->{ block_close }, "\n", $line_out, "\n" ); $block_flag = ''; } elsif ( ! $tag->{ $style }->{ block }){ $output = join( '', $output, $line_out, "\n" ); } else{ if ($style eq "K") { #this is another exception, don't worry a +bout it $output = join( '', $output, ",", $line_out ); } else { $output = join( '', $output, $line_out ); } $line_out = ''; } } } open OUT, ">", "output.txt" or die; print OUT $output; print OUT "<r>\n<t>\n<c>\n"; #this is because the ve +ry last block's ending tags aren't being processed, no biggie close(OUT);
janitored by ybiC: Balanced <code> tags around codeblock instead of HTML markup formatting, and balanced <readmore>'s as well, retitle from less-than-descriptive "Further help.." for better search results
In reply to Help translating into HTML by mrxg4
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |