Rosetta Code/Fix code tags

From Rosetta Code
Task
Rosetta Code/Fix code tags
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

AutoHotkey

<lang AutoHotkey>

usage
fixtags.ahk input.txt ouput.txt

FileRead, text, %1% langs = ada,awk,autohotkey,etc slang = /lang slang := "<" . slang . "/>" loop, parse, langs, `, { tag1 = <%A_LoopField%> tag2 = </%A_LoopField%>

   text := Regexreplace(text, tag1,"<lang " . A_LoopField . ">")
   text := Regexreplace(text, tag2, slang)
   text := RegexReplace(text, "(.*?)"
   , "<lang $1>$2" . slang)

} FileAppend, % text, %2% </lang>

Perl

<lang perl> my @langs = qw(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);

my $text = join "", <STDIN>; my $slang="/lang"; for (@langs) {

   $text =~ s|<$_>|<lang $_>|g;
   $text =~ s|</$_>|<$slang>|g;

}

$text =~ s|(.*?)|<lang $1>$2<$slang>|sg;

print $text; </lang>

Python

<lang python>

  1. 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']

slang = '/lang'

text = sys.stdin.read()

for i in langs:

   text = text.replace("<%s>" % i,"<lang %s>" % i)
   text = text.replace("</%s>" % i, "<%s>" % slang)

text = re.sub("(?s)(.*?)", r"<lang \1>\2<%s>" % slang, text)

sys.stdout.write(text) </lang>

Tcl

<lang tcl>set 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

}

set text [read stdin] set slang /lang foreach lang $langs {

   set text [regsub -all "<$lang>" $text "<lang $lang>"]
   set text [regsub -all "</$lang>" $text "<$slang>"]

} set text [regsub -all "(.+?)" $text "<lang \\1>\\2<$slang>"]</lang> Alternatively, for foreach loop may be replaced with: <lang tcl>set text [regexp -all "<([join $langs |])>" $text {<lang \1>}] set text [regexp -all "</(?:[join $langs |])>" $text "<$slang>"]</lang>