jekyll-kroki 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +13 -0
- data/.rubocop_todo.yml +37 -0
- data/LICENSE +21 -0
- data/README.md +40 -0
- data/Rakefile +16 -0
- data/jekyll-kroki.gemspec +37 -0
- data/lib/jekyll/kroki/version.rb +7 -0
- data/lib/jekyll/kroki.rb +103 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 20faf867e0d7257dc109beb7013daffedbed2d90642e3b483d1be42a62220008
|
4
|
+
data.tar.gz: b248eeb60615d9343256b79b1524abe5253c5b02c2f1fa01741f3f2d914cef62
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1aa3042410e6a16d5bc1e5519a3f7e1043611d22d404ed7856c943eba4a29dd36d5bab5f0a2a732c9cce77231927855bf464211d7a1ddfe58c54b4e3ed02a448
|
7
|
+
data.tar.gz: e2b86eed2875b0d846955222023102cbd215bbeebe68247debff8f56af2cbe328c28d60c974e9b321927178e09361758172553dcc863404068eaabb574a822a3
|
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2023-10-18 03:15:03 UTC using RuboCop version 1.57.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 4
|
10
|
+
Lint/ShadowedException:
|
11
|
+
Exclude:
|
12
|
+
- 'lib/jekyll-kroki.rb'
|
13
|
+
- 'site/_plugins/jekyll-kroki.rb'
|
14
|
+
|
15
|
+
# Offense count: 2
|
16
|
+
Naming/AccessorMethodName:
|
17
|
+
Exclude:
|
18
|
+
- 'lib/jekyll-kroki.rb'
|
19
|
+
- 'site/_plugins/jekyll-kroki.rb'
|
20
|
+
|
21
|
+
# Offense count: 2
|
22
|
+
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.
|
23
|
+
# CheckDefinitionPathHierarchyRoots: lib, spec, test, src
|
24
|
+
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
|
25
|
+
Naming/FileName:
|
26
|
+
Exclude:
|
27
|
+
- 'lib/jekyll-kroki.rb'
|
28
|
+
- 'site/_plugins/jekyll-kroki.rb'
|
29
|
+
|
30
|
+
# Offense count: 2
|
31
|
+
# Configuration parameters: AllowedConstants.
|
32
|
+
Style/Documentation:
|
33
|
+
Exclude:
|
34
|
+
- 'spec/**/*'
|
35
|
+
- 'test/**/*'
|
36
|
+
- 'lib/jekyll-kroki.rb'
|
37
|
+
- 'site/_plugins/jekyll-kroki.rb'
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 Felix van Oost
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# jekyll-kroki
|
2
|
+
A Jekyll plugin to convert diagram descriptions into images using Kroki
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add the `jekyll-kroki` Gem to the `:jekyll_plugins` group of your site's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
group :jekyll_plugins do
|
10
|
+
gem "jekyll-kroki"
|
11
|
+
end
|
12
|
+
```
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
[Kroki](https://github.com/yuzutech/kroki) supports over 20 popular diagram languages spanning several dozen diagram types. The [examples](https://kroki.io/examples.html) page provides a taste of what's possible.
|
17
|
+
|
18
|
+
In Markdown, simply write your diagram description inside a fenced code block with the language specified:
|
19
|
+
|
20
|
+
````
|
21
|
+
```plantuml
|
22
|
+
participant Jekyll
|
23
|
+
participant Kroki #MediumSpringGreen
|
24
|
+
|
25
|
+
Jekyll -> Kroki: Encoded diagram description
|
26
|
+
Kroki --> Jekyll: Rendered diagram in SVG format
|
27
|
+
```
|
28
|
+
````
|
29
|
+
|
30
|
+
When Jekyll builds your site, the `jekyll-kroki` plugin will encode the diagram, send it to the Kroki server for rendering, then replace the diagram description in the generated HTML with the rendered diagram in SVG format:
|
31
|
+
|
32
|
+
![sample-diagram](https://github.com/felixvanoost/jekyll-kroki/assets/10233016/e526864f-c364-49a0-9cca-929a59343af0)
|
33
|
+
|
34
|
+
The site remains truly static as the SVG is directly embedded in the HTML files that Jekyll serves. Jekyll only depends on the Kroki server (which can also be run locally) during the build stage, and all of the client-side processing that is normally used to render diagrams into images is eliminated.
|
35
|
+
|
36
|
+
`jekyll-kroki` uses the same Markdown fenced code syntax as the [GitLab Kroki integration](https://docs.gitlab.com/ee/administration/integration/kroki.html), allowing diagram descriptions in Markdown files to be displayed seamlessly in both the GitLab UI and on GitLab Pages sites generated using Jekyll.
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
Bug reports and pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
10
|
+
end
|
11
|
+
|
12
|
+
require "rubocop/rake_task"
|
13
|
+
|
14
|
+
RuboCop::RakeTask.new
|
15
|
+
|
16
|
+
task default: %i[test rubocop]
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/jekyll/kroki/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "jekyll-kroki"
|
7
|
+
spec.version = Jekyll::Kroki::VERSION
|
8
|
+
spec.authors = ["Felix van Oost"]
|
9
|
+
|
10
|
+
spec.summary = "A Jekyll plugin to convert diagram descriptions into images using Kroki"
|
11
|
+
spec.description = "Replaces diagram descriptions written in any Kroki-supported language in HTML files with their
|
12
|
+
visual representation in SVG format"
|
13
|
+
spec.homepage = "https://github.com/felixvanoost/jekyll-kroki"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.6.0"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
19
|
+
|
20
|
+
# Load the files that are versioned in Git into the RubyGem.
|
21
|
+
spec.files = Dir.chdir(__dir__) do
|
22
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
23
|
+
(File.expand_path(f) == __FILE__) ||
|
24
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_runtime_dependency "jekyll", ["~> 4"]
|
32
|
+
spec.add_runtime_dependency "nokogiri", ["~> 1.15"]
|
33
|
+
|
34
|
+
spec.add_development_dependency "minitest", ["~> 5.0"]
|
35
|
+
spec.add_development_dependency "rake", ["~> 13.0"]
|
36
|
+
spec.add_development_dependency "rubocop", ["~> 1.21"]
|
37
|
+
end
|
data/lib/jekyll/kroki.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "kroki/version"
|
4
|
+
|
5
|
+
require "base64"
|
6
|
+
require "jekyll"
|
7
|
+
require "json"
|
8
|
+
require "net/http"
|
9
|
+
require "nokogiri"
|
10
|
+
require "zlib"
|
11
|
+
|
12
|
+
module Jekyll
|
13
|
+
# Jekyll plugin for the Kroki diagram engine
|
14
|
+
class Kroki
|
15
|
+
KROKI_INSTANCE_URL = "https://kroki.io"
|
16
|
+
|
17
|
+
class << self
|
18
|
+
# Renders all diagram descriptions written in a Kroki-supported language in an HTML document.
|
19
|
+
#
|
20
|
+
# @param [Jekyll::Page or Jekyll::Document] The document to render diagrams in
|
21
|
+
def render(doc)
|
22
|
+
puts "Rendering diagrams using Kroki"
|
23
|
+
|
24
|
+
# Parse the HTML document
|
25
|
+
parsed_doc = Nokogiri::HTML.parse(doc.output)
|
26
|
+
|
27
|
+
# Iterate through every diagram description in each of the supported languages
|
28
|
+
get_supported_languages(KROKI_INSTANCE_URL).each do |language|
|
29
|
+
parsed_doc.css("code[class~='language-#{language}']").each do |diagram_desc|
|
30
|
+
# Get the rendered diagram using Kroki
|
31
|
+
rendered_diagram = render_diagram(KROKI_INSTANCE_URL, diagram_desc, language)
|
32
|
+
|
33
|
+
# Replace the diagram description with the SVG representation
|
34
|
+
diagram_desc.replace(rendered_diagram)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Generate the modified HTML document
|
39
|
+
doc.output = parsed_doc.to_html
|
40
|
+
end
|
41
|
+
|
42
|
+
# Renders a diagram description using Kroki.
|
43
|
+
#
|
44
|
+
# @param [String] The URL of the Kroki instance
|
45
|
+
# @param [String] The diagram description
|
46
|
+
# @param [String] The language of the diagram description
|
47
|
+
# @return [String] The rendered diagram in SVG format
|
48
|
+
def render_diagram(kroki_url, diagram_desc, language)
|
49
|
+
# Encode the diagram and construct the URI
|
50
|
+
uri = URI("#{kroki_url}/#{language}/svg/#{encode_diagram(diagram_desc.text)}")
|
51
|
+
|
52
|
+
begin
|
53
|
+
response = Net::HTTP.get_response(uri)
|
54
|
+
rescue StandardError => e
|
55
|
+
raise e.message
|
56
|
+
else
|
57
|
+
response.body if response.is_a?(Net::HTTPSuccess)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Encodes the diagram into Kroki format using deflate + base64.
|
62
|
+
# See https://docs.kroki.io/kroki/setup/encode-diagram/.
|
63
|
+
#
|
64
|
+
# @param [String, #read] The diagram to encode
|
65
|
+
# @return [String] The encoded diagram
|
66
|
+
def encode_diagram(diagram)
|
67
|
+
Base64.urlsafe_encode64(Zlib.deflate(diagram))
|
68
|
+
end
|
69
|
+
|
70
|
+
# Gets an array of supported diagram languages from the Kroki '/health' endpoint.
|
71
|
+
#
|
72
|
+
# This only shows which languages the Kroki project supports, not which ones are currently available from the
|
73
|
+
# configured Kroki instance. For example, Mermaid will still show up as a supported language even if the Mermaid
|
74
|
+
# companion container is not running.
|
75
|
+
#
|
76
|
+
# @param [String] The URL of the Kroki instance
|
77
|
+
# @return [Array] The supported diagram languages
|
78
|
+
def get_supported_languages(kroki_url)
|
79
|
+
uri = URI("#{kroki_url}/health")
|
80
|
+
|
81
|
+
begin
|
82
|
+
response = Net::HTTP.get_response(uri)
|
83
|
+
rescue StandardError => e
|
84
|
+
raise e.message
|
85
|
+
else
|
86
|
+
JSON.parse(response.body)["version"].keys if response.is_a?(Net::HTTPSuccess)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# Determines whether a document may contain renderable diagram descriptions - it is in HTML format and is either
|
91
|
+
# a Jekyll::Page or writeable Jekyll::Document.
|
92
|
+
#
|
93
|
+
# @param [Jekyll::Page or Jekyll::Document] The document to check for renderability
|
94
|
+
def renderable?(doc)
|
95
|
+
doc.output_ext == ".html" && (doc.is_a?(Jekyll::Page) || doc.write?)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
Jekyll::Hooks.register [:pages, :documents], :post_render do |doc|
|
102
|
+
Jekyll::Kroki.render(doc) if Jekyll::Kroki.renderable?(doc)
|
103
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-kroki
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Felix van Oost
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-10-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jekyll
|
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'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.15'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.15'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '13.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '13.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.21'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.21'
|
83
|
+
description: |-
|
84
|
+
Replaces diagram descriptions written in any Kroki-supported language in HTML files with their
|
85
|
+
visual representation in SVG format
|
86
|
+
email:
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".rubocop.yml"
|
92
|
+
- ".rubocop_todo.yml"
|
93
|
+
- LICENSE
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- jekyll-kroki.gemspec
|
97
|
+
- lib/jekyll/kroki.rb
|
98
|
+
- lib/jekyll/kroki/version.rb
|
99
|
+
homepage: https://github.com/felixvanoost/jekyll-kroki
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata:
|
103
|
+
homepage_uri: https://github.com/felixvanoost/jekyll-kroki
|
104
|
+
source_code_uri: https://github.com/felixvanoost/jekyll-kroki
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: 2.6.0
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubygems_version: 3.3.5
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: A Jekyll plugin to convert diagram descriptions into images using Kroki
|
124
|
+
test_files: []
|