asciidoctor-pdf 1.5.0.beta.1 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.adoc +277 -2
- data/LICENSE.adoc +1 -1
- data/NOTICE.adoc +1 -1
- data/README.adoc +486 -292
- data/asciidoctor-pdf.gemspec +12 -11
- data/bin/asciidoctor-pdf +2 -6
- data/bin/asciidoctor-pdf-optimize +20 -0
- data/data/fonts/ABOUT-mplus1mn-subset +26 -0
- data/data/fonts/ABOUT-mplus1p-subset +26 -0
- data/data/fonts/ABOUT-notoemoji-subset +3 -0
- data/data/fonts/ABOUT-notoserif-subset +26 -0
- data/data/fonts/{LICENSE-mplus-testflight-58 → LICENSE-mplus} +2 -2
- data/data/fonts/{LICENSE-noto-2015-06-05 → LICENSE-notoserif} +0 -0
- data/data/fonts/mplus1mn-bold-ascii.ttf +0 -0
- data/data/fonts/mplus1mn-bold-subset.ttf +0 -0
- data/data/fonts/mplus1mn-bold_italic-ascii.ttf +0 -0
- data/data/fonts/mplus1mn-bold_italic-subset.ttf +0 -0
- data/data/fonts/mplus1mn-italic-ascii.ttf +0 -0
- data/data/fonts/mplus1mn-italic-subset.ttf +0 -0
- data/data/fonts/mplus1mn-regular-ascii-conums.ttf +0 -0
- data/data/fonts/mplus1mn-regular-subset.ttf +0 -0
- data/data/fonts/mplus1p-regular-fallback.ttf +0 -0
- data/data/fonts/notoemoji-subset.ttf +0 -0
- data/data/fonts/notoserif-bold-subset.ttf +0 -0
- data/data/fonts/notoserif-bold_italic-subset.ttf +0 -0
- data/data/fonts/notoserif-italic-subset.ttf +0 -0
- data/data/fonts/notoserif-regular-subset.ttf +0 -0
- data/data/themes/base-theme.yml +22 -4
- data/data/themes/default-theme.yml +59 -29
- data/data/themes/default-with-fallback-font-theme.yml +4 -17
- data/docs/theming-guide.adoc +1647 -167
- data/lib/asciidoctor/pdf/converter.rb +4489 -0
- data/lib/{asciidoctor-pdf/asciidoctor_ext → asciidoctor/pdf/ext/asciidoctor}/abstract_block.rb +2 -0
- data/lib/asciidoctor/pdf/ext/asciidoctor/abstract_node.rb +7 -0
- data/lib/{asciidoctor-pdf/asciidoctor_ext → asciidoctor/pdf/ext/asciidoctor}/document.rb +2 -0
- data/lib/asciidoctor/pdf/ext/asciidoctor/image.rb +35 -0
- data/lib/{asciidoctor-pdf/asciidoctor_ext → asciidoctor/pdf/ext/asciidoctor}/list.rb +4 -2
- data/lib/{asciidoctor-pdf/asciidoctor_ext → asciidoctor/pdf/ext/asciidoctor}/list_item.rb +3 -1
- data/lib/asciidoctor/pdf/ext/asciidoctor/logging_shim.rb +33 -0
- data/lib/{asciidoctor-pdf/asciidoctor_ext → asciidoctor/pdf/ext/asciidoctor}/section.rb +9 -6
- data/lib/asciidoctor/pdf/ext/asciidoctor.rb +11 -0
- data/lib/{asciidoctor-pdf/core_ext → asciidoctor/pdf/ext/core}/array.rb +6 -0
- data/lib/asciidoctor/pdf/ext/core/file.rb +9 -0
- data/lib/{asciidoctor-pdf/core_ext → asciidoctor/pdf/ext/core}/hash.rb +2 -0
- data/lib/{asciidoctor-pdf/core_ext → asciidoctor/pdf/ext/core}/numeric.rb +5 -3
- data/lib/{asciidoctor-pdf/core_ext → asciidoctor/pdf/ext/core}/object.rb +3 -1
- data/lib/{asciidoctor-pdf/core_ext → asciidoctor/pdf/ext/core}/quantifiable_stdout.rb +9 -1
- data/lib/{asciidoctor-pdf/core_ext → asciidoctor/pdf/ext/core}/regexp.rb +2 -0
- data/lib/{asciidoctor-pdf/core_ext → asciidoctor/pdf/ext/core}/string.rb +9 -13
- data/lib/asciidoctor/pdf/ext/core.rb +10 -0
- data/lib/asciidoctor/pdf/ext/pdf-core/page.rb +54 -0
- data/lib/asciidoctor/pdf/ext/pdf-core/pdf_object.rb +8 -0
- data/lib/asciidoctor/pdf/ext/pdf-core.rb +4 -0
- data/lib/asciidoctor/pdf/ext/prawn/coderay_encoder.rb +117 -0
- data/lib/asciidoctor/pdf/ext/prawn/extensions.rb +922 -0
- data/lib/{asciidoctor-pdf/prawn_ext → asciidoctor/pdf/ext/prawn}/font/afm.rb +14 -10
- data/lib/asciidoctor/pdf/ext/prawn/font_metric_cache.rb +9 -0
- data/lib/asciidoctor/pdf/ext/prawn/formatted_text/box.rb +66 -0
- data/lib/{asciidoctor-pdf/prawn_ext → asciidoctor/pdf/ext/prawn}/formatted_text/fragment.rb +16 -12
- data/lib/asciidoctor/pdf/ext/prawn/images.rb +54 -0
- data/lib/asciidoctor/pdf/ext/prawn-svg/interface.rb +14 -0
- data/lib/{asciidoctor-pdf/prawn-svg_ext.rb → asciidoctor/pdf/ext/prawn-svg.rb} +3 -1
- data/lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb +76 -0
- data/lib/{asciidoctor-pdf/prawn-table_ext → asciidoctor/pdf/ext/prawn-table}/cell/text.rb +6 -3
- data/lib/{asciidoctor-pdf/prawn-table_ext → asciidoctor/pdf/ext/prawn-table}/cell.rb +10 -10
- data/lib/asciidoctor/pdf/ext/prawn-table.rb +6 -0
- data/lib/{asciidoctor-pdf/prawn-templates_ext.rb → asciidoctor/pdf/ext/prawn-templates.rb} +2 -0
- data/lib/asciidoctor/pdf/ext/prawn.rb +9 -0
- data/lib/asciidoctor/pdf/ext/pygments.rb +34 -0
- data/lib/asciidoctor/pdf/ext/rouge/formatters/prawn.rb +208 -0
- data/lib/{asciidoctor-pdf/rouge_ext → asciidoctor/pdf/ext/rouge}/themes/asciidoctor_pdf_default.rb +2 -0
- data/lib/asciidoctor/pdf/ext/rouge.rb +5 -0
- data/lib/asciidoctor/pdf/ext.rb +9 -0
- data/lib/asciidoctor/pdf/formatted_text/formatter.rb +43 -0
- data/lib/asciidoctor/pdf/formatted_text/fragment_position_renderer.rb +14 -0
- data/lib/asciidoctor/pdf/formatted_text/inline_destination_marker.rb +21 -0
- data/lib/asciidoctor/pdf/formatted_text/inline_image_arranger.rb +134 -0
- data/lib/asciidoctor/pdf/formatted_text/inline_image_renderer.rb +51 -0
- data/lib/asciidoctor/pdf/formatted_text/inline_text_aligner.rb +22 -0
- data/lib/{asciidoctor-pdf → asciidoctor/pdf}/formatted_text/parser.rb +31 -7
- data/lib/{asciidoctor-pdf → asciidoctor/pdf}/formatted_text/parser.treetop +3 -4
- data/lib/asciidoctor/pdf/formatted_text/source_wrap.rb +43 -0
- data/lib/asciidoctor/pdf/formatted_text/text_background_and_border_renderer.rb +55 -0
- data/lib/asciidoctor/pdf/formatted_text/transform.rb +394 -0
- data/lib/{asciidoctor-pdf → asciidoctor/pdf}/formatted_text.rb +4 -0
- data/lib/asciidoctor/pdf/index_catalog.rb +133 -0
- data/lib/asciidoctor/pdf/measurements.rb +62 -0
- data/lib/asciidoctor/pdf/optimizer.rb +44 -0
- data/lib/asciidoctor/pdf/pdfmark.rb +41 -0
- data/lib/asciidoctor/pdf/roman_numeral.rb +128 -0
- data/lib/asciidoctor/pdf/sanitizer.rb +45 -0
- data/lib/asciidoctor/pdf/text_transformer.rb +116 -0
- data/lib/asciidoctor/pdf/theme_loader.rb +305 -0
- data/lib/asciidoctor/pdf/version.rb +8 -1
- data/lib/asciidoctor/pdf.rb +15 -1
- data/lib/asciidoctor-pdf/converter.rb +2 -3824
- data/lib/asciidoctor-pdf/version.rb +3 -6
- data/lib/asciidoctor-pdf.rb +3 -4
- metadata +130 -85
- data/lib/asciidoctor-pdf/asciidoctor_ext/image.rb +0 -24
- data/lib/asciidoctor-pdf/asciidoctor_ext/logging_shim.rb +0 -25
- data/lib/asciidoctor-pdf/asciidoctor_ext.rb +0 -8
- data/lib/asciidoctor-pdf/core_ext/ostruct.rb +0 -8
- data/lib/asciidoctor-pdf/core_ext.rb +0 -6
- data/lib/asciidoctor-pdf/formatted_text/formatter.rb +0 -40
- data/lib/asciidoctor-pdf/formatted_text/inline_destination_marker.rb +0 -21
- data/lib/asciidoctor-pdf/formatted_text/inline_image_arranger.rb +0 -160
- data/lib/asciidoctor-pdf/formatted_text/inline_image_renderer.rb +0 -46
- data/lib/asciidoctor-pdf/formatted_text/inline_text_aligner.rb +0 -20
- data/lib/asciidoctor-pdf/formatted_text/text_background_and_border_renderer.rb +0 -45
- data/lib/asciidoctor-pdf/formatted_text/transform.rb +0 -294
- data/lib/asciidoctor-pdf/implicit_header_processor.rb +0 -63
- data/lib/asciidoctor-pdf/index_catalog.rb +0 -127
- data/lib/asciidoctor-pdf/measurements.rb +0 -58
- data/lib/asciidoctor-pdf/pdf-core_ext/page.rb +0 -25
- data/lib/asciidoctor-pdf/pdf-core_ext/pdf_object.rb +0 -6
- data/lib/asciidoctor-pdf/pdf-core_ext.rb +0 -2
- data/lib/asciidoctor-pdf/pdfmark.rb +0 -33
- data/lib/asciidoctor-pdf/prawn-svg_ext/interface.rb +0 -10
- data/lib/asciidoctor-pdf/prawn-table_ext/cell/asciidoc.rb +0 -69
- data/lib/asciidoctor-pdf/prawn-table_ext.rb +0 -4
- data/lib/asciidoctor-pdf/prawn_ext/coderay_encoder.rb +0 -115
- data/lib/asciidoctor-pdf/prawn_ext/extensions.rb +0 -904
- data/lib/asciidoctor-pdf/prawn_ext/images.rb +0 -51
- data/lib/asciidoctor-pdf/prawn_ext.rb +0 -5
- data/lib/asciidoctor-pdf/roman_numeral.rb +0 -126
- data/lib/asciidoctor-pdf/rouge_ext/formatters/prawn.rb +0 -175
- data/lib/asciidoctor-pdf/rouge_ext/themes/bw.rb +0 -38
- data/lib/asciidoctor-pdf/rouge_ext.rb +0 -4
- data/lib/asciidoctor-pdf/sanitizer.rb +0 -101
- data/lib/asciidoctor-pdf/temporary_path.rb +0 -13
- data/lib/asciidoctor-pdf/theme_loader.rb +0 -280
- data/lib/asciidoctor-pdf/ttfunk_ext.rb +0 -8
@@ -1,51 +0,0 @@
|
|
1
|
-
module Asciidoctor
|
2
|
-
module Prawn
|
3
|
-
module Images
|
4
|
-
class << self
|
5
|
-
def extended base
|
6
|
-
base.class.__send__ :alias_method, :_initial_image, :image
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
# Dispatch to suitable image method in Prawn based on file extension.
|
11
|
-
def image file, opts = {}
|
12
|
-
# FIXME handle case when SVG is an IO object
|
13
|
-
if ::String === file && (((opts = opts.dup).delete :format) == 'svg' || (file.downcase.end_with? '.svg'))
|
14
|
-
#opts[:enable_file_requests_with_root] = (::File.dirname file) unless opts.key? :enable_file_requests_with_root
|
15
|
-
#opts[:enable_web_requests] = allow_uri_read if !(opts.key? :enable_web_requests) && (respond_to? :allow_uri_read)
|
16
|
-
#opts[:fallback_font_name] = default_svg_font if !(opts.key? :fallback_font_name) && (respond_to? :default_svg_font)
|
17
|
-
if (opts.key? :fit) && (fit = opts.delete :fit) && !opts[:width] && !opts[:height]
|
18
|
-
svg (::File.read file), opts do |svg_doc|
|
19
|
-
max_width, max_height = fit
|
20
|
-
svg_doc.calculate_sizing requested_width: max_width if max_width && svg_doc.sizing.output_width != max_width
|
21
|
-
svg_doc.calculate_sizing requested_height: max_height if max_height && svg_doc.sizing.output_height > max_height
|
22
|
-
end
|
23
|
-
else
|
24
|
-
svg (::File.read file), opts
|
25
|
-
end
|
26
|
-
else
|
27
|
-
_initial_image file, opts
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
# Retrieve the intrinsic image dimensions for the specified path.
|
32
|
-
#
|
33
|
-
# Returns a Hash containing :width and :height keys that map to the image's
|
34
|
-
# intrinsic width and height values (in pixels)
|
35
|
-
def intrinsic_image_dimensions path, format
|
36
|
-
if format == 'svg'
|
37
|
-
img_obj = ::Prawn::SVG::Interface.new (::File.read path), self, {}
|
38
|
-
img_size = img_obj.document.sizing
|
39
|
-
{ width: img_size.output_width, height: img_size.output_height }
|
40
|
-
else
|
41
|
-
# NOTE build_image_object caches image data previously loaded
|
42
|
-
_, img_size = ::File.open(path, 'rb') {|fd| build_image_object fd }
|
43
|
-
{ width: img_size.width, height: img_size.height }
|
44
|
-
end
|
45
|
-
rescue
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
::Prawn::Document.extensions << Images
|
50
|
-
end
|
51
|
-
end
|
@@ -1,126 +0,0 @@
|
|
1
|
-
########################################################################
|
2
|
-
#
|
3
|
-
# This file was copied from roman-numerals and modified for use with
|
4
|
-
# Asciidoctor PDF.
|
5
|
-
#
|
6
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
7
|
-
# a copy of this software and associated documentation files (the
|
8
|
-
# "Software"), to deal in the Software without restriction, including
|
9
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
10
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
12
|
-
# the following conditions:
|
13
|
-
#
|
14
|
-
# The above copyright notice and this permission notice shall be
|
15
|
-
# included in all copies or substantial portions of the Software.
|
16
|
-
#
|
17
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
-
#
|
25
|
-
# Copyright (c) 2011 Andrew Vos
|
26
|
-
# Copyright (c) 2014 OpenDevise, Inc.
|
27
|
-
#
|
28
|
-
########################################################################
|
29
|
-
|
30
|
-
module Asciidoctor
|
31
|
-
module PDF
|
32
|
-
class RomanNumeral
|
33
|
-
BaseDigits = {
|
34
|
-
1 => 'I',
|
35
|
-
4 => 'IV',
|
36
|
-
5 => 'V',
|
37
|
-
9 => 'IX',
|
38
|
-
10 => 'X',
|
39
|
-
40 => 'XL',
|
40
|
-
50 => 'L',
|
41
|
-
90 => 'XC',
|
42
|
-
100 => 'C',
|
43
|
-
400 => 'CD',
|
44
|
-
500 => 'D',
|
45
|
-
900 => 'CM',
|
46
|
-
1000 => 'M'
|
47
|
-
}
|
48
|
-
|
49
|
-
def initialize initial_value, letter_case = nil
|
50
|
-
initial_value ||= 1
|
51
|
-
if ::Integer === initial_value
|
52
|
-
@integer_value = initial_value
|
53
|
-
else
|
54
|
-
@integer_value = RomanNumeral.roman_to_int initial_value
|
55
|
-
letter_case = :lower if letter_case.nil? && initial_value.upcase != initial_value
|
56
|
-
end
|
57
|
-
@letter_case = letter_case.nil? ? :upper : letter_case
|
58
|
-
end
|
59
|
-
|
60
|
-
def to_s
|
61
|
-
to_r
|
62
|
-
end
|
63
|
-
|
64
|
-
def to_r
|
65
|
-
if (int = @integer_value) < 1
|
66
|
-
return int.to_s
|
67
|
-
end
|
68
|
-
roman = RomanNumeral.int_to_roman int
|
69
|
-
@letter_case == :lower ? roman.downcase : roman
|
70
|
-
end
|
71
|
-
|
72
|
-
def to_i
|
73
|
-
@integer_value
|
74
|
-
end
|
75
|
-
|
76
|
-
def odd?
|
77
|
-
to_i.odd?
|
78
|
-
end
|
79
|
-
|
80
|
-
def even?
|
81
|
-
to_i.even?
|
82
|
-
end
|
83
|
-
|
84
|
-
def next
|
85
|
-
RomanNumeral.new @integer_value + 1, @letter_case
|
86
|
-
end
|
87
|
-
|
88
|
-
def next!
|
89
|
-
@integer_value += 1
|
90
|
-
self
|
91
|
-
end
|
92
|
-
|
93
|
-
def pred
|
94
|
-
RomanNumeral.new @integer_value - 1, @letter_case
|
95
|
-
end
|
96
|
-
|
97
|
-
def empty?
|
98
|
-
false
|
99
|
-
end
|
100
|
-
|
101
|
-
def self.int_to_roman value
|
102
|
-
result = []
|
103
|
-
BaseDigits.keys.reverse_each do |ival|
|
104
|
-
while value >= ival
|
105
|
-
value -= ival
|
106
|
-
result << BaseDigits[ival]
|
107
|
-
end
|
108
|
-
end
|
109
|
-
result.join
|
110
|
-
end
|
111
|
-
|
112
|
-
def self.roman_to_int value
|
113
|
-
value = value.upcase
|
114
|
-
result = 0
|
115
|
-
BaseDigits.values.reverse_each do |rval|
|
116
|
-
while value.start_with? rval
|
117
|
-
offset = rval.length
|
118
|
-
value = value[offset..offset]
|
119
|
-
result += BaseDigits.key rval
|
120
|
-
end
|
121
|
-
end
|
122
|
-
result
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
@@ -1,175 +0,0 @@
|
|
1
|
-
module Rouge
|
2
|
-
module Formatters
|
3
|
-
# Transforms a token stream into an array of
|
4
|
-
# formatted text fragments for use with Prawn.
|
5
|
-
class Prawn < Formatter
|
6
|
-
tag 'prawn'
|
7
|
-
|
8
|
-
Tokens = ::Rouge::Token::Tokens
|
9
|
-
LineOrientedTokens = [
|
10
|
-
::Rouge::Token::Tokens::Generic::Inserted,
|
11
|
-
::Rouge::Token::Tokens::Generic::Deleted,
|
12
|
-
::Rouge::Token::Tokens::Generic::Heading,
|
13
|
-
::Rouge::Token::Tokens::Generic::Subheading
|
14
|
-
]
|
15
|
-
|
16
|
-
LF = ?\n
|
17
|
-
NoBreakSpace = ?\u00a0
|
18
|
-
InnerIndent = %(#{LF} )
|
19
|
-
GuardedIndent = NoBreakSpace
|
20
|
-
GuardedInnerIndent = %(#{LF}#{NoBreakSpace})
|
21
|
-
BoldStyle = [:bold].to_set
|
22
|
-
ItalicStyle = [:italic].to_set
|
23
|
-
BoldItalicStyle = [:bold, :italic].to_set
|
24
|
-
UnderlineStyle = [:underline].to_set
|
25
|
-
|
26
|
-
def initialize opts = {}
|
27
|
-
unless ::Rouge::Theme === (theme = opts[:theme])
|
28
|
-
unless theme && (theme = ::Rouge::Theme.find theme)
|
29
|
-
theme = ::Rouge::Themes::AsciidoctorPDFDefault
|
30
|
-
end
|
31
|
-
theme = theme.new
|
32
|
-
end
|
33
|
-
@theme = theme
|
34
|
-
@normalized_colors = {}
|
35
|
-
@background_colorizer = BackgroundColorizer.new line_gap: opts[:line_gap]
|
36
|
-
@linenum_fragment_base = (create_fragment Tokens::Generic::Lineno).merge linenum: true
|
37
|
-
end
|
38
|
-
|
39
|
-
def background_color
|
40
|
-
@background_color ||= normalize_color((@theme.style_for Tokens::Text).bg)
|
41
|
-
end
|
42
|
-
|
43
|
-
# Override format method so fragments don't get flatted to a string
|
44
|
-
# and to add an options Hash.
|
45
|
-
def format tokens, opts = {}
|
46
|
-
stream tokens, opts
|
47
|
-
end
|
48
|
-
|
49
|
-
def stream tokens, opts = {}
|
50
|
-
if opts[:line_numbers]
|
51
|
-
if (linenum = opts[:start_line]) > 0
|
52
|
-
linenum -= 1
|
53
|
-
else
|
54
|
-
linenum = 0
|
55
|
-
end
|
56
|
-
fragments = []
|
57
|
-
fragments << (create_linenum_fragment linenum += 1)
|
58
|
-
tokens.each do |tok, val|
|
59
|
-
if val == LF
|
60
|
-
fragments << { text: LF }
|
61
|
-
fragments << (create_linenum_fragment linenum += 1)
|
62
|
-
elsif val.include? LF
|
63
|
-
# NOTE we assume if the fragment ends in a line feed, the intention was to match a line-oriented form
|
64
|
-
line_oriented = val.end_with? LF
|
65
|
-
base_fragment = create_fragment tok, val
|
66
|
-
val.each_line do |line|
|
67
|
-
fragments << (line_oriented ? (base_fragment.merge text: line, line_oriented: true) : (base_fragment.merge text: line))
|
68
|
-
# NOTE append linenum fragment if there's a next line; only works if source doesn't have trailing endline
|
69
|
-
fragments << (create_linenum_fragment linenum += 1) if line.end_with? LF
|
70
|
-
end
|
71
|
-
else
|
72
|
-
fragments << (create_fragment tok, val)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
# NOTE drop orphaned linenum fragment (due to trailing endline in source)
|
76
|
-
fragments.pop if (last_fragment = fragments[-1]) && last_fragment[:linenum]
|
77
|
-
# NOTE pad numbers that have less digits than the largest line number
|
78
|
-
if (linenum_w = linenum.to_s.length) > 1
|
79
|
-
# NOTE extra column is the trailing space after the line number
|
80
|
-
linenum_w += 1
|
81
|
-
fragments.each do |fragment|
|
82
|
-
fragment[:text] = %(#{fragment[:text].rjust linenum_w, NoBreakSpace}) if fragment[:linenum]
|
83
|
-
end
|
84
|
-
end
|
85
|
-
fragments
|
86
|
-
else
|
87
|
-
start_of_line = true
|
88
|
-
tokens.map do |tok, val|
|
89
|
-
# match one or more consecutive endlines
|
90
|
-
if val == LF || (val == (LF * val.length))
|
91
|
-
start_of_line = true
|
92
|
-
{ text: val }
|
93
|
-
else
|
94
|
-
val[0] = GuardedIndent if start_of_line && (val.start_with? ' ')
|
95
|
-
val.gsub! InnerIndent, GuardedInnerIndent if val.include? InnerIndent
|
96
|
-
# QUESTION do we need the call to create_fragment if val contains only spaces? consider bg
|
97
|
-
#fragment = create_fragment tok, val
|
98
|
-
fragment = val.rstrip.empty? ? { text: val } : (create_fragment tok, val)
|
99
|
-
# NOTE we assume if the fragment ends in a line feed, the intention was to match a line-oriented form
|
100
|
-
fragment[:line_oriented] = true if (start_of_line = val.end_with? LF)
|
101
|
-
fragment
|
102
|
-
end
|
103
|
-
end
|
104
|
-
# QUESTION should we strip trailing newline?
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
# TODO method could still be optimized (for instance, check if val is LF or empty)
|
109
|
-
def create_fragment tok, val = nil
|
110
|
-
fragment = val ? { text: val } : {}
|
111
|
-
if (style_rules = @theme.style_for tok)
|
112
|
-
if (bg = normalize_color style_rules.bg) && bg != @background_color
|
113
|
-
fragment[:background_color] = bg
|
114
|
-
fragment[:callback] = @background_colorizer
|
115
|
-
if LineOrientedTokens.include? tok
|
116
|
-
fragment[:inline_block] = true unless style_rules[:inline_block] == false
|
117
|
-
fragment[:extend] = true unless style_rules[:extend] == false
|
118
|
-
else
|
119
|
-
fragment[:inline_block] = true if style_rules[:inline_block]
|
120
|
-
fragment[:extend] = true if style_rules[:extend]
|
121
|
-
end
|
122
|
-
end
|
123
|
-
if (fg = normalize_color style_rules.fg)
|
124
|
-
fragment[:color] = fg
|
125
|
-
end
|
126
|
-
if style_rules[:bold]
|
127
|
-
fragment[:styles] = style_rules[:italic] ? BoldItalicStyle.dup : BoldStyle.dup
|
128
|
-
elsif style_rules[:italic]
|
129
|
-
fragment[:styles] = ItalicStyle.dup
|
130
|
-
end
|
131
|
-
if style_rules[:underline]
|
132
|
-
if fragment.key? :styles
|
133
|
-
fragment[:styles] << UnderlineStyle[0]
|
134
|
-
else
|
135
|
-
fragment[:styles] = UnderlineStyle.dup
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
fragment
|
140
|
-
end
|
141
|
-
|
142
|
-
def create_linenum_fragment linenum
|
143
|
-
@linenum_fragment_base.merge text: %(#{linenum} )
|
144
|
-
end
|
145
|
-
|
146
|
-
def normalize_color raw
|
147
|
-
return unless raw
|
148
|
-
if (normalized = @normalized_colors[raw])
|
149
|
-
normalized
|
150
|
-
else
|
151
|
-
normalized = (raw.start_with? '#') ? raw[1..-1] : raw
|
152
|
-
normalized = normalized.each_char.map {|c| c * 2 }.join if normalized.length == 3
|
153
|
-
@normalized_colors[raw] = normalized
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
class BackgroundColorizer
|
159
|
-
def initialize opts = {}
|
160
|
-
@line_gap = opts[:line_gap] || 0
|
161
|
-
end
|
162
|
-
|
163
|
-
def render_behind fragment
|
164
|
-
pdf = fragment.document
|
165
|
-
data = fragment.format_state
|
166
|
-
prev_fill_color = pdf.fill_color
|
167
|
-
pdf.fill_color data[:background_color]
|
168
|
-
v_gap = data[:inline_block] ? @line_gap : 0
|
169
|
-
fragment_width = data[:line_oriented] && data[:extend] ? (pdf.bounds.width - fragment.left) : fragment.width
|
170
|
-
pdf.fill_rectangle [fragment.left, fragment.top + v_gap * 0.5], fragment_width, (fragment.height + v_gap)
|
171
|
-
pdf.fill_color prev_fill_color
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module Rouge
|
2
|
-
module Themes
|
3
|
-
# A port of the bw style from Pygments.
|
4
|
-
# See https://bitbucket.org/birkenfeld/pygments-main/src/default/pygments/styles/bw.py
|
5
|
-
class BlackWhiteTheme < CSSTheme
|
6
|
-
name 'bw'
|
7
|
-
|
8
|
-
style Text, fg: '#000000', bg: '#ffffff'
|
9
|
-
|
10
|
-
style Comment, italic: true
|
11
|
-
style Comment::Preproc, italic: false
|
12
|
-
|
13
|
-
style Keyword, bold: true
|
14
|
-
style Keyword::Pseudo, bold: false
|
15
|
-
style Keyword::Type, bold: false
|
16
|
-
|
17
|
-
style Operator, bold: true
|
18
|
-
|
19
|
-
style Name::Class, bold: true
|
20
|
-
style Name::Namespace, bold: true
|
21
|
-
style Name::Exception, bold: true
|
22
|
-
style Name::Entity, bold: true
|
23
|
-
style Name::Tag, bold: true
|
24
|
-
|
25
|
-
style Literal::String, italic: true
|
26
|
-
style Literal::String::Interpol, bold: true
|
27
|
-
style Literal::String::Escape, bold: true
|
28
|
-
|
29
|
-
style Generic::Heading, bold: true
|
30
|
-
style Generic::Subheading, bold: true
|
31
|
-
style Generic::Emph, italic: true
|
32
|
-
style Generic::Strong, bold: true
|
33
|
-
style Generic::Prompt, bold: true
|
34
|
-
|
35
|
-
style Error, fg: '#FF0000'
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,101 +0,0 @@
|
|
1
|
-
unless RUBY_VERSION >= '2.4'
|
2
|
-
begin
|
3
|
-
require 'unicode' unless defined? Unicode::VERSION
|
4
|
-
rescue LoadError
|
5
|
-
begin
|
6
|
-
require 'active_support/multibyte' unless defined? ActiveSupport::Multibyte
|
7
|
-
rescue LoadError; end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
module Asciidoctor
|
12
|
-
module PDF
|
13
|
-
module Sanitizer
|
14
|
-
XMLSpecialChars = {
|
15
|
-
'<' => ?<,
|
16
|
-
'>' => ?>,
|
17
|
-
'&' => ?&,
|
18
|
-
}
|
19
|
-
XMLSpecialCharsRx = /(?:#{XMLSpecialChars.keys * ?|})/
|
20
|
-
InverseXMLSpecialChars = XMLSpecialChars.invert
|
21
|
-
InverseXMLSpecialCharsRx = /[#{InverseXMLSpecialChars.keys.join}]/
|
22
|
-
(BuiltInNamedEntities = {
|
23
|
-
'amp' => ?&,
|
24
|
-
'apos' => ?',
|
25
|
-
'gt' => ?>,
|
26
|
-
'lt' => ?<,
|
27
|
-
'nbsp' => ' ',
|
28
|
-
'quot' => ?",
|
29
|
-
}).default = ??
|
30
|
-
SanitizeXMLRx = /<[^>]+>/
|
31
|
-
XMLMarkupRx = /&#?[a-z\d]+;|</
|
32
|
-
CharRefRx = /&(?:([a-z][a-z]+\d{0,2})|#(?:(\d\d\d{0,4})|x([a-f\d][a-f\d][a-f\d]{0,3})));/
|
33
|
-
SiftPCDATARx = /(&#?[a-z\d]+;|<[^>]+>)|([^&<]+)/
|
34
|
-
|
35
|
-
# Strip leading, trailing and repeating whitespace, remove XML tags and
|
36
|
-
# resolve all entities in the specified string.
|
37
|
-
#
|
38
|
-
# FIXME move to a module so we can mix it in elsewhere
|
39
|
-
# FIXME add option to control escaping entities, or a filter mechanism in general
|
40
|
-
def sanitize string
|
41
|
-
string.strip
|
42
|
-
.gsub(SanitizeXMLRx, '')
|
43
|
-
.tr_s(' ', ' ')
|
44
|
-
.gsub(CharRefRx) { $1 ? BuiltInNamedEntities[$1] : [$2 ? $2.to_i : ($3.to_i 16)].pack('U1') }
|
45
|
-
end
|
46
|
-
|
47
|
-
def escape_xml string
|
48
|
-
string.gsub InverseXMLSpecialCharsRx, InverseXMLSpecialChars
|
49
|
-
end
|
50
|
-
|
51
|
-
def encode_quotes string
|
52
|
-
(string.include? ?") ? (string.gsub ?", '"') : string
|
53
|
-
end
|
54
|
-
|
55
|
-
def uppercase_pcdata string
|
56
|
-
if XMLMarkupRx.match? string
|
57
|
-
string.gsub(SiftPCDATARx) { $2 ? (uppercase_mb $2) : $1 }
|
58
|
-
else
|
59
|
-
uppercase_mb string
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
if RUBY_VERSION >= '2.4'
|
64
|
-
def uppercase_mb string
|
65
|
-
string.upcase
|
66
|
-
end
|
67
|
-
|
68
|
-
def lowercase_mb string
|
69
|
-
string.downcase
|
70
|
-
end
|
71
|
-
# NOTE Unicode library is 4x as fast as ActiveSupport::MultiByte::Chars
|
72
|
-
elsif defined? ::Unicode
|
73
|
-
def uppercase_mb string
|
74
|
-
string.ascii_only? ? string.upcase : (::Unicode.upcase string)
|
75
|
-
end
|
76
|
-
|
77
|
-
def lowercase_mb string
|
78
|
-
string.ascii_only? ? string.downcase : (::Unicode.downcase string)
|
79
|
-
end
|
80
|
-
elsif defined? ::ActiveSupport::Multibyte
|
81
|
-
MultibyteChars = ::ActiveSupport::Multibyte::Chars
|
82
|
-
|
83
|
-
def uppercase_mb string
|
84
|
-
string.ascii_only? ? string.upcase : (MultibyteChars.new string).upcase.to_s
|
85
|
-
end
|
86
|
-
|
87
|
-
def lowercase_mb string
|
88
|
-
string.ascii_only? ? string.downcase : (MultibyteChars.new string).downcase.to_s
|
89
|
-
end
|
90
|
-
else
|
91
|
-
def uppercase_mb string
|
92
|
-
string.upcase
|
93
|
-
end
|
94
|
-
|
95
|
-
def lowercase_mb string
|
96
|
-
string.downcase
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|