-
Notifications
You must be signed in to change notification settings - Fork 8
/
init.rb
31 lines (28 loc) · 1.09 KB
/
init.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require File.expand_path('lib/mermaid_macro_hook', __dir__)
Redmine::Plugin.register :redmine_mermaid_macro do
name 'Redmine Mermaid Macro plugin'
author 'Taiki IKEGAME'
description 'Add mermaid graphs to your wiki.'
version '1.0.5'
url 'https://github.com/taikii/redmine_mermaid_macro'
author_url 'https://taikii.github.io'
settings :default => { 'mermaid_url' => 'https://cdn.jsdelivr.net/npm/mermaid@9/dist/mermaid.js' },
:partial => 'settings/redmine_mermaid_macro_settings'
Redmine::WikiFormatting::Macros.register do
desc "Add mermaid graphs to your wiki. Example:\n\n" +
"{{mermaid\n" +
"graph TD;\n" +
" A-->B;\n" +
" A-->C;\n" +
" B-->D;\n" +
" C-->D;\n" +
"}}"
macro :mermaid do |obj, args, text|
divid = "mermaid_" + SecureRandom.urlsafe_base64(8)
out = ''.html_safe
out << content_tag(:div, text, id: divid, class: 'mermaid')
out << javascript_tag("if (typeof mermaidInitialized != 'undefined') {mermaid.init(undefined, '#" + divid + "');};")
out
end
end
end