Last active
May 3, 2019 15:03
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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