cheepub 0.7.1 → 0.8.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: 275407b281784acb45225fe33947a403dbae8764a86b1e999ff91c178356791d
4
- data.tar.gz: 78268645254fa5940f46ba260ce867a90ba04dc018bdcc7831f461ae49dbd3be
3
+ metadata.gz: 538a1c736e4d3cec8c8f051bf9a2a17b6d623694598d83d3470226e1b5b164dc
4
+ data.tar.gz: 5034ff0f4b102495fdf61773554f9097c1879c923523d2633394f6baff40ae0c
5
5
  SHA512:
6
- metadata.gz: a316b539db435c146a41eb9ae04ca8570076a22017eabe829b3c9df685b04f2f0400e8f9a3595dfd184b34bf3baeb04eb63d9fd6da730248bdc8ead7d1ee76ef
7
- data.tar.gz: c83555f1732b3693ac2bf490f30a7b80e5232ac4a2f2b233e37d2124241ed29a2dd3a473094a97613dcc3bbfa15f6c88a78f355fe401a45c4227addb5cc61da1
6
+ metadata.gz: e415c2d6100b921d9d61a4bc8ba078a38d0e4e2e9aa2f50d598c0908743266471ecded67828431e62e78f06032349d7cb97f99601c220af6e7295c877a5bb871
7
+ data.tar.gz: a2942d1b33fdf849977122d92998b9d91f972a36ba9819190f9b4f3313e04ebb8ec65e9b45dc23c70881329991ddabf7238916768f77aaec531f589c204f8e4c
data/README.md CHANGED
@@ -41,6 +41,8 @@ $ cheepub source.md
41
41
  * `--debug` set debug mode
42
42
  * `-o, --out OUTFILE` set output filename
43
43
  * `--[no-]titlepage` add titlepage or not
44
+ * `--page-direction PAGE_DIRECTION` set page direction (`ltr` or `rtl`)
45
+ * `--json` output JSON AST and exit
44
46
  * `-h, --help` print help
45
47
 
46
48
 
@@ -88,6 +90,10 @@ In a little district west of Washington Square the streets have run crazy and br
88
90
 
89
91
  ## History
90
92
 
93
+ ### 0.8.0
94
+
95
+ - support option `--json`
96
+
91
97
  ### 0.7.1
92
98
 
93
99
  - show backtrace when `--debug` mode
data/lib/cheepub/cli.rb CHANGED
@@ -11,8 +11,10 @@ module Cheepub
11
11
  option ["--config"], "CONFIG", "set configuration file"
12
12
  option ["--latex"], :flag, "generate PDF with LaTeX"
13
13
  option ["--debug"], :flag, "set debug mode"
14
- option ["-o", "--output"], "EPUBFILE", "set output filename", attribute_name: :output
14
+ option ["--json"], :flag, "output JSON AST and exit"
15
+ option ["-o", "--output"], "OUTFILE", "set output filename", attribute_name: :output
15
16
  option ["--[no-]titlepage"], :flag, "add titlepage (or not)"
17
+ option ["--page-direction"], "PAGE_DIRECTION", "set page direction (ltr or rtl)"
16
18
 
17
19
  parameter "SRC", "source file"
18
20
 
@@ -26,6 +28,12 @@ module Cheepub
26
28
  params[:output] = output
27
29
  params[:titlepage] = titlepage?
28
30
  params[:debug] = debug?
31
+ params[:pageDirection] = page_direction
32
+ if json?
33
+ params[:template] = nil
34
+ print Cheepub::Markdown.parse(src, params).to_json
35
+ exit 0
36
+ end
29
37
  if latex?
30
38
  gen = Cheepub::Generator::Latex.new(src, params)
31
39
  else
@@ -4,6 +4,16 @@ module Cheepub
4
4
  module Converter
5
5
  module CheeLatex
6
6
 
7
+ def convert_p(el, opts)
8
+ if el.children.size == 1 && el.children.first.type == :img && !(img = convert_img(el.children.first, opts)).empty?
9
+ convert_standalone_image(el, opts, img)
10
+ elsif el.attr['class'].to_s =~ /text\-right/
11
+ "#{latex_link_target(el)}\\begin{flushright}#{inner(el, opts)}\\end{flushright}\n\n"
12
+ else
13
+ "#{latex_link_target(el)}#{inner(el, opts)}\n\n"
14
+ end
15
+ end
16
+
7
17
  def convert_codeblock(el, opts)
8
18
  show_whitespace = el.attr['class'].to_s =~ /\bshow-whitespaces\b/
9
19
  lang = extract_code_language(el.attr)
@@ -35,6 +45,8 @@ module Cheepub
35
45
  "}{#{str}"
36
46
  elsif el.value == :span
37
47
  "\\rensuji{#{inner(el, opts)}}"
48
+ elsif el.value == :p && el.children.size == 1 && el.children.first.value == :br
49
+ "\\vspace{\\baselineskip}\n"
38
50
  else
39
51
  super
40
52
  end
@@ -14,7 +14,7 @@ module Cheepub
14
14
  end
15
15
 
16
16
  def output_file(params)
17
- outfile = params[:outfile] || "book.pdf"
17
+ outfile = params[:output] || "book.pdf"
18
18
  @maker.generate_pdf(outfile, debug: params[:debug])
19
19
  end
20
20
 
@@ -1,4 +1,5 @@
1
1
  require 'kramdown'
2
+ require 'json'
2
3
 
3
4
  module Cheepub
4
5
  class Markdown
@@ -37,6 +38,18 @@ module Cheepub
37
38
 
38
39
  alias_method :to_html, :convert
39
40
 
41
+ def to_hash_ast
42
+ params = @params.dup
43
+ params[:template] = nil
44
+ Kramdown::Document.new(@text, params).to_hash_ast
45
+ end
46
+
47
+ def to_json
48
+ params = @params.dup
49
+ params[:template] = nil
50
+ Kramdown::Document.new(@text, params).to_hash_ast.to_json
51
+ end
52
+
40
53
  def save_as(filename)
41
54
  html = convert
42
55
  File.write(filename, html)
@@ -1,3 +1,3 @@
1
1
  module Cheepub
2
- VERSION = "0.7.1"
2
+ VERSION = "0.8.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cheepub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - takahashim
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-10 00:00:00.000000000 Z
11
+ date: 2018-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gepub