jekyll-kroki 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.devcontainer/devcontainer.json +4 -0
- data/.rubocop.yml +1 -1
- data/.vscode/settings.json +7 -0
- data/README.md +10 -7
- data/jekyll-kroki.gemspec +3 -2
- data/lib/jekyll/kroki/version.rb +1 -1
- data/lib/jekyll/kroki.rb +36 -14
- metadata +21 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f353846f7017642be1207c60d318604e0f9c0ee211aee558efe6dc7f4bfbff4
|
4
|
+
data.tar.gz: d65f5ac400887790313a64244d528169238df4820d5828eccc5adf94d06efb46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c0a8a1ad9834f230721440ec19ba2bc9d847ee7f4509e99ddc780a108ffe8fd8d3ccf45182242c88eb088445a92de5dc3a9ebc754466b56b928bb485d65755b
|
7
|
+
data.tar.gz: 8131425affe90d14a5df9f61cf9806b66311f90a5827284e2b191c057c503031b69f58c1bd655ff367695ef59ff2df156439792067b461b0be3446638d892767
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
![Main Workflow](https://github.com/felixvanoost/jekyll-kroki/actions/workflows/main.yml/badge.svg)
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/jekyll-kroki.svg)](https://badge.fury.io/rb/jekyll-kroki)
|
3
|
+
|
1
4
|
# jekyll-kroki
|
2
|
-
A Jekyll plugin to convert diagram descriptions into images using Kroki
|
5
|
+
A [Jekyll](https://jekyllrb.com/) plugin to convert diagram descriptions into images using [Kroki](https://kroki.io/).
|
3
6
|
|
4
7
|
## Installation
|
5
8
|
|
@@ -13,9 +16,9 @@ end
|
|
13
16
|
|
14
17
|
## Usage
|
15
18
|
|
16
|
-
|
19
|
+
Kroki supports over 25 popular diagram scripting languages, including Blockdiag, D2, GraphViz, Mermaid, and PlantUML. The [examples](https://kroki.io/examples.html) page and complete list of [supported diagram languages](https://kroki.io/#support) provide a taste of what's possible.
|
17
20
|
|
18
|
-
In Markdown, simply write your diagram
|
21
|
+
In Markdown, simply write your diagram descriptions inside a fenced code block with the language specified:
|
19
22
|
|
20
23
|
````
|
21
24
|
```plantuml
|
@@ -27,13 +30,13 @@ Kroki --> Jekyll: Rendered diagram in SVG format
|
|
27
30
|
```
|
28
31
|
````
|
29
32
|
|
30
|
-
When Jekyll builds your site, the `jekyll-kroki` plugin will encode the
|
33
|
+
When Jekyll builds your site, the `jekyll-kroki` plugin will encode the diagrams, send them to the Kroki server for rendering, then replace the diagram descriptions in the generated HTML with the rendered images in SVG format:
|
31
34
|
|
32
35
|
![sample-diagram](https://github.com/felixvanoost/jekyll-kroki/assets/10233016/244d2ec4-b09b-4a5f-8164-3851574c3dd2)
|
33
36
|
|
34
|
-
The site remains truly static as the
|
37
|
+
The site remains truly static as the images are 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
38
|
|
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.
|
39
|
+
`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 as images in both the GitLab UI and on GitLab Pages sites generated using Jekyll.
|
37
40
|
|
38
41
|
### Configuration
|
39
42
|
|
@@ -44,7 +47,7 @@ kroki:
|
|
44
47
|
url: "https://my-kroki.server"
|
45
48
|
```
|
46
49
|
|
47
|
-
This is useful if you want to run a Kroki instance locally or your organisation maintains its own private Kroki server.
|
50
|
+
This is useful if you want to run a Kroki instance locally or your organisation maintains its own private Kroki server. The public Kroki instance https://kroki.io is used by default.
|
48
51
|
|
49
52
|
### Security
|
50
53
|
|
data/jekyll-kroki.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ["Felix van Oost"]
|
9
9
|
|
10
10
|
spec.summary = "A Jekyll plugin to convert diagram descriptions into images using Kroki"
|
11
|
-
spec.description = "
|
12
|
-
|
11
|
+
spec.description = "A Jekyll plugin to convert diagram descriptions written in over 25 popular diagram scripting
|
12
|
+
languages into images using Kroki"
|
13
13
|
spec.homepage = "https://github.com/felixvanoost/jekyll-kroki"
|
14
14
|
spec.license = "MIT"
|
15
15
|
spec.required_ruby_version = ">= 2.6.0"
|
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
|
31
31
|
spec.add_runtime_dependency "faraday", ["~> 2.7"]
|
32
32
|
spec.add_runtime_dependency "faraday-retry", ["~> 2.2"]
|
33
|
+
spec.add_runtime_dependency "httpx", ["~> 1.1"]
|
33
34
|
spec.add_runtime_dependency "jekyll", ["~> 4"]
|
34
35
|
spec.add_runtime_dependency "nokogiri", ["~> 1.15"]
|
35
36
|
|
data/lib/jekyll/kroki/version.rb
CHANGED
data/lib/jekyll/kroki.rb
CHANGED
@@ -5,6 +5,7 @@ require_relative "kroki/version"
|
|
5
5
|
require "base64"
|
6
6
|
require "faraday"
|
7
7
|
require "faraday/retry"
|
8
|
+
require "httpx/adapters/faraday"
|
8
9
|
require "jekyll"
|
9
10
|
require "nokogiri"
|
10
11
|
require "zlib"
|
@@ -24,27 +25,29 @@ module Jekyll
|
|
24
25
|
kroki_url = kroki_url(site.config)
|
25
26
|
puts "[jekyll-kroki] Rendering diagrams using Kroki instance at '#{kroki_url}'"
|
26
27
|
|
27
|
-
# Set up a Faraday connection
|
28
28
|
connection = setup_connection(kroki_url)
|
29
|
+
supported_languages = get_supported_languages(connection)
|
29
30
|
|
30
|
-
# Parse the page, render and embed the diagrams, then convert it back into HTML
|
31
31
|
site.pages.each do |page|
|
32
32
|
next unless embeddable?(page)
|
33
33
|
|
34
|
+
# Parse the page, render and embed the diagrams, then convert it back into HTML
|
34
35
|
parsed_page = Nokogiri::HTML(page.output)
|
35
|
-
embed_page(connection, parsed_page)
|
36
|
+
embed_page(connection, supported_languages, parsed_page)
|
36
37
|
page.output = parsed_page.to_html
|
37
38
|
end
|
39
|
+
rescue StandardError => e
|
40
|
+
exit(e)
|
38
41
|
end
|
39
42
|
|
40
43
|
# Renders all diagram descriptions in any Kroki-supported language and embeds them in an HTML document.
|
41
44
|
#
|
42
45
|
# @param [Faraday::Connection] The Faraday connection to use
|
46
|
+
# @param [Array] The supported diagram languages
|
43
47
|
# @param [Nokogiri::HTML4::Document] The parsed HTML document
|
44
|
-
def embed_page(connection,
|
45
|
-
|
46
|
-
|
47
|
-
parsed_doc.css("code[class~='language-#{language}']").each do |diagram_desc|
|
48
|
+
def embed_page(connection, supported_languages, parsed_page)
|
49
|
+
supported_languages.each do |language|
|
50
|
+
parsed_page.css("code[class~='language-#{language}']").each do |diagram_desc|
|
48
51
|
# Replace the diagram description with the SVG representation rendered by Kroki
|
49
52
|
diagram_desc.replace(render_diagram(connection, diagram_desc, language))
|
50
53
|
end
|
@@ -102,12 +105,13 @@ module Jekyll
|
|
102
105
|
# @param [Faraday::Connection] The Faraday connection to use
|
103
106
|
# @return [Array] The supported diagram languages
|
104
107
|
def get_supported_languages(connection)
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
108
|
+
response = connection.get("health")
|
109
|
+
supported_languages = response.body["version"]&.keys
|
110
|
+
raise "'#{connection.url_prefix}' does not point to a valid Kroki instance" if supported_languages.nil?
|
111
|
+
|
112
|
+
supported_languages
|
113
|
+
rescue Faraday::Error => e
|
114
|
+
raise e
|
111
115
|
end
|
112
116
|
|
113
117
|
# Sets up a new Faraday connection.
|
@@ -118,7 +122,8 @@ module Jekyll
|
|
118
122
|
retry_options = { max: HTTP_MAX_RETRIES, interval: 0.1, interval_randomness: 0.5, backoff_factor: 2,
|
119
123
|
exceptions: [Faraday::RequestTimeoutError, Faraday::ServerError] }
|
120
124
|
|
121
|
-
Faraday.new(url: kroki_url) do |builder|
|
125
|
+
Faraday.new(url: kroki_url, request: { timeout: 5 }) do |builder|
|
126
|
+
builder.adapter :httpx, persistent: true
|
122
127
|
builder.request :retry, retry_options
|
123
128
|
builder.response :json, content_type: /\bjson$/
|
124
129
|
builder.response :raise_error
|
@@ -147,6 +152,23 @@ module Jekyll
|
|
147
152
|
def embeddable?(doc)
|
148
153
|
doc.output_ext == ".html" && (doc.is_a?(Jekyll::Page) || doc.write?)
|
149
154
|
end
|
155
|
+
|
156
|
+
# Exits the Jekyll process without returning a stack trace. This method does not return because the process is
|
157
|
+
# abruptly terminated.
|
158
|
+
#
|
159
|
+
# @param [StandardError] The error to display in the termination message
|
160
|
+
# @param [int] The caller index to display in the termination message. The default index is 1, which means the
|
161
|
+
# calling method. To specify the calling method's caller, pass in 2.
|
162
|
+
#
|
163
|
+
# Source: https://www.mslinn.com/ruby/2200-crash-exit.html
|
164
|
+
def exit(error, caller_index = 1)
|
165
|
+
raise error
|
166
|
+
rescue StandardError => e
|
167
|
+
file, line_number, caller = e.backtrace[caller_index].split(":")
|
168
|
+
caller = caller.tr("`", "'")
|
169
|
+
warn %([jekyll-kroki] "#{error.message}" #{caller} on line #{line_number} of #{file}).red
|
170
|
+
exec "echo ''"
|
171
|
+
end
|
150
172
|
end
|
151
173
|
end
|
152
174
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-kroki
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Felix van Oost
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '2.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: httpx
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.1'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: jekyll
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,14 +123,16 @@ dependencies:
|
|
109
123
|
- !ruby/object:Gem::Version
|
110
124
|
version: '1.21'
|
111
125
|
description: |-
|
112
|
-
|
113
|
-
|
126
|
+
A Jekyll plugin to convert diagram descriptions written in over 25 popular diagram scripting
|
127
|
+
languages into images using Kroki
|
114
128
|
email:
|
115
129
|
executables: []
|
116
130
|
extensions: []
|
117
131
|
extra_rdoc_files: []
|
118
132
|
files:
|
133
|
+
- ".devcontainer/devcontainer.json"
|
119
134
|
- ".rubocop.yml"
|
135
|
+
- ".vscode/settings.json"
|
120
136
|
- LICENSE
|
121
137
|
- README.md
|
122
138
|
- Rakefile
|
@@ -144,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
160
|
- !ruby/object:Gem::Version
|
145
161
|
version: '0'
|
146
162
|
requirements: []
|
147
|
-
rubygems_version: 3.
|
163
|
+
rubygems_version: 3.2.33
|
148
164
|
signing_key:
|
149
165
|
specification_version: 4
|
150
166
|
summary: A Jekyll plugin to convert diagram descriptions into images using Kroki
|