kramdown-plantuml 1.1.6 → 1.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/kramdown-plantuml.gemspec +1 -0
- data/lib/kramdown-plantuml/jekyll_provider.rb +52 -22
- data/lib/kramdown-plantuml/theme.rb +25 -1
- data/lib/kramdown-plantuml/version.rb +1 -1
- data/lib/kramdown_html.rb +7 -3
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f3079884f4be0aff2684c326ba38d338463bdeb7948fadb809e5291da704e24
|
4
|
+
data.tar.gz: 626333b50918dabde967923545195585060f83198db77df1827fecd12a14308a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54fd75fec2cd706bcdbaeeac660449a4b7c0c406689baa0cb234353607dc03042ddd2da796b427d42d93d1ccbc3dfe8fbd4fb4c97e8b629f68feb30686023c76
|
7
|
+
data.tar.gz: cb3e10de50b8a30d2522982b941003df0fab61d5ef641008d35acfe13d230ead829e729d6293c65159c3d7d645bb33be368a2e443362ef727dac3c58c234f473
|
data/kramdown-plantuml.gemspec
CHANGED
@@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
36
|
spec.require_paths = ['lib']
|
37
37
|
|
38
|
+
spec.add_dependency 'htmlentities', '~> 4'
|
38
39
|
spec.add_dependency 'kramdown', '~> 2.3'
|
39
40
|
spec.add_dependency 'kramdown-parser-gfm', '~> 1.1'
|
40
41
|
spec.add_dependency 'open3', '~> 0.1'
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'json'
|
4
4
|
require 'English'
|
5
|
-
require '
|
5
|
+
require 'htmlentities'
|
6
6
|
require_relative 'log_wrapper'
|
7
7
|
require_relative 'diagram'
|
8
8
|
|
@@ -11,6 +11,8 @@ module Kramdown
|
|
11
11
|
# Provides an instance of Jekyll if available.
|
12
12
|
module JekyllProvider
|
13
13
|
class << self
|
14
|
+
attr_reader :site_destination_dir
|
15
|
+
|
14
16
|
def jekyll
|
15
17
|
return @jekyll if defined? @jekyll
|
16
18
|
|
@@ -20,16 +22,8 @@ module Kramdown
|
|
20
22
|
def install
|
21
23
|
return @installed = false if jekyll.nil?
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
Jekyll::Hooks.register :site, :post_render do |site|
|
26
|
-
logger.debug ':site:post_render triggered.'
|
27
|
-
|
28
|
-
site.pages.each do |page|
|
29
|
-
page.output = replace_needles(page.output)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
25
|
+
find_site_destination_dir
|
26
|
+
register_hook
|
33
27
|
@installed = true
|
34
28
|
end
|
35
29
|
|
@@ -56,31 +50,67 @@ module Kramdown
|
|
56
50
|
|
57
51
|
private
|
58
52
|
|
59
|
-
def
|
53
|
+
def find_site_destination_dir
|
54
|
+
if jekyll.sites.nil? || jekyll.sites.empty?
|
55
|
+
logger.debug 'Jekyll detected, hooking into :site:post_write.'
|
56
|
+
return nil
|
57
|
+
end
|
58
|
+
|
59
|
+
@site_destination_dir = jekyll.sites.first.dest
|
60
|
+
logger.debug "Jekyll detected, hooking into :site:post_write of '#{@site_destination_dir}'."
|
61
|
+
@site_destination_dir
|
62
|
+
end
|
63
|
+
|
64
|
+
def register_hook
|
65
|
+
Jekyll::Hooks.register :site, :post_write do |site|
|
66
|
+
logger.debug ':site:post_write triggered.'
|
67
|
+
|
68
|
+
@site_destination_dir ||= site.dest
|
69
|
+
|
70
|
+
site.pages.each do |page|
|
71
|
+
page.output = replace_needles(page)
|
72
|
+
page.write(@site_destination_dir)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def replace_needles(page)
|
78
|
+
logger.debug "Replacing Jekyll needle in #{page.path}"
|
79
|
+
|
80
|
+
html = page.output
|
81
|
+
return html if html.nil? || html.empty? || !html.is_a?(String)
|
82
|
+
|
60
83
|
html.gsub(/<!--#kramdown-plantuml\.start#-->(?<json>.*?)<!--#kramdown-plantuml\.end#-->/m) do
|
61
84
|
json = $LAST_MATCH_INFO[:json]
|
62
85
|
return replace_needle(json)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def replace_needle(json)
|
90
|
+
logger.debug 'Replacing Jekyll needle.'
|
91
|
+
|
92
|
+
needle_hash = JSON.parse(json)
|
93
|
+
options_hash = needle_hash['options']
|
94
|
+
options = ::Kramdown::PlantUml::Options.new({ plantuml: options_hash })
|
95
|
+
|
96
|
+
begin
|
97
|
+
decode_and_convert(needle_hash, options)
|
63
98
|
rescue StandardError => e
|
64
99
|
raise e if options.raise_errors?
|
65
100
|
|
66
|
-
logger.error
|
101
|
+
logger.error 'Error while replacing Jekyll needle.'
|
102
|
+
logger.error e.to_s
|
103
|
+
logger.debug_multiline json
|
67
104
|
end
|
68
105
|
end
|
69
106
|
|
70
|
-
def
|
71
|
-
hash = JSON.parse(json)
|
107
|
+
def decode_and_convert(hash, options)
|
72
108
|
encoded_plantuml = hash['plantuml']
|
73
|
-
plantuml =
|
74
|
-
options = ::Kramdown::PlantUml::Options.new({ plantuml: hash['options'] })
|
109
|
+
plantuml = HTMLEntities.new.decode encoded_plantuml
|
75
110
|
diagram = ::Kramdown::PlantUml::Diagram.new(plantuml, options)
|
76
111
|
diagram.convert_to_svg
|
77
112
|
end
|
78
113
|
|
79
|
-
def decode_html_entities(encoded_plantuml)
|
80
|
-
doc = REXML::Document.new "<plantuml>#{encoded_plantuml}</plantuml>"
|
81
|
-
doc.root.text
|
82
|
-
end
|
83
|
-
|
84
114
|
def load_jekyll
|
85
115
|
require 'jekyll'
|
86
116
|
::Jekyll
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative 'options'
|
4
4
|
require_relative 'log_wrapper'
|
5
|
+
require_relative 'jekyll_provider'
|
5
6
|
|
6
7
|
module Kramdown
|
7
8
|
module PlantUml
|
@@ -13,9 +14,10 @@ module Kramdown
|
|
13
14
|
raise ArgumentError, 'options cannot be nil' if options.nil?
|
14
15
|
raise ArgumentError, "options must be a '#{Options}'." unless options.is_a?(Options)
|
15
16
|
|
17
|
+
@raise_errors = options.raise_errors?
|
16
18
|
@logger = LogWrapper.init
|
17
19
|
@name = options.theme_name
|
18
|
-
@directory = options.theme_directory
|
20
|
+
@directory = resolve options.theme_directory
|
19
21
|
end
|
20
22
|
|
21
23
|
def apply(plantuml)
|
@@ -34,6 +36,28 @@ module Kramdown
|
|
34
36
|
|
35
37
|
private
|
36
38
|
|
39
|
+
def resolve(directory)
|
40
|
+
jekyll = JekyllProvider
|
41
|
+
|
42
|
+
return directory if directory.nil? || directory.empty? || !jekyll.installed?
|
43
|
+
|
44
|
+
directory = File.absolute_path(directory, jekyll.site_destination_dir)
|
45
|
+
|
46
|
+
log_or_raise "The theme directory '#{directory}' cannot be found" unless Dir.exist?(directory)
|
47
|
+
|
48
|
+
theme_path = File.join(directory, "puml-theme-#{@name}.puml")
|
49
|
+
|
50
|
+
log_or_raise "The theme '#{theme_path}' cannot be found" unless File.exist?(theme_path)
|
51
|
+
|
52
|
+
directory
|
53
|
+
end
|
54
|
+
|
55
|
+
def log_or_raise(message)
|
56
|
+
raise IOError, message if @raise_errors
|
57
|
+
|
58
|
+
logger.warn message
|
59
|
+
end
|
60
|
+
|
37
61
|
def theme(plantuml)
|
38
62
|
startuml = '@startuml'
|
39
63
|
startuml_index = plantuml.index(startuml) + startuml.length
|
data/lib/kramdown_html.rb
CHANGED
@@ -28,7 +28,7 @@ module Kramdown
|
|
28
28
|
options = ::Kramdown::PlantUml::Options.new(@options)
|
29
29
|
return jekyll.needle(element.value, options) if jekyll.installed?
|
30
30
|
|
31
|
-
convert_plantuml(element.value)
|
31
|
+
convert_plantuml(element.value, options)
|
32
32
|
end
|
33
33
|
|
34
34
|
private
|
@@ -37,10 +37,14 @@ module Kramdown
|
|
37
37
|
element.attr['class'] == 'language-plantuml'
|
38
38
|
end
|
39
39
|
|
40
|
-
def convert_plantuml(plantuml)
|
41
|
-
options = ::Kramdown::PlantUml::Options.new(@options)
|
40
|
+
def convert_plantuml(plantuml, options)
|
42
41
|
diagram = ::Kramdown::PlantUml::Diagram.new(plantuml, options)
|
43
42
|
diagram.convert_to_svg
|
43
|
+
rescue StandardError => e
|
44
|
+
raise e if options.raise_errors?
|
45
|
+
|
46
|
+
logger = ::Kramdown::PlantUml::LogWrapper.init
|
47
|
+
logger.error "Error while replacing needle: #{e.inspect}"
|
44
48
|
end
|
45
49
|
end
|
46
50
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kramdown-plantuml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Swedbank Pay
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: htmlentities
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: kramdown
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|