Skip to content

Commit

Permalink
Merge pull request #291 from chloerei/trailing
Browse files Browse the repository at this point in the history
去掉 PDF 的多余空格,调整样式
  • Loading branch information
networm committed Oct 19, 2015
2 parents 63cab3d + 8c0593e commit 98bb8dc
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ gem 'awesome_print'

gem 'asciidoctor-epub3', '1.0.0.alpha.2'
gem 'asciidoctor-pdf', '1.5.0.alpha.8'
gem 'asciidoctor-pdf-cjk-kai_gen_gothic', '~> 0.1.0'
gem 'asciidoctor-pdf-cjk-kai_gen_gothic', '~> 0.1.1'

gem 'coderay'
gem 'pygments.rb'
Expand Down
16 changes: 8 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ GEM
safe_yaml (= 1.0.4)
thread_safe (= 0.3.4)
treetop (= 1.5.3)
asciidoctor-pdf-cjk (0.1.1)
asciidoctor-pdf-cjk (0.1.2)
asciidoctor-pdf (~> 1.5.0.alpha.8)
asciidoctor-pdf-cjk-kai_gen_gothic (0.1.0)
asciidoctor-pdf-cjk (~> 0.1.1)
asciidoctor-pdf-cjk-kai_gen_gothic (0.1.1)
asciidoctor-pdf-cjk (~> 0.1.2)
awesome_print (1.2.0)
coderay (1.1.0)
css_parser (1.3.6)
css_parser (1.3.7)
addressable
epubcheck (3.0.1)
gepub (0.6.9.2)
Expand All @@ -37,7 +37,7 @@ GEM
mini_portile (0.6.0)
nokogiri (1.6.3.1)
mini_portile (= 0.6.0)
pdf-core (0.5.1)
pdf-core (0.6.0)
pdf-reader (1.3.3)
Ascii85 (~> 1.0.0)
afm (~> 0.2.0)
Expand All @@ -46,8 +46,8 @@ GEM
ttfunk
polyglot (0.3.5)
posix-spawn (0.3.9)
prawn (2.0.1)
pdf-core (~> 0.5.1)
prawn (2.0.2)
pdf-core (~> 0.6.0)
ttfunk (~> 1.4.0)
prawn-icon (0.6.4)
prawn (>= 1.1.0, < 3.0.0)
Expand Down Expand Up @@ -78,7 +78,7 @@ DEPENDENCIES
asciidoctor (= 1.5.0)
asciidoctor-epub3 (= 1.0.0.alpha.2)
asciidoctor-pdf (= 1.5.0.alpha.8)
asciidoctor-pdf-cjk-kai_gen_gothic (~> 0.1.0)
asciidoctor-pdf-cjk-kai_gen_gothic (~> 0.1.1)
awesome_print
coderay
epubcheck
Expand Down
8 changes: 4 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ namespace :book do
desc 'build basic book formats'
task :build => :prebuild do
puts "Converting to HTML..."
`bundle exec asciidoctor progit.asc`
`bundle exec asciidoctor -r ./config.rb progit.asc`
puts " -- HTML output at progit.html"

puts "Converting to EPub..."
`bundle exec asciidoctor-epub3 progit.asc`
`bundle exec asciidoctor-epub3 -r ./config.rb progit.asc`
puts " -- Epub output at progit.epub"

puts "Converting to Mobi (kf8)..."
`bundle exec asciidoctor-epub3 -a ebook-format=kf8 progit.asc`
`bundle exec asciidoctor-epub3 -r ./config.rb -a ebook-format=kf8 progit.asc`
puts " -- Mobi output at progit.mobi"

puts "Converting to PDF... (this one takes a while)"
`bundle exec asciidoctor-pdf -r asciidoctor-pdf-cjk-kai_gen_gothic -a pdf-style=KaiGenGothicCN progit.asc 2>/dev/null`
`bundle exec asciidoctor-pdf -r ./config.rb -a pdf-style=KaiGenGothicCN progit.asc 2>/dev/null`
puts " -- PDF output at progit.pdf"
end
end
Expand Down
23 changes: 23 additions & 0 deletions config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Bundler.require(:default)

class TrailingTreeprocessor < Asciidoctor::Extensions::Treeprocessor
def process document
return unless document.blocks?
process_blocks document
nil
end

def process_blocks node
node.blocks.each_with_index do |block, index|
if block.context == :paragraph
node.blocks[index] = create_paragraph block.document, block.content.gsub("\n", ''), block.attributes
else
process_blocks block
end
end
end
end

Asciidoctor::Extensions.register do
treeprocessor TrailingTreeprocessor
end

0 comments on commit 98bb8dc

Please sign in to comment.