Custom <head> contents when exporting

Garry Pettet's Avatar

Garry Pettet

18 Dec, 2013 01:29 PM

Hi,

First of all - this is a wonderful app.

Secondly, I am writing a textbook comprised of a couple of hundred markdown files which I need to export as HTML. When exporting as HTML, is there a way to have Marked generate a custom element instead of the boilerplate that is included by default? It's just that this book is for the Kindle which requires certain metadata to be added to the element and doing it one file at a time is very very tedious.

Many thanks,

Garry

  1. Support Staff 1 Posted by Brett on 18 Dec, 2013 01:58 PM

    Brett's Avatar

    Do you need styles to be included? In order to include styles, Marked
    has to generate the HTML using its own template. If you don't need that,
    you can use MMD Metadata to generate head metadata in the output (just
    make sure the Strip MMD Metadata setting is off).

    Metadata key: Metadata name

    on the very first line of the document.

    -Brett

  2. 2 Posted by Garry Pettet on 18 Dec, 2013 10:38 PM

    Garry Pettet's Avatar

    Thanks Brett,

    I hadn’t noticed the metadata property of MultiMarkdown - that’s excellent but isn’t quite what I need.

    Basically, I need each page to have this format:

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
    <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
    <link type="text/css" rel="stylesheet" href="path/to/stylesheet.css" />
    <title>My eBook</title>
    </head>
    <body>
    Output HTML from Marked pasted here
    </body>
    </html>

    Whereas currently it looks like this (using the MMD metadata you mentioned):

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8"/>
    <meta name="creator" content="Marked.app"/>
    <title>My eBook</title>
    </head>
    <body>
    Output from Marked pasted here
    </body>
    </html>

    If I don’t have the exact DOCTYPE and other bits in the HTML file then it won’t validate in the Kindle KindleGen application to build the eBook.

    I’m sure this isn’t something I can change from my end but would it be possible to add a feature to Marked to write your own <head></head> element?

    Thanks in advance,

    Garry

  3. Support Staff 3 Posted by Brett on 18 Dec, 2013 10:49 PM

    Brett's Avatar

    It's potentially feasible, but probably not something I'm going to do.
    It would be far too easy to allow invalid markup and create documents
    that would only increase my support queue.

    What you're looking for is an XHTML header, which is an outdated format
    (as I'm sure you know). Your best bet is to use a custom processor that
    creates this type of header by default. You could do it by hardcoding
    the header and footer and then using any processor to output just the
    "snippet" (as opposed to full document) version of the processed input.
    If you need a hand doing this, let me know.

    -Brett

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac