Skip to content

Instantly share code, notes, and snippets.

@blak3r
Last active May 3, 2019 15:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blak3r/ac59134239efdcc74328 to your computer and use it in GitHub Desktop.
Save blak3r/ac59134239efdcc74328 to your computer and use it in GitHub Desktop.
Zendesk, Hack to allow authoring in Markdown (which renders to HTML when viewing)
/**
* Step 1: Download showdown.js, from here: https://raw.githubusercontent.com/showdownjs/showdown/master/compressed/showdown.js
* Step 2: Customize Design --> edit theme --> assets and upload it.
* Step 3: Add a script tag to your head using the url from asset page.
* Step 4: Add this to article-body section, Javascript (make sure you select JS), add it before
* Step 5: Create an article, switch to source view, add <PRE>- to the top of the file,
* then put your markdown and end it with a </PRE>. If you don't do this, when you save the wysiwg will screw
* your markdown with html markup. The - is just what i chose to put on the top line... it could be any character
* or string
*
* This will not modify any non-markdown articles you have unless it starts with "<PRE>-""
*/
try {
// If .article-body exists and it starts with <PRE>-
if($('.article-body') && $('.article-body').html() && $('.article-body').html().match(/^\s*<PRE>-/i) ) {
var converter = new Showdown.converter();
// Remove the <PRE>- and </PRE>
var justMarkdownPortion = $('.article-body').html().replace(/<PRE>-/ig,"").replace(/<\/pre>/gi, "");
// Render the markdown and set the inner html of .article-body
var renderedHtml = converter.makeHtml(justMarkdownPortion);
$('.article-body').html( renderedHtml );
}
}catch(err) { console.error("showdown exc",err); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment