/** * Yona, 21st Century Project Hosting SW *

* Copyright Yona & Yobi Authors & NAVER Corp. & NAVER LABS Corp. * https://yona.io **/ yobi.Markdown = (function(htOptions){ var htVar = {}; /** * initialize * @param {Hash Table} htOptions */ function _init(htOptions){ htOptions = htOptions || {}; _initVar(htOptions); _enableMarkdown(htOptions.aTarget); } /** * initialize variables * @param {Hash Table} htOptions */ function _initVar(htOptions){ htVar.sMarkdownRendererUrl = htOptions.sMarkdownRendererUrl; htVar.htMarkedOption = { "gfm" : true, "tables" : true, "pedantic" : false, "sanitize" : false, "smartLists": true, "langPrefix": '', "highlight" : function(sCode, sLang) { if(sLang) { try { return hljs.highlight(sLang.toLowerCase(), sCode).value; } catch(oException) { console.log(oException.message); } } } }; } /** * Render as Markdown document * * @require showdown.js * @require hljs.js * @param {String} sText * @return {String} */ function _renderMarkdown(sText) { return $yobi.xssClean(marked(sText, htVar.htMarkedOption)); } /** * Replace auto-link * @param welTarget * @param sContentBody * @private */ function _replaceAutoLink(welTarget, sContentBody){ /** * If this ajax request is failed, do anything. * Because, the content body not replaced is shown to user before this request. */ if(htVar.sMarkdownRendererUrl){ _render(welTarget, sContentBody); } } function _render(welTarget, sContentBody) { var source = { "body": sContentBody, "breaks": (welTarget.hasClass('readme-body') ? false : true) }; $.ajax(htVar.sMarkdownRendererUrl,{ "type": "post", "contentType":"application/json; charset=utf-8", "data": JSON.stringify(source), "success": function(data){ welTarget.html(data); $('pre code').each(function(i, block) { hljs.highlightBlock(block); }); } }); } /** * set Markdown Viewer * * @param {Wrapped Element} welTarget is not