MarkdownDeep Head Block Extraction

Tuesday, March 29th, 2011     #markdowndeep #everything

Head block extraction lets Markdown authors add css, script and other content to the HTML head block of the main page.

Normally when using Markdown as a way to author static web pages, the translated markdown is simply rendered into the middle of an outer page template. This is exactly how Jab's static pages work.

In a couple of the pages on toptensoftware.com however I needed to insert script and css references into the page's head block. (eg: the MarkdownDeep Demo Page).

What I needed was a way to declare <head> content in my markdown that could be extracted and made available to the template that rendered the outer framework of each page.

MarkdownDeep provides this capability via two new properties:

ExtractHeadBlock
Set to true to enable head block extraction
HeadBlockContent
After translating a markdown document, this property will hold the content of any embedded head blocks.

So, say you have a markdown document like this:

<head>
<script type="text/javascript" src="/js/myscript.js">
</head>

Normal markdown paragraph here

<head>
<title>Oh!, an here's a title</title>
</head>

If you set ExtractHeadBlock to true after translating the markdown the HeadBlockContent property will contain this:

<script type="text/javascript" src="/js/myscript.js">
<title>Oh!, an here's a title</title>

ie: exactly what needs to be inserted into the final page's head block.

(Note the <head> tags themselves have already been removed).

These improvements are available now in github and the latest NuGet packages.

« Older - MarkdownDeep Syntax Highlighting Newer - MarkdownDeep Improved URL Qualification »