Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Markdown string interpolation
package org.streum.interpol
/* Here is the interpolator itself, we just add a method `md`
to the `StringContext` using implicit conversions */
object Markdown {
implicit class MDContext( val context: StringContext ) extends AnyVal {
// I used knockoff markdown processor. I don't have any real experience with
// it but it looks very good
import com.tristanhunt.knockoff.DefaultDiscounter._
// args will contain the value that will be interpolated
def md( args: Any* ) = {
//Here we use the standard interpolation first
val interpolated = context.s(args:_*)
//We then call knockoff to process the resulting string
toXHTML( knockoff( interpolated ) )
package org.streum.interpol
/* Example usage. The ouput is presented in file output.html (below) */
object Main extends App {
import Markdown._
def farenheit( celsius: Int ) = ( celsius*9.0/5 + 32 ).toInt
val location = "Anchorage, AK"
val url = ",_Alaska"
val temp = -3
println( md"**[$location]($url):** *$temp°C* (${farenheit(temp)}°F)" )
<p><strong><a href=",_Alaska">Anchorage, AK</a>:</strong> <em>-3°C</em> (26°F)</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.