From bca42fd594ad16cc1bddf0ec08215d44e40b8463 Mon Sep 17 00:00:00 2001 From: Koda Date: Sun, 9 Oct 2016 07:39:49 +0900 Subject: [PATCH] Fix markdown display process --- src/main/webapp/js/knowledge-common.js | 55 +++++++++++++------ src/main/webapp/js/knowledge-view-markdown.js | 3 + 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/src/main/webapp/js/knowledge-common.js b/src/main/webapp/js/knowledge-common.js index c0fc4002b..b81a4e55d 100644 --- a/src/main/webapp/js/knowledge-common.js +++ b/src/main/webapp/js/knowledge-common.js @@ -31,7 +31,6 @@ var codeHighlight = function(block) { var jqobj = $(this); highlightPromises.push(new Promise(function(resolve, reject) { try { -// jqobj.addClass('hljs'); jqobj.addClass('stylus'); var text = jqobj.text(); if (text.indexOf('://') != -1) { @@ -93,29 +92,53 @@ var processLink = function(parent) { }); }; + + +/** + * 1つのブロックの装飾処理 + * @return Promise + */ +var decoration = function(jqObj) { + console.log(jqObj); + return new Promise(function(resolve, reject) { + return codeHighlight(jqObj) + .then(function() { + var content = emoji(jqObj.html().trim(), _CONTEXT + '/bower/emoji-parser/emoji', {classes: 'emoji-img'}); + jqObj.html(content); + return Promise.resolve(); + }).then(function () { + jqObj.find('a.oembed').oembed(); + return Promise.resolve(); + }).then(function () { + // call slide.js + showSlide(jqObj); + return Promise.resolve(); + }).then(function () { + // call parse internal link + return processLink(jqObj); + }).then(function () { + return resolve(); + }).catch(function(err) { + console.error(err); + return reject(err); + }); + }); +}; + /** * 装飾処理 * @return Promise */ var processDecoration = function(target) { - var jqObj = target; if (isString(target)) { - jqObj = $(target); + target = $(target); } -// jqObj.find('code').addClass('hljs'); - return codeHighlight(jqObj) - .then(function() { - var content = emoji(jqObj.html().trim(), _CONTEXT + '/bower/emoji-parser/emoji', {classes: 'emoji-img'}); - jqObj.html(content); - }).then(function () { - jqObj.find('a.oembed').oembed(); - // call slide.js - showSlide(jqObj); - // call parse internal link - processLink(jqObj); - }).catch(function(err) { - console.error(err); + var promises = []; + target.each(function(index, element){ + var jqObj = $(element); + promises.push(decoration(jqObj)); }); + return Promise.all(promises); }; var doPreview = function(titleId, contentId, previewAreaId, titleAreaId) { diff --git a/src/main/webapp/js/knowledge-view-markdown.js b/src/main/webapp/js/knowledge-view-markdown.js index 346bfe06c..93d7491c1 100644 --- a/src/main/webapp/js/knowledge-view-markdown.js +++ b/src/main/webapp/js/knowledge-view-markdown.js @@ -1,3 +1,6 @@ $(document).ready(function() { processDecoration('#content'); + processDecoration('.arrow_answer'); + processDecoration('.arrow_question'); }); +