kramdown-plantuml 1.1.7 → 1.1.11
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 +50 -22
- data/lib/kramdown-plantuml/options.rb +6 -8
- 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: '0307159bac1bde4c2f9d21a19fde7e2c3a474df622f5a0fd54d368d71e7c6884'
|
4
|
+
data.tar.gz: 440a8b11f5398ffc6f73ebf67c9d1eb5e5c91e3fc63fb9a15455033bf413a882
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9a7db962e92eebd1729c3e043d6a6ba0fca49c8365d7eecdacd5120737eda1d0af58c423bdf8cdd7d6101e3421a19c778f9a3fee22148d9948b46f8f0a2d542
|
7
|
+
data.tar.gz: 5fe6ae9a8ffb8941825da89f0bf7f28229631292615938fcd9edd507553148a1feaab272c48fac9509dedffebd70e0cec8a3a6209a5d2ddb74323f575c606b01
|
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,33 +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
|
60
81
|
return html if html.nil? || html.empty? || !html.is_a?(String)
|
61
82
|
|
62
83
|
html.gsub(/<!--#kramdown-plantuml\.start#-->(?<json>.*?)<!--#kramdown-plantuml\.end#-->/m) do
|
63
84
|
json = $LAST_MATCH_INFO[:json]
|
64
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)
|
65
98
|
rescue StandardError => e
|
66
99
|
raise e if options.raise_errors?
|
67
100
|
|
68
|
-
logger.error
|
101
|
+
logger.error 'Error while replacing Jekyll needle.'
|
102
|
+
logger.error e.to_s
|
103
|
+
logger.debug_multiline json
|
69
104
|
end
|
70
105
|
end
|
71
106
|
|
72
|
-
def
|
73
|
-
hash = JSON.parse(json)
|
107
|
+
def decode_and_convert(hash, options)
|
74
108
|
encoded_plantuml = hash['plantuml']
|
75
|
-
plantuml =
|
76
|
-
options = ::Kramdown::PlantUml::Options.new({ plantuml: hash['options'] })
|
109
|
+
plantuml = HTMLEntities.new.decode encoded_plantuml
|
77
110
|
diagram = ::Kramdown::PlantUml::Diagram.new(plantuml, options)
|
78
111
|
diagram.convert_to_svg
|
79
112
|
end
|
80
113
|
|
81
|
-
def decode_html_entities(encoded_plantuml)
|
82
|
-
doc = REXML::Document.new "<plantuml>#{encoded_plantuml}</plantuml>"
|
83
|
-
doc.root.text
|
84
|
-
end
|
85
|
-
|
86
114
|
def load_jekyll
|
87
115
|
require 'jekyll'
|
88
116
|
::Jekyll
|
@@ -10,7 +10,7 @@ module Kramdown
|
|
10
10
|
|
11
11
|
def initialize(options_hash = {})
|
12
12
|
@logger = LogWrapper.init
|
13
|
-
@options = massage(options_hash)
|
13
|
+
@options = massage(options_hash) || {}
|
14
14
|
@raise_errors = extract_raise_errors(@options)
|
15
15
|
extract_theme_options(@options)
|
16
16
|
end
|
@@ -44,9 +44,9 @@ module Kramdown
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def extract_theme_options(options)
|
47
|
-
return if options.empty? || !options.key?(:theme)
|
47
|
+
return if options.nil? || options.empty? || !options.key?(:theme)
|
48
48
|
|
49
|
-
theme = options[:theme]
|
49
|
+
theme = options[:theme]
|
50
50
|
|
51
51
|
unless theme.is_a?(Hash)
|
52
52
|
@logger.warn ":theme is not a Hash: #{theme}"
|
@@ -58,12 +58,10 @@ module Kramdown
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def extract_raise_errors(options)
|
61
|
-
if options.key?(:raise_errors)
|
62
|
-
raise_errors = options[:raise_errors]
|
63
|
-
return boolean(raise_errors, true)
|
64
|
-
end
|
61
|
+
return true if options.nil? || options.empty? || !options.key?(:raise_errors)
|
65
62
|
|
66
|
-
|
63
|
+
raise_errors = options[:raise_errors]
|
64
|
+
boolean(raise_errors, true)
|
67
65
|
end
|
68
66
|
|
69
67
|
def massage(options_hash)
|
@@ -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.11
|
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
|