Text to HTML: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: fix bad markup) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 16: | Line 16: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
This isn't very sophisticated but does a few things in a simple-minded way. |
This isn't very sophisticated but does a few things in a simple-minded way. |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 106: | Line 106: | ||
fmt.Println("</body>") |
fmt.Println("</body>") |
||
fmt.Println("</html>") |
fmt.Println("</html>") |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
< |
<syntaxhighlight lang="html"><html> |
||
<head><title>Sample Text</title></head> |
<head><title>Sample Text</title></head> |
||
<body> |
<body> |
||
Line 125: | Line 125: | ||
<p>That's all folks.</p> |
<p>That's all folks.</p> |
||
</body> |
</body> |
||
</html></ |
</html></syntaxhighlight> |
||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="julia">using HttpCommon, Printf |
||
const exampletxt = """ Sample Text |
const exampletxt = """ Sample Text |
||
Line 212: | Line 212: | ||
txt_to_html() |
txt_to_html() |
||
</ |
</syntaxhighlight>{{out}} |
||
<pre> |
<pre> |
||
<html> |
<html> |
||
Line 235: | Line 235: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="nim">import re, strutils, xmltree |
||
const Text = """ Sample Text |
const Text = """ Sample Text |
||
Line 305: | Line 305: | ||
echo "</body>" |
echo "</body>" |
||
echo "</html>"</ |
echo "</html>"</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 328: | Line 328: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
{{trans|Raku}} |
{{trans|Raku}} |
||
< |
<syntaxhighlight lang="perl"># 20201023 added Perl programming solution |
||
use strict; |
use strict; |
||
Line 387: | Line 387: | ||
my $parser = Pod::Simple::HTML->new(); |
my $parser = Pod::Simple::HTML->new(); |
||
$parser->output_fh(*STDOUT); |
$parser->output_fh(*STDOUT); |
||
$parser->parse_string_document($pod)</ |
$parser->parse_string_document($pod)</syntaxhighlight> |
||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
The best thing to do here is to keep it utterly trivial. |
The best thing to do here is to keep it utterly trivial. |
||
<!--< |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
<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;"</span><span style="color: #0000FF;">},</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;"</span><span style="color: #0000FF;">},</span> |
||
Line 431: | 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> |
<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> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
The last line of text_to_html() (as commented out) was used to generate the |
The last line of text_to_html() (as commented out) was used to generate the |
||
Line 474: | Line 474: | ||
this implementation is still incomplete. |
this implementation is still incomplete. |
||
< |
<syntaxhighlight lang="pike">// function to calculate the average line length (not used yet below) |
||
int linelength(array lines) |
int linelength(array lines) |
||
{ |
{ |
||
Line 591: | Line 591: | ||
} |
} |
||
return root; |
return root; |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
Line 601: | Line 601: | ||
It certainly seems to me as a useful thing compared to some half-baked not-really-markdown-or-anything implementation.) |
It certainly seems to me as a useful thing compared to some half-baked not-really-markdown-or-anything implementation.) |
||
< |
<syntaxhighlight lang="racket"> |
||
#lang at-exp racket |
#lang at-exp racket |
||
Line 630: | Line 630: | ||
> and code |
> and code |
||
}) |
}) |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Line 658: | Line 658: | ||
It is '''not''' markup free, but it is actually usable in production. |
It is '''not''' markup free, but it is actually usable in production. |
||
<lang |
<syntaxhighlight lang="raku" line>use Pod::To::HTML; |
||
use HTML::Escape; |
use HTML::Escape; |
||
Line 762: | Line 762: | ||
# normally |
# normally |
||
#say render($pod6);</ |
#say render($pod6);</syntaxhighlight> |
||
{{out|Returns something like}} |
{{out|Returns something like}} |
||
Line 891: | Line 891: | ||
=={{header|Tcl}}== |
=={{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. |
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. |
||
< |
<syntaxhighlight lang="tcl">package require Tcl 8.5 |
||
proc splitParagraphs {text} { |
proc splitParagraphs {text} { |
||
Line 961: | Line 961: | ||
} |
} |
||
return [append result "</body></html>"] |
return [append result "</body></html>"] |
||
}</ |
}</syntaxhighlight> |
||
Here's an example of how it would be used. |
Here's an example of how it would be used. |
||
< |
<syntaxhighlight lang="tcl">set sample " |
||
This is an example of how a pseudo-markdown-ish formatting scheme could |
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. |
work. It's really much simpler than markdown, but does support a few things. |
||
Line 985: | Line 985: | ||
but relies on the encoding of the characters to be conveyed separately." |
but relies on the encoding of the characters to be conveyed separately." |
||
puts [markupText "Sample" $sample]</ |
puts [markupText "Sample" $sample]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
< |
<syntaxhighlight lang="html"><html><head><title>Sample</title> |
||
</head><body><h1>Sample</h1> |
</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> |
<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: | Line 998: | ||
</ol><h2>Inline formatting types</h2> |
</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 <angle brackets> and &amp;ersands, but relies on the encoding of the characters to be conveyed separately.</p> |
<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 <angle brackets> and &amp;ersands, but relies on the encoding of the characters to be conveyed separately.</p> |
||
</body></html></ |
</body></html></syntaxhighlight> |
||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
Line 1,004: | Line 1,004: | ||
{{libheader|Wren-pattern}} |
{{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. |
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. |
||
< |
<syntaxhighlight lang="ecmascript">import "/pattern" for Pattern |
||
var t = |
var t = |
||
Line 1,075: | Line 1,075: | ||
System.print("</body>") |
System.print("</body>") |
||
System.print("</html>") |
System.print("</html>") |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |