Rosetta Code/Fix code tags: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: syntax coloured) |
m (new example and change in task) |
||
Line 5: | Line 5: | ||
Fix Rosetta Code deprecated code tags, with these rules: |
Fix Rosetta Code deprecated code tags, with these rules: |
||
<pre> |
<pre> |
||
Change <%s> to < |
Change <lang %s> to <syntaxhighlight lang=%s> |
||
Change </ |
Change </lang> to </syntaxhighlight> |
||
Change < |
Change <lang> to <syntaxhighlight lang=text> |
||
Change </code> to </lang> |
|||
</pre> |
</pre> |
||
;Demonstarte the task on these examples: |
|||
<pre> |
|||
<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, "<code (.+?)>(.*?)</code>" |
|||
, "<lang $1>$2" . slang) |
|||
} |
|||
FileAppend, % text, %2% |
|||
</lang> |
|||
</pre> |
|||
<pre> |
|||
<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>; |
|||
;Usage: |
|||
my $slang="/lang"; |
|||
for (@langs) { |
|||
$text =~ s|<$_>|<lang $_>|g; |
|||
$text =~ s|</$_>|<$slang>|g; |
|||
} |
|||
$text =~ s|<code (.+?)>(.*?)</code>|<lang $1>$2<$slang>|sg; |
|||
print $text;</lang> |
|||
</pre> |
|||
<pre> |
<pre> |
||
<lang>HAI 1.3 |
|||
./convert.py < wikisource.txt > converted.txt |
|||
I HAS A bottles ITZ 99 I HAS A plural ITZ "Z" I HAS A lyric ITZ "99 BOTTLZ OV BEER" |
|||
IM IN YR song |
|||
VISIBLE lyric " ON TEH WALL" |
|||
VISIBLE lyric |
|||
VISIBLE "TAEK 1 DOWN, PAZ IT AROUN" |
|||
bottles R DIFF OF bottles AN 1 |
|||
NOT bottles, O RLY? |
|||
YA RLY, VISIBLE "NO MOAR BOTTLZ OV BEER ON TEH WALL", GTFO |
|||
OIC |
|||
BOTH SAEM bottles AN 1, O RLY? |
|||
YA RLY, plural R "" |
|||
OIC |
|||
lyric R SMOOSH bottles " BOTTL" plural " OV BEER" MKAY |
|||
VISIBLE lyric " ON TEH WALL:)" |
|||
IM OUTTA YR song |
|||
KTHXBYE</lang> |
|||
</pre> |
</pre> |
||
<br><br> |
<br><br> |
||
Line 937: | Line 1,001: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
<lang |
<syntaxhighlight lang=python> |
||
""" Rosetta Code task rosettacode.org/wiki/Rosetta_Code/Fix_code_tags """ |
|||
import |
from re import sub |
||
import re |
|||
testtexts = [ |
|||
langs = ['ada', 'cpp-qt', 'pascal', 'lscript', 'z80', 'visualprolog', |
|||
"""<lang AutoHotkey>; usage: > fixtags.ahk input.txt ouput.txt |
|||
'html4strict', 'cil', 'objc', 'asm', 'progress', 'teraterm', 'hq9plus', |
|||
FileRead, text, %1% |
|||
'genero', 'tsql', 'email', 'pic16', 'tcl', 'apt_sources', 'io', 'apache', |
|||
langs = ada,awk,autohotkey,etc |
|||
'vhdl', 'avisynth', 'winbatch', 'vbnet', 'ini', 'scilab', 'ocaml-brief', |
|||
slang = /lang |
|||
'sas', 'actionscript3', 'qbasic', 'perl', 'bnf', 'cobol', 'powershell', |
|||
slang := "<" . slang . "/>" |
|||
'php', 'kixtart', 'visualfoxpro', 'mirc', 'make', 'javascript', 'cpp', |
|||
Loop, Parse, langs, `, |
|||
'sdlbasic', 'cadlisp', 'php-brief', 'rails', 'verilog', 'xml', 'csharp', |
|||
{ |
|||
'actionscript', 'nsis', 'bash', 'typoscript', 'freebasic', 'dot', |
|||
tag1 = <%A_LoopField%> |
|||
'applescript', 'haskell', 'dos', 'oracle8', 'cfdg', 'glsl', 'lotusscript', |
|||
tag2 = </%A_LoopField%> |
|||
'mpasm', 'latex', 'sql', 'klonec', 'ruby', 'ocaml', 'smarty', 'python', |
|||
text := RegExReplace(text, tag1, "<lang " . A_LoopField . ">") |
|||
'oracle11', 'caddcl', 'robots', 'groovy', 'smalltalk', 'diff', 'fortran', |
|||
text := RegExReplace(text, tag2, slang) |
|||
'cfm', 'lua', 'modula3', 'vb', 'autoit', 'java', 'text', 'scala', |
|||
text := RegExReplace(text, "<code (.+?)>(.*?)</code>" |
|||
'lotusformulas', 'pixelbender', 'reg', '_div', 'whitespace', 'providex', |
|||
, "<lang $1>$2" . slang) |
|||
'asp', 'css', 'lolcode', 'lisp', 'inno', 'mysql', 'plsql', 'matlab', |
|||
} |
|||
'oobas', 'vim', 'delphi', 'xorg_conf', 'gml', 'prolog', 'bf', 'per', |
|||
FileAppend, % text, %2% |
|||
'scheme', 'mxml', 'd', 'basic4gl', 'm68k', 'gnuplot', 'idl', 'abap', |
|||
</lang>""", |
|||
'intercal', 'c_mac', 'thinbasic', 'java5', 'xpp', 'boo', 'klonecpp', |
|||
"""<lang perl>my @langs = qw(ada cpp-qt pascal lscript z80 visualprolog |
|||
'blitzbasic', 'eiffel', 'povray', 'c', 'gettext'] |
|||
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>; |
|||
slang = '/lang' |
|||
my $slang="/lang"; |
|||
code='code' |
|||
for (@langs) { |
|||
$text =~ s|<$_>|<lang $_>|g; |
|||
$text =~ s|</$_>|<$slang>|g; |
|||
} |
|||
$text =~ s|<code (.+?)>(.*?)</code>|<lang $1>$2<$slang>|sg; |
|||
text = sys.stdin.read() |
|||
print $text;</lang>""", |
|||
for i in langs: |
|||
"""<lang>HAI 1.3 |
|||
text = text.replace("</%s>" % i, "<%s>" % slang) |
|||
I HAS A bottles ITZ 99 I HAS A plural ITZ "Z" I HAS A lyric ITZ "99 BOTTLZ OV BEER" |
|||
text = re.sub("(?s)<%s (.+?)>(.*?)</%s>"%(code,code), r"<lang \1>\2<%s>" % slang, text) |
|||
IM IN YR song |
|||
sys.stdout.write(text) |
|||
</lang> |
|||
VISIBLE lyric " ON TEH WALL" |
|||
VISIBLE lyric |
|||
VISIBLE "TAEK 1 DOWN, PAZ IT AROUN" |
|||
bottles R DIFF OF bottles AN 1 |
|||
NOT bottles, O RLY? |
|||
YA RLY, VISIBLE "NO MOAR BOTTLZ OV BEER ON TEH WALL", GTFO |
|||
OIC |
|||
BOTH SAEM bottles AN 1, O RLY? |
|||
YA RLY, plural R "" |
|||
OIC |
|||
lyric R SMOOSH bottles " BOTTL" plural " OV BEER" MKAY |
|||
VISIBLE lyric " ON TEH WALL:)" |
|||
IM OUTTA YR song |
|||
KTHXBYE</lang> |
|||
"""] |
|||
for txt in testtexts: |
|||
text2 = sub(r'<lang\s+([\w\d\s]+)>', r'<syntaxhighlight lang=\1>', txt) |
|||
text2 = sub(r'<lang\s*>', r'<syntaxhighlight lang=text>', text2) |
|||
text2 = sub(r'</lang\s*>', r'</syntaxhighlight>', text2) |
|||
print(txt, '\n=>\n', text2) |
|||
</lang>{{out}} |
|||
<pre> |
|||
<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, "<code (.+?)>(.*?)</code>" |
|||
, "<lang $1>$2" . slang) |
|||
} |
|||
FileAppend, % text, %2% |
|||
</lang> |
|||
=> |
|||
<syntaxhighlight 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, "<code (.+?)>(.*?)</code>" |
|||
, "<lang $1>$2" . slang) |
|||
} |
|||
FileAppend, % text, %2% |
|||
</syntaxhighlight> |
|||
<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|<code (.+?)>(.*?)</code>|<lang $1>$2<$slang>|sg; |
|||
print $text;</lang> |
|||
=> |
|||
<syntaxhighlight 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|<code (.+?)>(.*?)</code>|<lang $1>$2<$slang>|sg; |
|||
print $text;</syntaxhighlight> |
|||
<lang>HAI 1.3 |
|||
I HAS A bottles ITZ 99 I HAS A plural ITZ "Z" I HAS A lyric ITZ "99 BOTTLZ OV BEER" |
|||
IM IN YR song |
|||
VISIBLE lyric " ON TEH WALL" |
|||
VISIBLE lyric |
|||
VISIBLE "TAEK 1 DOWN, PAZ IT AROUN" |
|||
bottles R DIFF OF bottles AN 1 |
|||
NOT bottles, O RLY? |
|||
YA RLY, VISIBLE "NO MOAR BOTTLZ OV BEER ON TEH WALL", GTFO |
|||
OIC |
|||
BOTH SAEM bottles AN 1, O RLY? |
|||
YA RLY, plural R "" |
|||
OIC |
|||
lyric R SMOOSH bottles " BOTTL" plural " OV BEER" MKAY |
|||
VISIBLE lyric " ON TEH WALL:)" |
|||
IM OUTTA YR song |
|||
KTHXBYE</lang> |
|||
=> |
|||
<syntaxhighlight lang=text>HAI 1.3 |
|||
I HAS A bottles ITZ 99 I HAS A plural ITZ "Z" I HAS A lyric ITZ "99 BOTTLZ OV BEER" |
|||
IM IN YR song |
|||
VISIBLE lyric " ON TEH WALL" |
|||
VISIBLE lyric |
|||
VISIBLE "TAEK 1 DOWN, PAZ IT AROUN" |
|||
bottles R DIFF OF bottles AN 1 |
|||
NOT bottles, O RLY? |
|||
YA RLY, VISIBLE "NO MOAR BOTTLZ OV BEER ON TEH WALL", GTFO |
|||
OIC |
|||
BOTH SAEM bottles AN 1, O RLY? |
|||
YA RLY, plural R "" |
|||
OIC |
|||
lyric R SMOOSH bottles " BOTTL" plural " OV BEER" MKAY |
|||
VISIBLE lyric " ON TEH WALL:)" |
|||
IM OUTTA YR song |
|||
KTHXBYE</syntaxhighlight> |
|||
</pre> |
|||
=={{header|R}}== |
=={{header|R}}== |