Text to HTML: Difference between revisions
→{{header|Phix}}
m (→{{header|Racket}}: Typo) |
|||
Line 13:
The only requirement is to ensure that the result is valid xhtml.
=={{header|Phix}}==
The best thing to do here is to keep it utterly trivial.
<lang Phix>constant {hchars,hsubs} = columnize({{"&","&"},
{"<","<"},
{">",">"},
{"\"","""},
{"\'","'"}})
constant fmt = """
<html>
<head><title>%s</title></head>
<body>
<pre>
%s
</pre>
</body>
</html>
"""
function text_to_html_page(string title, text)
title = substitute_all(title,hchars,hsubs)
text = substitute_all(text,hchars,hsubs)
return sprintf(fmt,{title,text})
-- return substitute_all(sprintf(fmt,{title,text}),hchars,hsubs)
end function
constant text = """
This is
a paragraph
a block of
code
* A one-bullet list
> With quoted text
>
> and code
"""
puts(1,text_to_html_page("my title",text))</lang>
{{out}}
The last line of text_to_html() (as commented out) was used to generate the
sanitised version of the output, as needed for inclusion on this page.
<pre>
<html>
<head><title>my title</title></head>
<body>
<pre>
This is
a paragraph
a block of
code
* A one-bullet list
&gt; With quoted text
&gt;
&gt; and code
</pre>
</body>
</html>
</pre>
=={{header|Pike}}==
|