Skip to content

Instantly share code, notes, and snippets.

@trcook
Last active August 29, 2015 14:09
Show Gist options
  • Save trcook/e77196aad716b9f333cf to your computer and use it in GitHub Desktop.
Save trcook/e77196aad716b9f333cf to your computer and use it in GitHub Desktop.
Use latex output from kramdown to set custom environments based on classes defined in kramdown.

Start with some kramdown markdown:

{:.custom} 
* this is the start of a list

This is the output:

\begin{itemize}   %  class="custom"
\item this is the start of a list
\end{itemize}   %  class="custom"

Now run these regex filters on it:


(?# Find:)
^\ *\\begin\{\w+?\}.*%[ |\t]+class="(\w+?)".*?\n

(?# Replace:)
\\begin{\1}\n



(?# Find:)
^\ *\\end\{\w+?\}.*%[ |\t]+class="(\w+?)".*?\n

(?# Replace:)
\\end{\1}\n

Final Result.text

\begin{custom}
\item this is the start of a list
\end{custom}

Good for styling using custom environments. Enables semantic tagging in markdown.

Use case: cases where you want to write markdown once and output to multiple formats (html, latex) while keeping special formatting based on defined classes. For example, creation of a codebook or technical manual.

(?# Find:)
^\ *\\begin\{\w+?\}.*%[ |\t]+class="(\w+?)".*?\n
(?# Replace:)
\\begin{\1}\n
(?# Find:)
^\ *\\end\{\w+?\}.*%[ |\t]+class="(\w+?)".*?\n
(?# Replace:)
\\end{\1}\n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment