cancel
Showing results for 
Search instead for 
Did you mean: 

Five easy pieces #3: Mark this

SJT
Contributor III
Contributor III

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>

 

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

 

1 ACCEPTED SOLUTION

rocuinneagain
Contributor III
Contributor III

A few different variations: 

Spoiler
-1 {i:where ""~/:x;raze "<html><body><p>",@[x;i;:;count[i]#enlist "</p><p>"],"</p></body></html>"}read0 `:smile.txt

-1"<html><body><p>",,[;"</p></body></html>"]ssr[;"\n";""]"</p><p>" sv "\n\n" vs`char$read1`:smile.txt

-1"<html><body><p>",ssr["</p><p>"sv"\n\n"vs`char$read1`:smile.txt;"\n";""],"</p></body></html>"

-1{.h.htc[y;x]}over(ssr["</p><p>"sv"\n\n"vs`char$read1`:smile.txt;"\n";""];`p;`body;`html)

-1({.h.htc[y;x]}\)(ssr["</p><p>"sv"\n\n"vs`char$read1`:smile.txt;"\n";""];`p;`body;`html)

 

View solution in original post

5 REPLIES 5

LeahS
Moderator Moderator
Moderator

Super @SJT 👏

Linking the related content for our new community members:

Five easy pieces 

Five easy pieces #2:getting around 

Happy Coding, 

Leah 

SJT
Contributor III
Contributor III

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.

rocuinneagain
Contributor III
Contributor III

A few different variations: 

Spoiler
-1 {i:where ""~/:x;raze "<html><body><p>",@[x;i;:;count[i]#enlist "</p><p>"],"</p></body></html>"}read0 `:smile.txt

-1"<html><body><p>",,[;"</p></body></html>"]ssr[;"\n";""]"</p><p>" sv "\n\n" vs`char$read1`:smile.txt

-1"<html><body><p>",ssr["</p><p>"sv"\n\n"vs`char$read1`:smile.txt;"\n";""],"</p></body></html>"

-1{.h.htc[y;x]}over(ssr["</p><p>"sv"\n\n"vs`char$read1`:smile.txt;"\n";""];`p;`body;`html)

-1({.h.htc[y;x]}\)(ssr["</p><p>"sv"\n\n"vs`char$read1`:smile.txt;"\n";""];`p;`body;`html)

 

Oh yes.  Now we’re having fun.

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

SJT
Contributor III
Contributor III

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>