Five easy pieces #3: Mark this

First stage: file smile.txt

 

The All-American Smile In a way he was like the land itself. Everything came to him too easily. But at least he knew it, and from time to time he worried about being a phoney.

 

Write a single expression that reads the file, follows Markdown rules, and returns an HTML document as a string, e.g.

 

<html><body><p>The All-American Smile</p><p>In a way he was like the land itself. Everything came to him too easily.</p><p>But at least he knew it, and from time to time he worried about being a phoney.</p></body></html>

 

Hints: The .h namespace and File Binary; however .h.ht is not a solution.

 

Super @SJT 

Linking the related content for our new community members:

Five easy pieces 

Five easy pieces #2:getting around 

Happy Coding, 

Leah 

Not tempted yet? Let’s make it easier and harder.

  • Easier: file lines have no trailing spaces.
  • Harder: let your expression contain no more than one reference to .h.htc.

A few different variations: 

-1 {i:where “”~/:x;raze “<html><body><p>”,@[x;i;:;count[i]#enlist “</p><p>”],“</p></body></html>”}read0 :smile.txt -1"&lt;html&gt;&lt;body&gt;&lt;p&gt;",,[;"&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;"]ssr[;"\n";""]"&lt;/p&gt;&lt;p&gt;" sv "\n\n" vschar$read1:smile.txt -1"&lt;html&gt;&lt;body&gt;&lt;p&gt;",ssr["&lt;/p&gt;&lt;p&gt;"sv"\n\n"vschar$read1:smile.txt;"\n";""],"&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;" -1{.h.htc[y;x]}over(ssr["&lt;/p&gt;&lt;p&gt;"sv"\n\n"vschar$read1:smile.txt;"\n";""];p;body;html) -1({.h.htc[y;x]})(ssr[“</p><p>“sv”\n\n"vschar$read1:smile.txt;”\n";“”];p;body;`html)

 

Oh yes.  Now we’re having fun.

{.h.htc[y;x]}/[.h.text"\n\n"vs"c"$ read1 `:smile.md;`body`html]

Second stage: smile2.md

 

# The All-American Smile In a way he was like the land itself. Everything came to him too easily. But at least he knew it, and from time to time he worried about being a phoney.

 

Output:

 

<html><body><h1>The All-American Smile</h1><p>In a way he was like the land itself. Everything came to him too easily.</p><p>But at least he knew it, and from time to time he worried about being a phoney.</p></body></html>