
Markdown rendering : Fix bug in help page.
Recover _setViewer() method because the help markdown area depends on this method.
@9a5f15f25224f67f55ae333dced906db42c6f2da
--- public/javascripts/common/yobi.Markdown.js
+++ public/javascripts/common/yobi.Markdown.js
... | ... | @@ -38,7 +38,38 @@ |
38 | 38 |
* @param {Hash Table} htOptions |
39 | 39 |
*/ |
40 | 40 |
function _initVar(htOptions){ |
41 |
+ htVar.htFilter = new Filter(); |
|
41 | 42 |
htVar.sMarkdownRendererUrl = htOptions.sMarkdownRendererUrl; |
43 |
+ |
|
44 |
+ htVar.htMarkedOption = { |
|
45 |
+ "gfm" : true, |
|
46 |
+ "tables" : true, |
|
47 |
+ "pedantic" : false, |
|
48 |
+ "sanitize" : false, |
|
49 |
+ "smartLists": true, |
|
50 |
+ "langPrefix": '', |
|
51 |
+ "highlight" : function(sCode, sLang) { |
|
52 |
+ if(sLang) { |
|
53 |
+ try { |
|
54 |
+ return hljs.highlight(sLang.toLowerCase(), sCode).value; |
|
55 |
+ } catch(oException) { |
|
56 |
+ console.log(oException.message); |
|
57 |
+ } |
|
58 |
+ } |
|
59 |
+ } |
|
60 |
+ }; |
|
61 |
+ } |
|
62 |
+ |
|
63 |
+ /** |
|
64 |
+ * Render as Markdown document |
|
65 |
+ * |
|
66 |
+ * @require showdown.js |
|
67 |
+ * @require hljs.js |
|
68 |
+ * @param {String} sText |
|
69 |
+ * @return {String} |
|
70 |
+ */ |
|
71 |
+ function _renderMarkdown(sText) { |
|
72 |
+ return htVar.htFilter.sanitize(marked(sText, htVar.htMarkedOption)).xss(); |
|
42 | 73 |
} |
43 | 74 |
|
44 | 75 |
/** |
... | ... | @@ -65,6 +96,18 @@ |
65 | 96 |
welTarget.html(data); |
66 | 97 |
} |
67 | 98 |
}); |
99 |
+ } |
|
100 |
+ |
|
101 |
+ /** |
|
102 |
+ * set Markdown Viewer |
|
103 |
+ * |
|
104 |
+ * @param {Wrapped Element} welTarget is not <textarea> or <input> |
|
105 |
+ */ |
|
106 |
+ function _setViewer(welTarget){ |
|
107 |
+ var sMarkdownText = welTarget.text(); |
|
108 |
+ var sContentBody = (sMarkdownText) ? _renderMarkdown(sMarkdownText) : welTarget.html(); |
|
109 |
+ $('.markdown-loader').remove(); |
|
110 |
+ welTarget.html(sContentBody).removeClass('markdown-before'); |
|
68 | 111 |
} |
69 | 112 |
|
70 | 113 |
/** |
... | ... | @@ -109,9 +152,7 @@ |
109 | 152 |
var waTarget = $(sQuery || "[markdown]"); // TODO: markdown=true |
110 | 153 |
|
111 | 154 |
waTarget.each(function(nIndex, elTarget){ |
112 |
- if(_isEditableElement(elTarget)){ |
|
113 |
- _setEditor($(elTarget)); |
|
114 |
- }; |
|
155 |
+ _isEditableElement(elTarget) ? _setEditor($(elTarget)) : _setViewer($(elTarget)); |
|
115 | 156 |
}); |
116 | 157 |
} |
117 | 158 |
|
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?