Skip to content

Commit

Permalink
Enable mermaid(Fixes support-project#1103).
Browse files Browse the repository at this point in the history
  • Loading branch information
y-okumura-isp committed Mar 8, 2021
1 parent bee4efe commit f2ff756
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 10 deletions.
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"vue": "2.4.2",
"html2canvas": "0.4.1",
"jspdf": "1.3.2",
"animate.css": "3.5.2"
"animate.css": "3.5.2",
"mermaid": "8.9.0"
},
"devDependencies": {},
"resolutions": {
Expand Down
8 changes: 7 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ gulp.task('min', function() {

gulp.task('copy', ['copy:bootswatch', 'copy:bootswatch2', 'copy:highlightjs', 'copy:font-awesome', 'copy:flag-icon-css',
'copy:html5shiv', 'copy:respond', 'copy:MathJax', 'copy:emoji-parser', 'copy:free-file-icons',
'copy:diff2html', 'copy:jsdiff', 'copy:jspdf', 'copy:pdfthema']);
'copy:diff2html', 'copy:jsdiff', 'copy:jspdf', 'copy:pdfthema', 'copy:mermaid']);

gulp.task('copy:bootswatch', function() {
return gulp.src([
Expand Down Expand Up @@ -125,6 +125,12 @@ gulp.task('copy:pdfthema', function() {
])
.pipe(gulp.dest('target/knowledge/css/presentation-thema'));
});
gulp.task('copy:mermaid', function() {
return gulp.src([
'src/main/webapp/bower/mermaid/**/*'
])
.pipe(gulp.dest('target/knowledge/bower/mermaid'));
});

gulp.task('check', function () {
return gulp.src(['src/main/webapp/js/slide.js'])
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"gulp-eslint": "4.0.0",
"emoji-parser": "0.1.1",
"emoji-images": "0.1.1",
"fs-extra": "*"
"fs-extra": "8.1.0"
},
"devDependencies": {},
"scripts": {
Expand Down
4 changes: 1 addition & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@
<arguments>run emoji</arguments>
</configuration>
</execution>
<!--
<execution>
<id>gulp</id>
<phase>prepare-package</phase>
Expand All @@ -386,7 +385,6 @@
<arguments>default</arguments>
</configuration>
</execution>
-->
</executions>
</plugin>

Expand Down Expand Up @@ -542,4 +540,4 @@
</plugins>
</reporting>

</project>
</project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.support.project.knowledge.logic;

import io.github.gitbucket.markedj.Marked;
import io.github.gitbucket.markedj.Renderer;
import io.github.gitbucket.markedj.Options;

import java.io.IOException;
Expand Down Expand Up @@ -116,7 +117,23 @@ private void markdownToHtmlOnMarkedJ(String markdown, MarkDown result) {
options.setHeaderPrefix("markdown-agenda-");
options.setHeaderIdSequential(true);

String html = Marked.marked(markdown, options);
Renderer renderer =
new Renderer(options) {
@Override
public String code(String code, String lang, boolean escaped){
if(lang.equals("mermaid")) {
StringBuilder sb = new StringBuilder();
sb.append("<div class=\"mermaid\">");
sb.append(code);
sb.append("</div>");
return sb.toString();
} else {
return super.code(code, lang, escaped);
}
};
};

String html = Marked.marked(markdown, options, renderer);
result.setHtml(html);
result.setParsed(true);
result.setMarkdown(markdown);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -769,12 +769,18 @@ Renderer.prototype.code = function(code, lang, escaped) {
+ '\n</code></pre>';
}

if (lang === "mermaid") {
return '<div class="mermaid>"'
+ code
+ '\n</div>';
}

return '<pre><code class="'
+ this.options.langPrefix
+ escape(lang, true)
+ '">'
+ (escaped ? code : escape(code, true))
+ '\n</code></pre>\n';
+ '\n</code></pre>\n' + escape(lang, true);
};

Renderer.prototype.blockquote = function(quote) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ MathJax.Hub.Config({
<script type="text/javascript" src="<%= request.getContextPath() %>/bower/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML,Safe"></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/bower/emoji-parser/main.min.js"></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/bower/jspdf/dist/jspdf.min.js"></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/bower/mermaid/dist/mermaid.min.js"></script>
<script>mermaid.initialize({startOnLoad:true});</script>

<!-- build:js(src/main/webapp) js/page-knowledge-view.js -->
<script type="text/javascript" src="<%= request.getContextPath() %>/bower/bootstrap-tagsinput/dist/bootstrap-tagsinput.min.js"></script>
Expand Down
11 changes: 10 additions & 1 deletion src/main/webapp/WEB-INF/views/open/license/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ $(document).ready(function(){
type: 'GET',
timeout: 10000,
}).done(function(result, textStatus, xhr) {
$('#content').html(marked(result));
var renderer = new marked.Renderer();
renderer.code = function (code, language) {
if(language.match(/^mermaid/)){
return '<div class="mermaid">'+code+'</div>';
}else{
return '<pre><code>' + hljs.highlightAuto(code).value + '</code></pre>';
}
};
$('#content').html(marked(result, { renderer: renderer }));
}).fail(function(xhr, textStatus, error) {
handleErrorResponse(xhr, textStatus, error);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ MathJax.Hub.Config({
<script type="text/javascript" src="<%= request.getContextPath() %>/bower/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML,Safe"></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/bower/emoji-parser/main.min.js"></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/bower/jspdf/dist/jspdf.min.js"></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/bower/mermaid/dist/mermaid.min.js"></script>
<script>mermaid.initialize({startOnLoad:true});</script>

<!-- build:js(src/main/webapp) js/page-knowledge-edit.js -->
<script type="text/javascript" src="<%= request.getContextPath() %>/bower/bootstrap-tagsinput/dist/bootstrap-tagsinput.min.js"></script>
Expand Down
4 changes: 4 additions & 0 deletions src/main/webapp/js/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ $(document).ready(function() {
'#markdownSamplePreview'
).then(function() {
return processMathJax('#sampleMarkdownText');
}).then(function() {
return processMermaid();
});
});

Expand Down Expand Up @@ -66,6 +68,8 @@ var preview = function() {
jqObj.html(html);
processDecoration(target).then(function() {
return processMathJax(target);
}).then(function() {
return processMermaid();
});
});
};
Expand Down
6 changes: 6 additions & 0 deletions src/main/webapp/js/knowledge-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ var processMathJax = function(target) {
});
};

var processMermaid = function(target) {
return new Promise(function(resolve, reject) {
mermaid.init();
return resolve();
});
};

/**
* 内部の別の記事へのリンクを生成
Expand Down
2 changes: 2 additions & 0 deletions src/main/webapp/js/knowledge-emoji-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ $(document).ready(function() {
'#markdownSamplePreview'
).then(function() {
return processMathJax('#sampleMarkdownText');
}).then(function() {
return processMermaid();
});
});
});
Expand Down
5 changes: 5 additions & 0 deletions src/main/webapp/js/knowledge-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ var preview = function() {
'#preview'
).then(function() {
return processMathJax('#preview');
}).then(function() {
return new Promise(function(resolve, reject) {
mermaid.init();
return resolve();
});
}).then(function() {
if ($('input[name=typeId]:checked').val() === '-102') {
// プレゼンテーションのタイプであった場合に、プレゼンテーションを生成する
Expand Down
4 changes: 4 additions & 0 deletions src/main/webapp/js/knowledge-view-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ var preview = function() {
jqObj.html(html);
processDecoration(target).then(function() {
return processMathJax(target);
}).then(function() {
return processMermaid();
});
});
};
Expand Down Expand Up @@ -59,6 +61,8 @@ var previewans = function() {
jqObj.html(html);
processDecoration(target).then(function() {
return processMathJax(target);
}).then(function() {
return processMermaid();
});
});
};
Expand Down
4 changes: 3 additions & 1 deletion src/main/webapp/js/mynotice.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ $(document).ready(function() {
var showNotice = function(notice) {
parseMarkdown(notice.title, notice.message, '#notice_content_area', '#notice_title_area').then(function() {
return processMathJax('#notice_content_area');
}).then(function() {
return processMermaid();
});
if (notice.showNextTime) {
$('#showagain').prop('checked', true);
Expand Down Expand Up @@ -93,4 +95,4 @@ $(document).ready(function() {
});

loadList();
});
});
2 changes: 2 additions & 0 deletions src/main/webapp/js/notice-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ var showNotice = function(idx) {
shown = idx;
parseMarkdown(notice.title, notice.message, '#notice_content_area', '#notice_title_area').then(function() {
return processMathJax('#notice_content_area');
}).then(function() {
return processMermaid();
});
if (notice.showNextTime) {
$('#showagain').prop('checked', true);
Expand Down

0 comments on commit f2ff756

Please sign in to comment.