Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rc0.7.0 #18

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ['2.7', '3.1', '3.2']
ruby: ['3.1', '3.2']
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
steps:
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 0.7.0 - 2023-12-08

* BREAKING: removed support for ruby 2.7. Ruby 3.1 is the minimal
version supported.

* Replaced Redcarpet by Commonmarker, which is closer to the Markdown
engine we use in Klaro Cards itself, and supports code highlighting
natively.

## 0.6.0 - 2023-06-23

* Upgraded dependencies, notably http (5.x)
Expand Down
76 changes: 76 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
PATH
remote: .
specs:
klaro-client (0.7.0)
commonmarker (>= 0.26, < 1.0)
dotenv (~> 2.7)
http (>= 5.0, < 6.0)
i18n (>= 1.8)

GEM
remote: https://rubygems.org/
specs:
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
commonmarker (1.0.0.pre12-aarch64-linux)
commonmarker (1.0.0.pre12-arm64-darwin)
commonmarker (1.0.0.pre12-x86_64-linux)
concurrent-ruby (1.2.2)
crack (0.4.5)
rexml
diff-lcs (1.5.0)
domain_name (0.6.20231109)
dotenv (2.8.1)
ffi (1.16.3)
ffi-compiler (1.0.1)
ffi (>= 1.0.0)
rake
hashdiff (1.0.1)
http (5.1.1)
addressable (~> 2.8)
http-cookie (~> 1.0)
http-form_data (~> 2.2)
llhttp-ffi (~> 0.4.0)
http-cookie (1.0.5)
domain_name (~> 0.5)
http-form_data (2.3.0)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
llhttp-ffi (0.4.0)
ffi-compiler (~> 1.0)
rake (~> 13.0)
path (2.1.0)
public_suffix (5.0.4)
rake (13.1.0)
rexml (3.2.6)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.6)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.1)
webmock (3.19.1)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)

PLATFORMS
aarch64-linux
arm64-darwin-22
x86_64-linux

DEPENDENCIES
klaro-client!
path (~> 2.1)
rspec (~> 3.8)
webmock (~> 3.7)

BUNDLED WITH
2.3.26
2 changes: 1 addition & 1 deletion klaro_client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Gem::Specification.new do |s|
s.require_paths = ['lib']
s.add_dependency 'dotenv', '~> 2.7'
s.add_dependency 'http', '>= 5.0', '< 6.0'
s.add_dependency 'redcarpet', '>= 3.6', '< 4.0'
s.add_dependency 'commonmarker', '>= 0.26', '< 1.0'
s.add_dependency 'i18n', '>= 1.8'
s.add_development_dependency 'path', '~> 2.1'
s.add_development_dependency 'rspec', '~> 3.8'
Expand Down
2 changes: 1 addition & 1 deletion lib/klaro/client.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'http'
require 'path'
require 'redcarpet'
require 'commonmarker'
require 'i18n'

module Klaro
Expand Down
31 changes: 11 additions & 20 deletions lib/klaro/client/support/md_text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,28 @@ class Client
class MdText

SHARED_OPTIONS = {
filter_html: true,
no_links: false,
no_styles: true,
safe_links_only: true,
with_toc_data: false
}

VARIANTS = {
:summary => Redcarpet::Markdown.new(
Redcarpet::Render::HTML.new(SHARED_OPTIONS.merge({
hard_wrap: true,
}))
),
:details => Redcarpet::Markdown.new(
Redcarpet::Render::HTML.new(SHARED_OPTIONS.merge({
hard_wrap: false,
}))
)
unsafe: false,
}

def initialize(src, variant)
@src = src
@renderer = VARIANTS[variant]
@variant = variant
end

def to_s
@src
end

def render_options
SHARED_OPTIONS.merge({
hardbreaks: (@variant == :summary)
})
end

def to_html
@renderer.render(to_s).strip.gsub(/<a href/, '<a target="_blank" href')
Commonmarker.to_html(to_s, options: {
render: render_options
}).strip.gsub(/<a href/, '<a target="_blank" href')
end

end # class MdText
Expand Down
2 changes: 1 addition & 1 deletion lib/klaro/client/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Klaro
class Client
module Version
MAJOR = 0
MINOR = 6
MINOR = 7
TINY = 0
end
VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
Expand Down
4 changes: 2 additions & 2 deletions spec/resource/story_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ def story(extra = {})

describe "summary" do
it 'returns all but the first line of the story title' do
expect(story.summary.to_html).to eql("<p>I&#39;m fine, for myself<br>\nand you?</p>")
expect(story.summary.to_html).to eql("<p>I'm fine, for myself<br />\nand you?</p>")
end
end

describe "specification" do
it 'returns the specification' do
expect(story.specification.to_html).to eql(%Q{<p>Here <strong>we</strong> go!\ncariage <a target="_blank" href="http://returns.org">returns</a> do not br</p>\n\n<p>but doubles do p</p>})
expect(story.specification.to_html).to eql(%Q{<p>Here <strong>we</strong> go!\ncariage <a target="_blank" href="http://returns.org">returns</a> do not br</p>\n<p>but doubles do p</p>})
expect(story.details.to_html).to eql(story.specification.to_html)
end
end
Expand Down
31 changes: 31 additions & 0 deletions spec/support/md_text_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'spec_helper'

module Klaro
class Client
module Support
describe MdText do

it 'works for summary' do
got = MdText.new("hello\nworld", :summary).to_html
expect(got).to eql("<p>hello<br />\nworld</p>")
end

it 'works for details' do
got = MdText.new("hello\nworld", :details).to_html
expect(got).to eql("<p>hello\nworld</p>")
end

it 'does not render dangerous html' do
got = MdText.new("hello<script>var x;</script>", :details).to_html
expect(got).to eql("<p>hello<!-- raw HTML omitted -->var x;<!-- raw HTML omitted --></p>")
end

it 'does not accept style tags' do
got = MdText.new("hello<style>display: none;</style>", :details).to_html
expect(got).to eql("<p>hello<!-- raw HTML omitted -->display: none;<!-- raw HTML omitted --></p>")
end

end
end
end
end
Loading