Compare commits

..

No commits in common. "master" and "v0.9.1" have entirely different histories.

9 changed files with 60 additions and 177 deletions

3
.rspec
View File

@ -1,3 +0,0 @@
--color
--format progress
--require spec_helper

View File

@ -146,7 +146,7 @@ plugins:
**💡 Tip:** Note that GitHub Pages runs in `safe` mode and only allows [a set of whitelisted plugins](https://pages.github.com/versions/). To use the gem in GitHub Pages, you need to build locally or use CI (e.g. [travis](https://travis-ci.org/), [github workflow](https://help.github.com/en/actions/configuring-and-managing-workflows/configuring-a-workflow)) and deploy to your `gh-pages` branch.
### Additions for Unlimited GitHub Pages
### Additions
* Here is a GitHub Action named [jekyll-deploy-action](https://github.com/jeffreytse/jekyll-deploy-action) for Jekyll site deployment conveniently. 👍
* Here is a [Jekyll site](https://github.com/jeffreytse/jekyll-jeffreytse-blog) using Travis to build and deploy to GitHub Pages for your references.
@ -186,7 +186,7 @@ jekyll-spaceship:
syntax:
code: 'plantuml!'
custom: ['@startuml', '@enduml']
src: http://www.plantuml.com/plantuml/svg/
src: http://www.plantuml.com/plantuml/png/
mermaid-processor:
mode: default # mode value 'pre-fetch' for fetching image at building stage
css:
@ -637,7 +637,7 @@ Code above would be parsed as:
### 3. PlantUML Usage
[PlantUML](https://plantuml.com) is a component that allows to quickly write:
[PlantUML](http://plantuml.sourceforge.net/) is a component that allows to quickly write:
- sequence diagram,
- use case diagram,
@ -966,7 +966,7 @@ Automatically adds a `target="_blank" rel="noopener noreferrer"` attribute to al
jekyll-spaceship:
element-processor:
css:
- a: # Replace all `a` tags
- a: # Replce all `a` tags
props:
class: ['(^.*$)', '\0 ext-link'] # Add `ext-link` to class by regex pattern
target: _blank # Replace `target` value to `_blank`
@ -982,7 +982,7 @@ Automatically adds `loading="lazy"` to `img` and `iframe` tags to natively load
jekyll-spaceship:
element-processor:
css:
- a: # Replace all `a` tags
- a: # Replce all `a` tags
props: #
loading: lazy # Replace `loading` value to `lazy`
```
@ -997,7 +997,7 @@ See the following examples to prevent lazy loading.
jekyll-spaceship:
element-processor:
css:
- a: # Replace all `a` tags
- a: # Replce all `a` tags
props: #
loading: eager # Replace `loading` value to `eager`
```

View File

@ -116,7 +116,7 @@ module Jekyll::Spaceship
if self.respond_to? method
@page.content = self.pre_exclude @page.content
@page.content = self.send method, @page.content
@page.content = self.post_exclude @page.content
@page.content = self.after_exclude @page.content
end
else
if Type.html? output_ext
@ -151,8 +151,8 @@ module Jekyll::Spaceship
logger.log file
end
def exclusion_regexs()
regexs = []
def pre_exclude(content)
@exclusion_store = []
@exclusions.each do |type|
regex = nil
if type == :code
@ -162,14 +162,7 @@ module Jekyll::Spaceship
elsif type == :liquid_filter
regex = /((?<!\\)((\{\{[^\n]*?\}\})|(\{%[^\n]*?%\})))/
end
regexs.push regex unless regex.nil?
end
regexs
end
def pre_exclude(content, regexs = self.exclusion_regexs())
@exclusion_store = []
regexs.each do |regex|
next if regex.nil?
content.scan(regex) do |match_data|
match = match_data[0]
id = @exclusion_store.size
@ -180,7 +173,7 @@ module Jekyll::Spaceship
content
end
def post_exclude(content)
def after_exclude(content)
while @exclusion_store.size > 0
match = @exclusion_store.pop
id = @exclusion_store.size
@ -199,38 +192,5 @@ module Jekyll::Spaceship
end
content
end
def self.fetch_img_data(url)
begin
res = Net::HTTP.get_response URI(url)
raise res.body unless res.is_a?(Net::HTTPSuccess)
content_type = res.header['Content-Type']
raise 'Unknown content type!' if content_type.nil?
content_body = res.body.force_encoding('UTF-8')
return {
'type' => content_type,
'body' => content_body
}
rescue StandardError => msg
logger.log msg
end
end
def self.make_img_tag(data)
css_class = data['class']
type = data['type']
body = data['body']
if type == 'url'
"<img class=\"#{css_class}\" src=\"#{body}\">"
elsif type.include?('svg')
body.gsub(/\<\?xml.*?\?>/, '')
.gsub(/<!--[^\0]*?-->/, '')
.sub(/<svg /, "<svg class=\"#{css_class}\" ")
else
body = Base64.encode64(body)
body = "data:#{type};base64, #{body}"
"<img class=\"#{css_class}\" src=\"#{body}\">"
end
end
end
end

View File

@ -62,20 +62,18 @@ module Jekyll::Spaceship
def handle_mermaid(code)
# encode to UTF-8
code = code.encode('UTF-8')
url = get_url(code)
# render mode
case self.config['mode']
when 'pre-fetch'
data = self.class.fetch_img_data(url)
end
if data.nil?
data = { 'type' => 'url', 'body' => url }
url = self.get_mermaid_img_data(url)
end
# return img tag
data['class'] = self.config['css']['class']
self.class.make_img_tag(data)
css_class = self.config['css']['class']
"<img class=\"#{css_class}\" src=\"#{url}\">"
end
def get_url(code)
@ -98,5 +96,21 @@ module Jekyll::Spaceship
raise "No supported src ! #{src}"
end
end
def get_mermaid_img_data(url)
data = ''
begin
res = Net::HTTP.get_response URI(url)
raise res.body unless res.is_a?(Net::HTTPSuccess)
data = Base64.encode64(res.body)
content_type = res.header['Content-Type']
raise 'Unknown content type!' if content_type.nil?
data = "data:#{content_type};base64, #{data}"
rescue StandardError => msg
data = url
logger.log msg
end
data
end
end
end

View File

@ -17,7 +17,7 @@ module Jekyll::Spaceship
'css' => {
'class' => 'plantuml'
},
'src' => 'http://www.plantuml.com/plantuml/svg/'
'src' => 'http://www.plantuml.com/plantuml/png/'
}
end
@ -59,20 +59,18 @@ module Jekyll::Spaceship
def handle_plantuml(code)
# wrap plantuml code
code = "@startuml#{code}@enduml".encode('UTF-8')
url = self.get_url(code)
url = get_url(code)
# render mode
case self.config['mode']
when 'pre-fetch'
data = self.class.fetch_img_data(url)
end
if data.nil?
data = { 'type' => 'url', 'body' => url }
url = self.get_plantuml_img_data(url)
end
# return img tag
data['class'] = self.config['css']['class']
self.class.make_img_tag(data)
css_class = self.config['css']['class']
"<img class=\"#{css_class}\" src=\"#{url}\">"
end
def get_url(code)
@ -89,5 +87,21 @@ module Jekyll::Spaceship
raise "No supported src ! #{src}"
end
end
def get_plantuml_img_data(url)
data = ''
begin
res = Net::HTTP.get_response URI(url)
raise res.body unless res.is_a?(Net::HTTPSuccess)
data = Base64.encode64(res.body)
content_type = res.header['Content-Type']
raise 'Unknown content type!' if content_type.nil?
data = "data:#{content_type};base64, #{data}"
rescue StandardError => msg
data = url
logger.log msg
end
data
end
end
end

View File

@ -305,12 +305,10 @@ module Jekyll::Spaceship
cvter = self.converter('markdown')
return if cvter.nil?
content = cell.inner_html
content = self.pre_exclude(content, [/(\<code.*\>.*\<\/code\>)/])
.gsub(/(?<!\\)\|/, '\\|')
.gsub(/^\s+|\s+$/, '')
.gsub(/&lt;/, '<')
.gsub(/&gt;/, '>')
content = self.post_exclude(content)
content = cvter.convert(content)
content = Nokogiri::HTML.fragment(content)
if content.children.first&.name == 'p'

View File

@ -2,6 +2,6 @@
module Jekyll
module Spaceship
VERSION = "0.9.3"
VERSION = "0.9.1"
end
end

View File

@ -1,100 +0,0 @@
# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause
# this file to always be loaded, without a need to explicitly require it in any
# files.
#
# Given that it is always loaded, you are encouraged to keep this file as
# light-weight as possible. Requiring heavyweight dependencies from this file
# will add to the boot time of your test suite on EVERY test run, even for an
# individual file that may not need all of that loaded. Instead, consider making
# a separate helper file that requires the additional dependencies and performs
# the additional setup, and require it from the spec files that actually need
# it.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.
config.expect_with :rspec do |expectations|
# This option will default to `true` in RSpec 4. It makes the `description`
# and `failure_message` of custom matchers include text for helper methods
# defined using `chain`, e.g.:
# be_bigger_than(2).and_smaller_than(4).description
# # => "be bigger than 2 and smaller than 4"
# ...rather than:
# # => "be bigger than 2"
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
# rspec-mocks config goes here. You can use an alternate test double
# library (such as bogus or mocha) by changing the `mock_with` option here.
config.mock_with :rspec do |mocks|
# Prevents you from mocking or stubbing a method that does not exist on
# a real object. This is generally recommended, and will default to
# `true` in RSpec 4.
mocks.verify_partial_doubles = true
end
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
# have no way to turn it off -- the option exists only for backwards
# compatibility in RSpec 3). It causes shared context metadata to be
# inherited by the metadata hash of host groups and examples, rather than
# triggering implicit auto-inclusion in groups with matching metadata.
config.shared_context_metadata_behavior = :apply_to_host_groups
# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
=begin
# This allows you to limit a spec run to individual examples or groups
# you care about by tagging them with `:focus` metadata. When nothing
# is tagged with `:focus`, all examples get run. RSpec also provides
# aliases for `it`, `describe`, and `context` that include `:focus`
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
config.filter_run_when_matching :focus
# Allows RSpec to persist some state between runs in order to support
# the `--only-failures` and `--next-failure` CLI options. We recommend
# you configure your source control system to ignore this file.
config.example_status_persistence_file_path = "spec/examples.txt"
# Limits the available syntax to the non-monkey patched syntax that is
# recommended. For more details, see:
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
config.disable_monkey_patching!
# This setting enables warnings. It's recommended, but in some cases may
# be too noisy due to issues in dependencies.
config.warnings = true
# Many RSpec users commonly either run the entire suite or an individual
# file, and it's useful to allow more verbose output when running an
# individual spec file.
if config.files_to_run.one?
# Use the documentation formatter for detailed output,
# unless a formatter has already been configured
# (e.g. via a command-line flag).
config.default_formatter = "doc"
end
# Print the 10 slowest examples and example groups at the
# end of the spec run, to help surface which specs are running
# particularly slow.
config.profile_examples = 10
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = :random
# Seed global randomization in this process using the `--seed` CLI option.
# Setting this allows you to use `--seed` to deterministically reproduce
# test failures related to randomization by passing the same `--seed` value
# as the one that triggered the failure.
Kernel.srand config.seed
=end
end