kitabu 3.0.3 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a15501f3e1767a56b549ee1ec0362330f1e06f9d09a30f45ee48ee7336b1331
4
- data.tar.gz: e49ef66fd50e324a611f16671915905baf031fc0dc1d0ff7e0e56a14eaf6b62a
3
+ metadata.gz: 562752c6728b0fcaf670120941d9864612edf13375f482a0e129d61ceb487845
4
+ data.tar.gz: 42ae997787207adca50cd791df060181e5e2b37ee84647d20ac4ebbf0b105dd1
5
5
  SHA512:
6
- metadata.gz: 65b392f97c0b51b1a5b863476b6d6a18ee5b4acf66e2d31fb48c43ef14044eaf30abe45169da2e52b84541f221435058a59c72b05c309e835f8cf6bd1b495642
7
- data.tar.gz: d40bd333e9487e20b1467ab554c1d8b3162d02aed3383ec20cb25a6d64ac68e3570609ffae7c4deeb7b6c8a854a98893e088b51815880bd09b74a5d3b4557ed1
6
+ metadata.gz: 7fc4d5ecaf3f24edbd3f04e1733aab2ca67017c8a91626b78df810727cb2fc843f6c885a591238a13542b3c6391fd5b3e0b088b3e348f2a1367063e3f9ca363c
7
+ data.tar.gz: 9a5b6367c443ed3343ac8b379af171c1fc6713aea6cc5d894858f2fad8bff8185283c6e6bc8c00e82abd5d77afd3df07bab2fcf4e97a60a4a15e24784e385738
@@ -19,11 +19,14 @@ jobs:
19
19
  strategy:
20
20
  fail-fast: false
21
21
  matrix:
22
- ruby: ["2.7", "3.0", "3.1"]
22
+ ruby: ["3.2", "3.3"]
23
23
  gemfile:
24
24
  - Gemfile
25
25
 
26
26
  steps:
27
+ - name: Update deps
28
+ run: sudo apt update -y
29
+
27
30
  - name: Install deps
28
31
  run: sudo apt install -y calibre gdebi
29
32
 
@@ -32,9 +35,9 @@ jobs:
32
35
  wget https://www.princexml.com/download/prince_14.2-1_ubuntu20.04_amd64.deb
33
36
  sudo gdebi --non-interactive prince_14.2-1_ubuntu20.04_amd64.deb
34
37
 
35
- - uses: actions/checkout@v2.4.0
38
+ - uses: actions/checkout@v4
36
39
 
37
- - uses: actions/cache@v2
40
+ - uses: actions/cache@v3
38
41
  with:
39
42
  path: vendor/bundle
40
43
  key: >
data/.rubocop.yml CHANGED
@@ -3,7 +3,7 @@ inherit_gem:
3
3
  rubocop-fnando: .rubocop.yml
4
4
 
5
5
  AllCops:
6
- TargetRubyVersion: 2.7
6
+ TargetRubyVersion: 3.2
7
7
  NewCops: enable
8
8
  Exclude:
9
9
  - db/schema.rb
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## v3.0.4
4
+
5
+ - Add support for
6
+ [Github's alert syntax](https://github.com/orgs/community/discussions/16925).
7
+ Kitabu's implementation supports any arbitrary name, so you can use anything
8
+ (e.g. `[!ALERT]`).
9
+
3
10
  ## v3.0.3
4
11
 
5
12
  - Fix Rouge options keys; symbols are required.
data/README.md CHANGED
@@ -26,7 +26,7 @@ starting at \$15/mo.
26
26
 
27
27
  ## Installation
28
28
 
29
- To install Kitabu, you'll need a working Ruby 2.7+ installation. If you're cool
29
+ To install Kitabu, you'll need a working Ruby 3.2+ installation. If you're cool
30
30
  with it, just run the following command to install it.
31
31
 
32
32
  gem install kitabu
data/kitabu.gemspec CHANGED
@@ -16,11 +16,10 @@ Gem::Specification.new do |s|
16
16
  "supports EPUB, Mobi, Text and HTML generation."
17
17
  s.description = s.summary
18
18
  s.license = "MIT"
19
- s.required_ruby_version = ">= 2.7"
19
+ s.required_ruby_version = ">= 3.2"
20
20
  s.metadata = {"rubygems_mfa_required" => "true"}
21
21
 
22
22
  s.files = `git ls-files`.split("\n")
23
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
23
  s.executables = `git ls-files -- bin/*`.split("\n").map do |f|
25
24
  File.basename(f)
26
25
  end
@@ -7,7 +7,7 @@ module Kitabu
7
7
  @sections ||=
8
8
  html.css("div.chapter").each_with_index.map do |chapter, index|
9
9
  OpenStruct.new(
10
- index: index,
10
+ index:,
11
11
  filename: "section_#{index}.html",
12
12
  filepath: tmp_dir.join("section_#{index}.html").to_s,
13
13
  html: Nokogiri::HTML(chapter.inner_html)
@@ -114,7 +114,7 @@ module Kitabu
114
114
  end
115
115
 
116
116
  def render_chapter(content)
117
- locals = config.merge(content: content)
117
+ locals = config.merge(content:)
118
118
  render_template(template_path, locals)
119
119
  end
120
120
 
@@ -130,7 +130,7 @@ module Kitabu
130
130
  path =
131
131
  Dir[root_dir.join("templates/epub/cover.{jpg,png,gif}").to_s].first
132
132
 
133
- return path if path && File.exist?(path)
133
+ path if path && File.exist?(path)
134
134
  end
135
135
 
136
136
  def navigation
@@ -73,7 +73,7 @@ module Kitabu
73
73
  Footnotes::HTML.process(toc.content).html.css("body").first.inner_html
74
74
 
75
75
  locals = config.merge(
76
- content: content,
76
+ content:,
77
77
  toc: toc.to_html,
78
78
  changelog: render_changelog
79
79
  )
@@ -8,6 +8,8 @@ module Rouge
8
8
  options = options.keys.map(&:to_sym).zip(options.values).to_h
9
9
  options[:start_line] = options.fetch(:start_line, 1).to_i
10
10
 
11
+ options = options.keys.map(&:to_sym).zip(options.values).to_h
12
+
11
13
  Formatters::HTMLLegacy.new(
12
14
  {css_class: "highlight #{lexer.tag}"}.merge(options)
13
15
  )
@@ -5,6 +5,38 @@ module Kitabu
5
5
  class Renderer < Redcarpet::Render::HTML
6
6
  include Redcarpet::Render::SmartyPants
7
7
  include Rouge::Plugins::Redcarpet
8
+
9
+ # Be more flexible than github and support any arbitrary name.
10
+ ALERT_MARK = /^\[!(?<type>[A-Z]+)\]$/
11
+
12
+ # Support alert boxes just like github.
13
+ # https://github.com/orgs/community/discussions/16925
14
+ def block_quote(quote)
15
+ html = Nokogiri::HTML(quote)
16
+ element = html.css("body > :first-child").first
17
+
18
+ matches = element.text.match(ALERT_MARK)
19
+
20
+ return "<blockquote>#{quote}</blockquote>" unless matches
21
+
22
+ element.remove
23
+
24
+ type = matches[:type].downcase
25
+ type = "info" if type == "note"
26
+
27
+ title = I18n.t(
28
+ type,
29
+ scope: :notes,
30
+ default: type.titleize
31
+ )
32
+
33
+ <<~HTML.strip_heredoc
34
+ <div class="note #{type}">
35
+ <p class="note--title">#{title}</p>
36
+ #{html.css('body').inner_html}
37
+ </div>
38
+ HTML
39
+ end
8
40
  end
9
41
 
10
42
  class << self
@@ -8,7 +8,7 @@ module Kitabu
8
8
 
9
9
  # Files that should be skipped.
10
10
  #
11
- IGNORE_FILES = /^(CHANGELOG|TOC)\..*?$/.freeze
11
+ IGNORE_FILES = /^(CHANGELOG|TOC)\..*?$/
12
12
 
13
13
  # List of recognized extensions.
14
14
  #
@@ -37,7 +37,7 @@ module Kitabu
37
37
  if File.file?(entry)
38
38
  [entry]
39
39
  else
40
- Dir["#{entry}/**/*.{#{EXTENSIONS.join(',')}}"].sort
40
+ Dir["#{entry}/**/*.{#{EXTENSIONS.join(',')}}"]
41
41
  end
42
42
  end
43
43
 
@@ -10,7 +10,7 @@ module Kitabu
10
10
  end
11
11
 
12
12
  def to_html
13
- data = OpenStruct.new(navigation: navigation).instance_eval { binding }
13
+ data = OpenStruct.new(navigation:).instance_eval { binding }
14
14
  ERB.new(template).result(data)
15
15
  end
16
16
 
@@ -61,9 +61,9 @@ module Kitabu
61
61
  #
62
62
  def to_hash
63
63
  {
64
- content: content,
64
+ content:,
65
65
  html: to_html,
66
- toc: toc
66
+ toc:
67
67
  }
68
68
  end
69
69
 
@@ -3,8 +3,8 @@
3
3
  module Kitabu
4
4
  module Version
5
5
  MAJOR = 3
6
- MINOR = 0
7
- PATCH = 3
8
- STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
6
+ MINOR = 1
7
+ PATCH = 0
8
+ STRING = "#{MAJOR}.#{MINOR}.#{PATCH}".freeze
9
9
  end
10
10
  end
@@ -44,4 +44,43 @@ describe Kitabu::Markdown do
44
44
  TEXT
45
45
  end.not_to raise_error
46
46
  end
47
+
48
+ it "renders alert boxes using block quotes" do
49
+ html = Kitabu::Markdown.render <<-TEXT.strip_heredoc
50
+ > [!NOTE]
51
+ >
52
+ > This is just a note
53
+ TEXT
54
+
55
+ html = Nokogiri::HTML(html)
56
+ selector = "div.note.info > .note--title"
57
+
58
+ expect(html.css(selector).text).to eql("Info")
59
+ expect(html.css("#{selector} + p").text).to eql("This is just a note")
60
+ end
61
+
62
+ it "renders arbitrary alert boxes using block quotes" do
63
+ html = Kitabu::Markdown.render <<-TEXT.strip_heredoc
64
+ > [!ALERT]
65
+ >
66
+ > This is just an alert
67
+ TEXT
68
+
69
+ html = Nokogiri::HTML(html)
70
+ selector = "div.note.alert > .note--title"
71
+
72
+ expect(html.css(selector).text).to eql("Alert")
73
+ expect(html.css("#{selector} + p").text).to eql("This is just an alert")
74
+ end
75
+
76
+ it "renders regular block quotes" do
77
+ html = Kitabu::Markdown.render <<-TEXT.strip_heredoc
78
+ > This is just a quote
79
+ TEXT
80
+
81
+ html = Nokogiri::HTML(html)
82
+
83
+ expect(html.css(".note").count).to eql(0)
84
+ expect(html.css("blockquote").text.chomp).to eql("This is just a quote")
85
+ end
47
86
  end
data/spec/spec_helper.rb CHANGED
@@ -13,7 +13,7 @@ require "pathname"
13
13
  SPECDIR = Pathname.new(File.dirname(__FILE__))
14
14
  TMPDIR = SPECDIR.join("tmp")
15
15
 
16
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each {|r| require r }
16
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|r| require r }
17
17
 
18
18
  p [
19
19
  :filter_env,
@@ -47,7 +47,7 @@ RSpec.configure do |config|
47
47
 
48
48
  cleaner = proc do
49
49
  [TMPDIR, SPECDIR.join("support/mybook/output")].each do |i|
50
- FileUtils.rm_rf(i) if File.exist?(i)
50
+ FileUtils.rm_rf(i)
51
51
  end
52
52
 
53
53
  Dir.chdir File.expand_path("..", __dir__)
@@ -31,7 +31,7 @@ module Matchers
31
31
 
32
32
  if input.respond_to?(:body)
33
33
  engine.parse(input.body.to_s)
34
- elsif Nokogiri::XML::Element == input
34
+ elsif input == Nokogiri::XML::Element
35
35
  input
36
36
  else
37
37
  engine.parse(input.to_s)
data/templates/config.erb CHANGED
@@ -25,7 +25,7 @@ published_at: "<%= Date.today %>"
25
25
  subject: "This guide will help you understand how all of the pieces fit together on Kitabu."
26
26
 
27
27
  # Some keywords that identify this book.
28
- keywords: "kitabu, e-book, kindlegen, epub, mobi, pdf, prince"
28
+ keywords: "kitabu, e-book, calibre, epub, mobi, pdf, prince"
29
29
 
30
30
  # Some unique identification. Works great with your domain
31
31
  # like `http://yourbook.example.com`.
@@ -4,10 +4,8 @@ This guide is designed for beginners who want to get started with Kitabu from
4
4
  scratch. However, to get the most out of it, you need to have some prerequisites
5
5
  installed:
6
6
 
7
- - The [Ruby](http://ruby-lang.org) interpreter version 2.0.0 or greater.
8
- - The [PrinceXML](http://princexml.com) converter version 9.0 or greater.
9
- - The [KindleGen](http://www.amazon.com/gp/feature.html?docId=1000765211)
10
- converter.
7
+ - The [Ruby](http://ruby-lang.org) interpreter version 3.2 or newer.
8
+ - The [PrinceXML](http://princexml.com) converter version 14.0 or newer.
11
9
 
12
10
  ### Installing Ruby
13
11
 
@@ -29,16 +27,10 @@ user costs 495USD. If you don't like the price tag, consider using
29
27
  To install PrinceXML, go to the website and download the correct version for
30
28
  your platform; you can choose from Mac OSX, to Linux and Windows.
31
29
 
32
- ### Installing KindleGen
30
+ ### Installing Calibre
33
31
 
34
- KindleGen is the command-line tool that allows you to convert e-pubs into
35
- `.mobi` files. You can't sell these files, though.[^1] So if that's the case,
36
- consider using [Calibre](http://calibre-ebook.com/) for this task.[^2]
32
+ [Calibre](http://calibre-ebook.com/) is a e-book manager that, among other
33
+ features, allows converting ePub files into .mobi files.
37
34
 
38
- If you're running [Homebrew](http://brew.sh) on the Mac OSX, you can install it
39
- with `brew install kindlegen`. Go to
40
- [KindleGen's website](http://www.amazon.com/gp/feature.html?docId=1000765211)
41
- and download the appropriate installer otherwise.
42
-
43
- [^1]: You can, but that would be a violation of Amazon's terms of use.
44
- [^2]: Calibre is not perfect, but does a good job.
35
+ To install Calibre, go to the website and download the correct version for your
36
+ platform; you can choose from Mac OSX, to Linux and Windows.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitabu
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-20 00:00:00.000000000 Z
11
+ date: 2024-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -368,62 +368,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
368
368
  requirements:
369
369
  - - ">="
370
370
  - !ruby/object:Gem::Version
371
- version: '2.7'
371
+ version: '3.2'
372
372
  required_rubygems_version: !ruby/object:Gem::Requirement
373
373
  requirements:
374
374
  - - ">="
375
375
  - !ruby/object:Gem::Version
376
376
  version: '0'
377
377
  requirements: []
378
- rubygems_version: 3.3.7
378
+ rubygems_version: 3.5.3
379
379
  signing_key:
380
380
  specification_version: 4
381
381
  summary: A framework for creating e-books from Markdown using Ruby. Using the Prince
382
382
  PDF generator, you'll be able to get high quality PDFs. Also supports EPUB, Mobi,
383
383
  Text and HTML generation.
384
- test_files:
385
- - spec/kitabu/cli/export_spec.rb
386
- - spec/kitabu/cli/new_spec.rb
387
- - spec/kitabu/cli/permalinks_spec.rb
388
- - spec/kitabu/cli/stats_spec.rb
389
- - spec/kitabu/cli/version_spec.rb
390
- - spec/kitabu/exporter/css_spec.rb
391
- - spec/kitabu/exporter/epub_spec.rb
392
- - spec/kitabu/exporter/html_spec.rb
393
- - spec/kitabu/exporter/mobi_spec.rb
394
- - spec/kitabu/exporter/pdf_spec.rb
395
- - spec/kitabu/extensions/string_spec.rb
396
- - spec/kitabu/footnotes/html_spec.rb
397
- - spec/kitabu/generator_spec.rb
398
- - spec/kitabu/markdown_spec.rb
399
- - spec/kitabu/source_list_spec.rb
400
- - spec/kitabu/stats_spec.rb
401
- - spec/kitabu/toc/html_spec.rb
402
- - spec/spec_helper.rb
403
- - spec/support/exit_with_code.rb
404
- - spec/support/have_tag.rb
405
- - spec/support/helper.rb
406
- - spec/support/mybook/.gitignore
407
- - spec/support/mybook/code/.gitkeep
408
- - spec/support/mybook/code/code.rb
409
- - spec/support/mybook/config/helper.rb
410
- - spec/support/mybook/config/kitabu.yml
411
- - spec/support/mybook/fonts/OpenSans-CondBold.ttf
412
- - spec/support/mybook/images/.gitkeep
413
- - spec/support/mybook/images/logo.gif
414
- - spec/support/mybook/templates/epub/cover.erb
415
- - spec/support/mybook/templates/epub/cover.png
416
- - spec/support/mybook/templates/epub/page.erb
417
- - spec/support/mybook/templates/html/layout.erb
418
- - spec/support/mybook/templates/styles/epub.css
419
- - spec/support/mybook/templates/styles/html.css
420
- - spec/support/mybook/templates/styles/pdf.css
421
- - spec/support/mybook/templates/styles/print.css
422
- - spec/support/mybook/text/.gitkeep
423
- - spec/support/mybook/text/01_Markdown_Chapter.md
424
- - spec/support/mybook/text/02_ERB_Chapter.md.erb
425
- - spec/support/mybook/text/03_With_Directory/Some_Chapter.md
426
- - spec/support/mybook/text/CHANGELOG.md
427
- - spec/support/mybook/text/TOC.md
428
- - spec/support/mybook/text/_00_Introduction.md
429
- - spec/support/shared.rb
384
+ test_files: []