diff --git a/lib/isodoc/presentation_function/inline.rb b/lib/isodoc/presentation_function/inline.rb index c7f95098..f9467b0a 100644 --- a/lib/isodoc/presentation_function/inline.rb +++ b/lib/isodoc/presentation_function/inline.rb @@ -102,6 +102,43 @@ def date1(elem) def inline_format(docxml) custom_charset(docxml) + text_transform(docxml) + end + + def text_transform(docxml) + docxml.xpath(ns("//span[contains(@style, 'text-transform')]")).each do |s| + text_transform1(s) + end + end + + def text_transform1(span) + m = span["style"].split(/;\s*/) + i = m.index { |x| /^text-transform/.match?(x) } + value = m[i].sub(/^text-transform:/, "") + change_case(span, value, true) + m[i] = "text-transform:none" + span["style"] = m.join(";") + end + + def change_case(span, value, seen_space) + span.traverse do |s| + s.text? or next + case value + when "uppercase" then s.replace s.text.upcase + when "lowercase" then s.replace s.text.downcase + when "capitalize" + s.replace conditional_capitalize(s.text, seen_space) + end + seen_space = /\s$/.match?(s.text) + end + end + + def conditional_capitalize(text, seen_space) + m = text.split(/(?<=\s)/) + ((seen_space ? 0 : 1)...m.size).each do |i| + m[i] = m[i].capitalize + end + m.join end def custom_charset(docxml) diff --git a/spec/isodoc/presentation_xml_spec.rb b/spec/isodoc/presentation_xml_spec.rb index 14b44f4d..4f86f1f0 100644 --- a/spec/isodoc/presentation_xml_spec.rb +++ b/spec/isodoc/presentation_xml_spec.rb @@ -1488,6 +1488,41 @@ .to be_equivalent_to (presxml) end + it "realises text-transform" do + input = <<~INPUT + + + +

+ ABCDaBc + abc + ABC + abc abc + abc abc +

+
+ INPUT + presxml = <<~OUTPUT + + Table of contents + + +

+ ABCDABC + ABC + abc + Abc Abc + Abc Abc +

+
+ OUTPUT + expect(strip_guid(IsoDoc::PresentationXMLConvert + .new(presxml_options) + .convert("test", input, true)) + .sub(%r{.*}m, "")) + .to be_equivalent_to (presxml) + end + it "supplies formats in passthrough" do input = <<~INPUT