Tuesday, January 11, 2011
Saturday, January 8, 2011
Using Markdown in ColdFusion
Markdown is "a text-to-HTML conversion tool for web writers. Markdown allows you to write using an easy-to-read, easy-to-write plain text format, then convert it to structurally valid XHTML (or HTML)."
Here's a quick post describing how you can use Markdown in ColdFusion.
First, download MarkdownJ, a Java port of the Markdown conversion utility originally written in Perl. Here's a direct link to the download site: http://code.google.com/p/markdownj/.
Next, either put the markdownj.jar file in the ColdFusion classpath or download JavaLoader. I prefer using JavaLoader, so that's what my example will show.
Finally, some code:
The above code will produce the following HTML output:
OK. So if that's the simple example, what about a more complex example?
And that's the basics of Markdown. Here's a full set of syntax rules: http://daringfireball.net/projects/markdown/syntax. Pretty sweet if you ask me.
Here's a quick post describing how you can use Markdown in ColdFusion.
First, download MarkdownJ, a Java port of the Markdown conversion utility originally written in Perl. Here's a direct link to the download site: http://code.google.com/p/markdownj/.
Next, either put the markdownj.jar file in the ColdFusion classpath or download JavaLoader. I prefer using JavaLoader, so that's what my example will show.
Finally, some code:
<cfset paths = [ expandPath("markdownj-1.0.2b4-0.3.0.jar") ] />
<cfset javaLoader = new javaloader.JavaLoader(paths, true) />
<cfset markdownProcessor = javaLoader.create("com.petebevin.markdown.MarkdownProcessor").init() />
<cfset html = markdownProcessor.markdown("This is a *simple* example") />
<cfoutput>
#html#
</cfoutput>
The above code will produce the following HTML output:
<p>This is a <em>simple</em> example</p>
OK. So if that's the simple example, what about a more complex example?
# This is an h1
## This is an h2
This is a normal paragraph. Lorem ipsum dolor sit amet,
consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
* This is a unordered list. Hanging indents allow
you to wrap a list item onto multiple lines
* List item 2
* List item 3
---
These are horizontal rules
***
This is how to *italicize* something. This is _another way_ to italicize something.
This is how to **bold** something. This is __another way__ to bold something.
1. This is an ordered list
2. List item 2
3. List item 3
This is [an example](http://example.com/ "Title") inline link.
[This link](http://example.net/) has no title attribute.
> This is a block quote. Lorem ipsum dolor sit amet,
> consectetur adipisicing elit, sed do eiusmod tempor
> incididunt ut labore et dolore magna aliqua.
This is a code block.
To produce a code block in Markdown, simply
indent every line of the block by at least
4 spaces or 1 tab
And that's the basics of Markdown. Here's a full set of syntax rules: http://daringfireball.net/projects/markdown/syntax. Pretty sweet if you ask me.
Subscribe to:
Posts (Atom)