insert lines from text file in a HTML boilerplate Haskell

Its me again... So, I am supposed to take in an input.md file into my program. This file is a markdown file of some basic html. ex:

Title!

This should be simple.

But its not

---

body of text 

---

So that's the basic structure of my input file. Now in my project, I need to format the incoming lines of String so the "Title!", or line 1 of the file goes into the HTML layout in the title space. the header goes between the title and the horizontal rule, the body after the horizontal rule.

This is the layout I am working with.

  <html>
      <head>
          <meta http-equiv="content-type" content="text/html; charset=utf-8">
          <title>The Title</title>
      </head>
      <body>
       Body Goes Here
      </body>
  </html>

Am I overcomplicating this solution at all? Wouldnt I just give the head line title tags and tail lines body tags? It seems that simple. But yet, I don't know html too well, and this chunk of code is just laying in my haskell program creating a bunch of problems..

Thanks guys

Upvotes: 0

Views: 78

Answers (1)

CR Drost
CR Drost

Reputation: 9817

Are you using an HTML library or just string concatenation? Because HTML is a plain text format, so you can just do this:

makeDoc title body = unlines [
    "<html>",
    "    <head>",
    "        <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">",
    "        <title>" ++ title ++ "</title>",
    "    </head>",
    "    <body>",
    body,
    "    </body>",
    "</html>"]

On the flip-side, your markdown text, if placed literally in there, will not be properly converted to HTML; it will look like This should be simple. But its not --- body of text ---. For this you need a Markdown parser. For that, look at examples like these ones after cabal install markdown; you'll need to format only the body and not the title (since title elements in HTML are plain text).

If you're still confused about HTML, a great resource is the HTML 4.01 spec and its DTD.

Upvotes: 1

Related Questions