Skip to content

Commit

Permalink
uppercase acronyms in constants
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed Apr 23, 2019
1 parent 6ef8740 commit ad3848a
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 25 deletions.
12 changes: 4 additions & 8 deletions lib/asciidoctor-pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ def convert_admonition node
elsif icons
if icon_path.end_with? '.svg'
begin
svg_obj = ::Prawn::Svg::Interface.new ::File.read(icon_path), self,
svg_obj = ::Prawn::SVG::Interface.new ::File.read(icon_path), self,
position: label_align,
vposition: label_valign,
width: label_width,
Expand Down Expand Up @@ -1210,7 +1210,7 @@ def convert_image node, opts = {}
svg_data = ::File.read image_path
file_request_root = ::File.dirname image_path
end
svg_obj = ::Prawn::Svg::Interface.new svg_data, self,
svg_obj = ::Prawn::SVG::Interface.new svg_data, self,
position: alignment,
width: width,
fallback_font_name: default_svg_font,
Expand Down Expand Up @@ -1465,11 +1465,7 @@ def convert_listing_or_literal node
conum_mapping ? (restore_conums fragments, conum_mapping) : fragments
else
# NOTE only format if we detect a need (callouts or inline formatting)
if XmlMarkupRx.match? source_string
text_formatter.format source_string
else
[{ text: source_string }]
end
(XMLMarkupRx.match? source_string) ? (text_formatter.format source_string) : [{ text: source_string }]
end

node.subs.replace prev_subs if prev_subs
Expand Down Expand Up @@ -2912,7 +2908,7 @@ def layout_running_content periphery, doc, opts = {}
begin
if (img_path = content[:path]).downcase.end_with? '.svg'
svg_data = ::File.read img_path
svg_obj = ::Prawn::Svg::Interface.new svg_data, self,
svg_obj = ::Prawn::SVG::Interface.new svg_data, self,
position: colspec[:align],
vposition: trim_img_valign,
width: content[:width],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def arrange_images fragments

# TODO make helper method to calculate width and height of image
if fragment[:image_format] == 'svg'
svg_obj = ::Prawn::Svg::Interface.new ::File.read(image_path), doc,
svg_obj = ::Prawn::SVG::Interface.new ::File.read(image_path), doc,
at: doc.bounds.top_left,
width: image_w,
fallback_font_name: doc.default_svg_font
Expand Down
4 changes: 2 additions & 2 deletions lib/asciidoctor-pdf/prawn-svg_ext.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'prawn-svg' unless defined? Prawn::Svg::VERSION
require 'prawn-svg' unless defined? Prawn::SVG::Interface
require_relative 'prawn-svg_ext/interface'
# NOTE disable system fonts since they're non-portable
Prawn::Svg::Interface.font_path.clear
Prawn::SVG::Interface.font_path.clear
4 changes: 2 additions & 2 deletions lib/asciidoctor-pdf/prawn-svg_ext/interface.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Prawn; module Svg
module Prawn; module SVG
class Interface
def resize opts = {}
sizing = document.sizing
Expand All @@ -7,4 +7,4 @@ def resize opts = {}
sizing.calculate
end
end
end; end unless Prawn::Svg::Interface.method_defined? :resize
end; end unless Prawn::SVG::Interface.method_defined? :resize
2 changes: 1 addition & 1 deletion lib/asciidoctor-pdf/prawn_ext/images.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def image file, opts = {}
# intrinsic width and height values (in pixels)
def intrinsic_image_dimensions path
if path.end_with? '.svg'
img_obj = ::Prawn::Svg::Interface.new ::File.read(path), self, {}
img_obj = ::Prawn::SVG::Interface.new ::File.read(path), self, {}
img_size = img_obj.document.sizing
{ width: img_size.output_width, height: img_size.output_height }
else
Expand Down
22 changes: 11 additions & 11 deletions lib/asciidoctor-pdf/sanitizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
module Asciidoctor
module PDF
module Sanitizer
XmlSpecialChars = {
XMLSpecialChars = {
'&lt;' => ?<,
'&gt;' => ?>,
'&amp;' => ?&,
}
XmlSpecialCharsRx = /(?:#{XmlSpecialChars.keys * ?|})/
InverseXmlSpecialChars = XmlSpecialChars.invert
InverseXmlSpecialCharsRx = /[#{InverseXmlSpecialChars.keys.join}]/
XMLSpecialCharsRx = /(?:#{XMLSpecialChars.keys * ?|})/
InverseXMLSpecialChars = XMLSpecialChars.invert
InverseXMLSpecialCharsRx = /[#{InverseXMLSpecialChars.keys.join}]/
(BuiltInNamedEntities = {
'amp' => ?&,
'apos' => ?',
Expand All @@ -27,10 +27,10 @@ module Sanitizer
'nbsp' => ' ',
'quot' => ?",
}).default = ??
XmlSanitizeRx = /<[^>]+>/
XmlMarkupRx = /&#?[a-z\d]+;|</
SanitizeXMLRx = /<[^>]+>/
XMLMarkupRx = /&#?[a-z\d]+;|</
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})));/
SiftPcdataRx = /(&#?[a-z\d]+;|<[^>]+>)|([^&<]+)/
SiftPCDATARx = /(&#?[a-z\d]+;|<[^>]+>)|([^&<]+)/

# Strip leading, trailing and repeating whitespace, remove XML tags and
# resolve all entities in the specified string.
Expand All @@ -39,22 +39,22 @@ module Sanitizer
# FIXME add option to control escaping entities, or a filter mechanism in general
def sanitize string
string.strip
.gsub(XmlSanitizeRx, '')
.gsub(SanitizeXMLRx, '')
.tr_s(' ', ' ')
.gsub(CharRefRx) { $1 ? BuiltInNamedEntities[$1] : [$2 ? $2.to_i : ($3.to_i 16)].pack('U1') }
end

def escape_xml string
string.gsub InverseXmlSpecialCharsRx, InverseXmlSpecialChars
string.gsub InverseXMLSpecialCharsRx, InverseXMLSpecialChars
end

def encode_quotes string
(string.include? ?") ? (string.gsub ?", '&quot;') : string
end

def uppercase_pcdata string
if XmlMarkupRx.match? string
string.gsub(SiftPcdataRx) { $2 ? (uppercase_mb $2) : $1 }
if XMLMarkupRx.match? string
string.gsub(SiftPCDATARx) { $2 ? (uppercase_mb $2) : $1 }
else
uppercase_mb string
end
Expand Down

0 comments on commit ad3848a

Please sign in to comment.