Format Post (HTML)

Posted by @nahumck, Last update over 5 years ago

Convert a Markdown-formatted draft into HTML for posting. Creates a pristine copy of the Markdown for safe keeping.


  • script

    // Process Post for sending to Workflow
    // Create backup draft prior to processing
    var d = Draft.create();
    d.content = draft.processTemplate("[[draft]]");
    //Update the current draft text converted to HTML
    var content = draft.content;
    var conv = draft.processTemplate("%%[[draft]]%%");
    draft.content = conv;
    // Add id tags to HTML headers based on their content
    var newContent = content.replace(/<h(\d)>(.*?)<\/h\d>/gi, '<h$1 id="$2">$2</h$1>');
    // make the ids lowercase and hyphenated
    newContent = newContent.replace(/id=".*?"/gi, function makeID(a){
    	a = a.replace(/\s/g, "-");
    	a = a.toLowerCase();
    	return a;
    // Add changes to HTML <img> tags
    var content = draft.content;
    newContent = content.replace(/img src/gi, "img class=\"aligncenter\" style=\"maxwidth:1136\" src");
    draft.content = newContent


  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.