[racket] [Frog] Code examples in handwritten HTML

From: Greg Hendershott (greghendershott at gmail.com)
Date: Mon Oct 21 13:16:30 EDT 2013

On Mon, Oct 21, 2013 at 9:34 AM, Joe Gibbs Politz <joe at cs.brown.edu> wrote:
> I want to write an index page with some handwritten HTML using Frog,
> and I want it to include source code.  Two issues.  First, it seems
> like Frog doesn't respect my <pre> structure.  If I write something
> like this in _src/index.html:

The intended use of Frog is a site that is a blog, plus some non-blog
pages. The sources are Markdown (or Scribble) format files. These get
processed and put in _src/page-template.html for a consistent sitewide
structure. (The sources that are blog posts are put inside
_src/post-template.html, which in turn is nested in
_src/page-template.html). Certain pages like /index.html are generated
automatically.

So right off the bat, I'm not sure I understand you making a
_src/index.html file. Because both (1) it should be .md or .scrbl, and
(2) it shouldn't be /index.

However let's say you mean _src/foo.md --- a Markdown source file for
some generic non-post page:

> # Index page
>
> <div class="container">
>   <div class="row">
>   <div class="col-md-4">
>   Some exciting text!
>   </div>
>   <div class="col-md-8">
> <pre>
> fun sum(l :: List):
>   cases(List) l:
>     | empty => 0
>     | link(first, rest) => first + sum(rest)
>   end
> where:
>   sum([]) is 0
>   sum([1, 2, 3]) is 6
> end
> </pre>
>   </div>
>   </div>
> </div>
>
>
> And then I build, the generated index looks like this:
>
>
>  <div class="container">
>   <div class="row">
>    <div class="col-md-4"> Some exciting text!  </div>
>    <div class="col-md-8">
>     <pre> fun sum(l :: List): cases(List) l: | empty => 0 |
> link(first, rest) => first + sum(rest) end where: sum([]) is 0
> sum([1, 2, 3]) is 6 end </pre> </div> </div> </div></p>
>         </div>
>
> Which destroys my line breaks.  If I put in <br/>s at the end of each
> line, breaks *are* preserved, but then there's two line breaks for
> each line.

This should be valid Markdown, because you can can include HTML in
Markdown (with some practical limits).

However it looks like my Markdown parser isn't respecting linebreaks
in <pre> formatting.

I didn't realize that because it's an unexercised case. Normally
people using Markdown would use indented or fenced (```) code blocks,
just because it's simpler than typing <pre>....</pre>.  But if they
want to use <pre>, -- or need to because of fancier local formatting
as in your case -- then it ought to work. So I logged that as a bug
[1] and have a fix ready to commit and push, shortly.

[1]: https://github.com/greghendershott/markdown/issues/21

Posted on the users mailing list.