Rosetta Code/Fix code tags: Difference between revisions
Content added Content deleted
(→{{header|Python}}: process one line at a time for scalability) |
(added perl) |
||
Line 11: | Line 11: | ||
<pre>cat wikisource.txt | ./convert.py > converted.txt</pre> |
<pre>cat wikisource.txt | ./convert.py > converted.txt</pre> |
||
=={{header|Perl}}== |
|||
Syntax highlighting does not work, because <nowiki></lang></nowiki> is inside the code. |
|||
<pre> |
|||
# coding: utf-8 |
|||
my @langs = ('ada', 'cpp-qt', 'pascal', 'lscript', 'z80', 'visualprolog', |
|||
'html4strict', 'cil', 'objc', 'asm', 'progress', 'teraterm', 'hq9plus', |
|||
'genero', 'tsql', 'email', 'pic16', 'tcl', 'apt_sources', 'io', 'apache', |
|||
'vhdl', 'avisynth', 'winbatch', 'vbnet', 'ini', 'scilab', 'ocaml-brief', |
|||
'sas', 'actionscript3', 'qbasic', 'perl', 'bnf', 'cobol', 'powershell', |
|||
'php', 'kixtart', 'visualfoxpro', 'mirc', 'make', 'javascript', 'cpp', |
|||
'sdlbasic', 'cadlisp', 'php-brief', 'rails', 'verilog', 'xml', 'csharp', |
|||
'actionscript', 'nsis', 'bash', 'typoscript', 'freebasic', 'dot', |
|||
'applescript', 'haskell', 'dos', 'oracle8', 'cfdg', 'glsl', 'lotusscript', |
|||
'mpasm', 'latex', 'sql', 'klonec', 'ruby', 'ocaml', 'smarty', 'python', |
|||
'oracle11', 'caddcl', 'robots', 'groovy', 'smalltalk', 'diff', 'fortran', |
|||
'cfm', 'lua', 'modula3', 'vb', 'autoit', 'java', 'text', 'scala', |
|||
'lotusformulas', 'pixelbender', 'reg', '_div', 'whitespace', 'providex', |
|||
'asp', 'css', 'lolcode', 'lisp', 'inno', 'mysql', 'plsql', 'matlab', |
|||
'oobas', 'vim', 'delphi', 'xorg_conf', 'gml', 'prolog', 'bf', 'per', |
|||
'scheme', 'mxml', 'd', 'basic4gl', 'm68k', 'gnuplot', 'idl', 'abap', |
|||
'intercal', 'c_mac', 'thinbasic', 'java5', 'xpp', 'boo', 'klonecpp', |
|||
'blitzbasic', 'eiffel', 'povray', 'c', 'gettext'); |
|||
while (<STDIN>) { |
|||
foreach my $i (@langs) { |
|||
s|<$i>|<lang $i>|g; |
|||
s|</$i>|</lang>|g; |
|||
} |
|||
s|<code (.*)>|<lang \1>|g; |
|||
s|</code>|</lang>|g; |
|||
print; |
|||
} |
|||
</pre> |
|||
=={{header|Python}}== |
=={{header|Python}}== |
Revision as of 06:31, 30 January 2009
Rosetta Code/Fix code tags
You are encouraged to solve this task according to the task description, using any language you may know.
You are encouraged to solve this task according to the task description, using any language you may know.
Fix Rosetta Code deprecated code tags, with these rules:
Change <%s> to <lang %s> Change </%s> to </lang> Change <code %s> to <lang %s> Change </code> to </lang>
Usage:
cat wikisource.txt | ./convert.py > converted.txt
Perl
Syntax highlighting does not work, because </lang> is inside the code.
# coding: utf-8 my @langs = ('ada', 'cpp-qt', 'pascal', 'lscript', 'z80', 'visualprolog', 'html4strict', 'cil', 'objc', 'asm', 'progress', 'teraterm', 'hq9plus', 'genero', 'tsql', 'email', 'pic16', 'tcl', 'apt_sources', 'io', 'apache', 'vhdl', 'avisynth', 'winbatch', 'vbnet', 'ini', 'scilab', 'ocaml-brief', 'sas', 'actionscript3', 'qbasic', 'perl', 'bnf', 'cobol', 'powershell', 'php', 'kixtart', 'visualfoxpro', 'mirc', 'make', 'javascript', 'cpp', 'sdlbasic', 'cadlisp', 'php-brief', 'rails', 'verilog', 'xml', 'csharp', 'actionscript', 'nsis', 'bash', 'typoscript', 'freebasic', 'dot', 'applescript', 'haskell', 'dos', 'oracle8', 'cfdg', 'glsl', 'lotusscript', 'mpasm', 'latex', 'sql', 'klonec', 'ruby', 'ocaml', 'smarty', 'python', 'oracle11', 'caddcl', 'robots', 'groovy', 'smalltalk', 'diff', 'fortran', 'cfm', 'lua', 'modula3', 'vb', 'autoit', 'java', 'text', 'scala', 'lotusformulas', 'pixelbender', 'reg', '_div', 'whitespace', 'providex', 'asp', 'css', 'lolcode', 'lisp', 'inno', 'mysql', 'plsql', 'matlab', 'oobas', 'vim', 'delphi', 'xorg_conf', 'gml', 'prolog', 'bf', 'per', 'scheme', 'mxml', 'd', 'basic4gl', 'm68k', 'gnuplot', 'idl', 'abap', 'intercal', 'c_mac', 'thinbasic', 'java5', 'xpp', 'boo', 'klonecpp', 'blitzbasic', 'eiffel', 'povray', 'c', 'gettext'); while (<STDIN>) { foreach my $i (@langs) { s|<$i>|<lang $i>|g; s|</$i>|</lang>|g; } s|<code (.*)>|<lang \1>|g; s|</code>|</lang>|g; print; }
Python
Syntax highlighting does not work, because </lang> is inside the code.
# coding: utf-8 import sys import re langs = ['ada', 'cpp-qt', 'pascal', 'lscript', 'z80', 'visualprolog', 'html4strict', 'cil', 'objc', 'asm', 'progress', 'teraterm', 'hq9plus', 'genero', 'tsql', 'email', 'pic16', 'tcl', 'apt_sources', 'io', 'apache', 'vhdl', 'avisynth', 'winbatch', 'vbnet', 'ini', 'scilab', 'ocaml-brief', 'sas', 'actionscript3', 'qbasic', 'perl', 'bnf', 'cobol', 'powershell', 'php', 'kixtart', 'visualfoxpro', 'mirc', 'make', 'javascript', 'cpp', 'sdlbasic', 'cadlisp', 'php-brief', 'rails', 'verilog', 'xml', 'csharp', 'actionscript', 'nsis', 'bash', 'typoscript', 'freebasic', 'dot', 'applescript', 'haskell', 'dos', 'oracle8', 'cfdg', 'glsl', 'lotusscript', 'mpasm', 'latex', 'sql', 'klonec', 'ruby', 'ocaml', 'smarty', 'python', 'oracle11', 'caddcl', 'robots', 'groovy', 'smalltalk', 'diff', 'fortran', 'cfm', 'lua', 'modula3', 'vb', 'autoit', 'java', 'text', 'scala', 'lotusformulas', 'pixelbender', 'reg', '_div', 'whitespace', 'providex', 'asp', 'css', 'lolcode', 'lisp', 'inno', 'mysql', 'plsql', 'matlab', 'oobas', 'vim', 'delphi', 'xorg_conf', 'gml', 'prolog', 'bf', 'per', 'scheme', 'mxml', 'd', 'basic4gl', 'm68k', 'gnuplot', 'idl', 'abap', 'intercal', 'c_mac', 'thinbasic', 'java5', 'xpp', 'boo', 'klonecpp', 'blitzbasic', 'eiffel', 'povray', 'c', 'gettext'] for line in sys.stdin: for i in langs: line = line.replace("<%s>" % i,"<lang %s>" % i) line = line.replace("</%s>" % i, "</lang>") line = re.sub("<code (.*)>", r"<lang \1>", line) line = line.replace("</code>","</lang>") sys.stdout.write(line)