kitabu 3.0.2 → 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: 7373f8260e5946669b21df6e626ca0742e765b4078a6d739452580cf892cea0b
4
- data.tar.gz: f440520e583e4955bd66903f7ca057c1abaccbf9e30868270ed595318bfb57eb
3
+ metadata.gz: 562752c6728b0fcaf670120941d9864612edf13375f482a0e129d61ceb487845
4
+ data.tar.gz: 42ae997787207adca50cd791df060181e5e2b37ee84647d20ac4ebbf0b105dd1
5
5
  SHA512:
6
- metadata.gz: f506160c9264ea90b0dc7e42f8e9530c80376a7ec10dd4d0f1294b15803902ad584b9a3b61cb96b2639729472ed62d1b4030fa2915344014064dd7240d7b61eb
7
- data.tar.gz: acfa26ae9ad539737948607617a424f1af733966b023f5e02dfa4706e9482001e594789eba9ffb6271e6eeb6eb6e53d982944ea16cddf80b1ffc3592a8f35941
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,16 @@
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
+
10
+ ## v3.0.3
11
+
12
+ - Fix Rouge options keys; symbols are required.
13
+
3
14
  ## v3.0.2
4
15
 
5
16
  - Fix `styles` directory copying.
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
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.version = Kitabu::Version::STRING
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.authors = ["Nando Vieira"]
11
- s.email = ["fnando.vieira@gmail.com"]
11
+ s.email = ["me@fnando.com"]
12
12
  s.homepage = "http://rubygems.org/gems/kitabu"
13
13
  s.summary = "A framework for creating e-books from Markdown " \
14
14
  "using Ruby. Using the Prince PDF generator, " \
@@ -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
@@ -20,6 +20,10 @@ module Kitabu
20
20
  @source = root_dir.join("text")
21
21
  end
22
22
 
23
+ def export
24
+ FileUtils.mkdir_p(root_dir.join("output"))
25
+ end
26
+
23
27
  def source_list
24
28
  @source_list ||= SourceList.new(root_dir)
25
29
  end
@@ -6,6 +6,8 @@ module Kitabu
6
6
  attr_reader :root_dir
7
7
 
8
8
  def export
9
+ super
10
+
9
11
  FileUtils.cp_r(
10
12
  root_dir.join("templates/styles").to_s,
11
13
  root_dir.join("output").to_s
@@ -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)
@@ -24,6 +24,7 @@ module Kitabu
24
24
  end
25
25
 
26
26
  def export
27
+ super
27
28
  copy_styles!
28
29
  copy_images!
29
30
  set_metadata!
@@ -113,7 +114,7 @@ module Kitabu
113
114
  end
114
115
 
115
116
  def render_chapter(content)
116
- locals = config.merge(content: content)
117
+ locals = config.merge(content:)
117
118
  render_template(template_path, locals)
118
119
  end
119
120
 
@@ -129,7 +130,7 @@ module Kitabu
129
130
  path =
130
131
  Dir[root_dir.join("templates/epub/cover.{jpg,png,gif}").to_s].first
131
132
 
132
- return path if path && File.exist?(path)
133
+ path if path && File.exist?(path)
133
134
  end
134
135
 
135
136
  def navigation
@@ -14,6 +14,7 @@ module Kitabu
14
14
  # to <tt>output/book_name.html</tt>.
15
15
  #
16
16
  def export
17
+ super
17
18
  copy_images!
18
19
  copy_fonts!
19
20
  export_stylesheets!
@@ -72,7 +73,7 @@ module Kitabu
72
73
  Footnotes::HTML.process(toc.content).html.css("body").first.inner_html
73
74
 
74
75
  locals = config.merge(
75
- content: content,
76
+ content:,
76
77
  toc: toc.to_html,
77
78
  changelog: render_changelog
78
79
  )
@@ -4,6 +4,7 @@ module Kitabu
4
4
  class Exporter
5
5
  class Mobi < Base
6
6
  def export
7
+ super
7
8
  spawn_command ["ebook-convert", epub_file.to_s, mobi_file.to_s]
8
9
  true
9
10
  end
@@ -4,6 +4,7 @@ module Kitabu
4
4
  class Exporter
5
5
  class PDF < Base
6
6
  def export
7
+ super
7
8
  apply_footnotes!
8
9
  spawn_command ["prince", html_for_pdf.to_s, "-o", pdf_file.to_s]
9
10
  spawn_command ["prince", html_for_print.to_s, "-o", print_file.to_s]
@@ -5,6 +5,10 @@ module Rouge
5
5
  module Redcarpet
6
6
  def rouge_formatter(lexer)
7
7
  options = lexer.respond_to?(:options) ? lexer.options : {}
8
+ options = options.keys.map(&:to_sym).zip(options.values).to_h
9
+ options[:start_line] = options.fetch(:start_line, 1).to_i
10
+
11
+ options = options.keys.map(&:to_sym).zip(options.values).to_h
8
12
 
9
13
  Formatters::HTMLLegacy.new(
10
14
  {css_class: "highlight #{lexer.tag}"}.merge(options)
@@ -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 = 2
8
- STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
6
+ MINOR = 1
7
+ PATCH = 0
8
+ STRING = "#{MAJOR}.#{MINOR}.#{PATCH}".freeze
9
9
  end
10
10
  end
@@ -7,6 +7,7 @@ describe Kitabu::Exporter::Mobi, calibre: Kitabu::Dependency.calibre? do
7
7
  root = SPECDIR.join("support/mybook")
8
8
 
9
9
  Kitabu::Exporter::HTML.export(root)
10
+ Kitabu::Exporter::Epub.export(root)
10
11
  Kitabu::Exporter::Mobi.export(root)
11
12
 
12
13
  expect(root.join("output/mybook.mobi")).to be_file
@@ -24,6 +24,17 @@ describe Kitabu::Markdown do
24
24
  expect(html).to include('<span class="k">echo</span>')
25
25
  end
26
26
 
27
+ it "enables line numbers" do
28
+ html = Kitabu::Markdown.render <<-TEXT.strip_heredoc
29
+ ```ruby?line_numbers=true
30
+ class User
31
+ end
32
+ ```
33
+ TEXT
34
+
35
+ expect(html).to include(%[<table class="rouge-table">])
36
+ end
37
+
27
38
  it "does not raise with unknown lexers" do
28
39
  expect do
29
40
  Kitabu::Markdown.render <<-TEXT.strip_heredoc
@@ -33,4 +44,43 @@ describe Kitabu::Markdown do
33
44
  TEXT
34
45
  end.not_to raise_error
35
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
36
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,
@@ -46,8 +46,8 @@ RSpec.configure do |config|
46
46
  )
47
47
 
48
48
  cleaner = proc do
49
- [TMPDIR].each do |i|
50
- FileUtils.rm_rf(i) if File.exist?(i)
49
+ [TMPDIR, SPECDIR.join("support/mybook/output")].each do |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.2
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-19 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
@@ -224,7 +224,7 @@ description: A framework for creating e-books from Markdown using Ruby. Using th
224
224
  Prince PDF generator, you'll be able to get high quality PDFs. Also supports EPUB,
225
225
  Mobi, Text and HTML generation.
226
226
  email:
227
- - fnando.vieira@gmail.com
227
+ - me@fnando.com
228
228
  executables:
229
229
  - kitabu
230
230
  extensions: []
@@ -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: []