Text to HTML: Difference between revisions

m
syntax highlighting fixup automation
m (→‎{{header|Phix}}: fix bad markup)
m (syntax highlighting fixup automation)
Line 16:
=={{header|Go}}==
This isn't very sophisticated but does a few things in a simple-minded way.
<langsyntaxhighlight lang="go">package main
 
import (
Line 106:
fmt.Println("</body>")
fmt.Println("</html>")
}</langsyntaxhighlight>
 
{{out}}
<langsyntaxhighlight lang="html"><html>
<head><title>Sample Text</title></head>
<body>
Line 125:
<p>That&#39;s all folks.</p>
</body>
</html></langsyntaxhighlight>
 
=={{header|Julia}}==
{{trans|Go}}
<langsyntaxhighlight lang="julia">using HttpCommon, Printf
 
const exampletxt = """ Sample Text
Line 212:
 
txt_to_html()
</langsyntaxhighlight>{{out}}
<pre>
<html>
Line 235:
=={{header|Nim}}==
{{trans|Go}}
<langsyntaxhighlight Nimlang="nim">import re, strutils, xmltree
 
const Text = """ Sample Text
Line 305:
 
echo "</body>"
echo "</html>"</langsyntaxhighlight>
 
{{out}}
Line 328:
=={{header|Perl}}==
{{trans|Raku}}
<langsyntaxhighlight Perllang="perl"># 20201023 added Perl programming solution
 
use strict;
Line 387:
my $parser = Pod::Simple::HTML->new();
$parser->output_fh(*STDOUT);
$parser->parse_string_document($pod)</langsyntaxhighlight>
 
=={{header|Phix}}==
The best thing to do here is to keep it utterly trivial.
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">constant</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">hchars</span><span style="color: #0000FF;">,</span><span style="color: #000000;">hsubs</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">columnize</span><span style="color: #0000FF;">({{</span><span style="color: #008000;">"&"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"&amp;amp;"</span><span style="color: #0000FF;">},</span>
Line 431:
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">text_to_html_page</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"my title"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">text</span><span style="color: #0000FF;">))</span>
<!--</langsyntaxhighlight>-->
{{out}}
The last line of text_to_html() (as commented out) was used to generate the
Line 474:
 
this implementation is still incomplete.
<langsyntaxhighlight Pikelang="pike">// function to calculate the average line length (not used yet below)
int linelength(array lines)
{
Line 591:
}
return root;
}</langsyntaxhighlight>
 
=={{header|Racket}}==
Line 601:
It certainly seems to me as a useful thing compared to some half-baked not-really-markdown-or-anything implementation.)
 
<langsyntaxhighlight lang="racket">
#lang at-exp racket
 
Line 630:
> and code
})
</syntaxhighlight>
</lang>
 
{{out}}
Line 658:
 
It is '''not''' markup free, but it is actually usable in production.
<syntaxhighlight lang="raku" perl6line>use Pod::To::HTML;
use HTML::Escape;
 
Line 762:
 
# normally
#say render($pod6);</langsyntaxhighlight>
 
{{out|Returns something like}}
Line 891:
=={{header|Tcl}}==
This renderer doesn't do all that much. Indeed, it deliberately avoids doing all the complexity that is possible; instead it seeks to just provide the minimum that could possibly be useful to someone who is doing very simple text pages.
<langsyntaxhighlight lang="tcl">package require Tcl 8.5
 
proc splitParagraphs {text} {
Line 961:
}
return [append result "</body></html>"]
}</langsyntaxhighlight>
Here's an example of how it would be used.
<langsyntaxhighlight lang="tcl">set sample "
This is an example of how a pseudo-markdown-ish formatting scheme could
work. It's really much simpler than markdown, but does support a few things.
Line 985:
but relies on the encoding of the characters to be conveyed separately."
 
puts [markupText "Sample" $sample]</langsyntaxhighlight>
{{out}}
<langsyntaxhighlight lang="html"><html><head><title>Sample</title>
</head><body><h1>Sample</h1>
<p>This is an example of how a pseudo-markdown-ish formatting scheme could work. It's really much simpler than markdown, but does support a few things.</p>
Line 998:
</ol><h2>Inline formatting types</h2>
<p>The formatter can render text with <i>italics</i>, <b>bold</b> and in a <tt>typewriter</tt> font. It also does the right thing with &lt;angle brackets&gt; and &amp;amp;ersands, but relies on the encoding of the characters to be conveyed separately.</p>
</body></html></langsyntaxhighlight>
 
=={{header|Wren}}==
Line 1,004:
{{libheader|Wren-pattern}}
Note that Wren doesn't support any form of raw string so we need to construct the sample text by concatenating strings for each paragraph.
<langsyntaxhighlight lang="ecmascript">import "/pattern" for Pattern
 
var t =
Line 1,075:
System.print("</body>")
System.print("</html>")
</syntaxhighlight>
</lang>
 
{{out}}
10,333

edits