Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom-charset for Private Use character codepoints: https://github.c… #541

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/isodoc/presentation_function/inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,28 @@ def date1(elem)
elem.replace(@i18n.date(elem["value"], elem["format"].strip))
end

def inline_format(docxml)
custom_charset(docxml)
end

def custom_charset(docxml)
charsets = extract_custom_charsets(docxml)
docxml.xpath(ns("//span[@custom-charset]")).each do |s|
s["style"] ||= ""
s["style"] += ";font-family:#{charsets[s['custom-charset']]}"
end
end

private

def extract_custom_charsets(docxml)
docxml.xpath(ns("//presentation-metadata/custom-charset-font")).
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Place the . on the next line, together with the method name.

each_with_object({}) do |x, m|
kv = x.text.split(":", 2)
m[kv[0]] = kv[1]
end
end

def found_matching_variant_sibling(node)
prev = node.xpath("./preceding-sibling::xmlns:variant")
foll = node.xpath("./following-sibling::xmlns:variant")
Expand Down
1 change: 1 addition & 0 deletions lib/isodoc/presentation_xml_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def inline(docxml)
variant docxml
identifier docxml
date docxml
inline_format docxml
end

def terms(docxml)
Expand Down
28 changes: 28 additions & 0 deletions spec/isodoc/presentation_xml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1839,6 +1839,34 @@
.to be_equivalent_to (presxml)
end

it "realises custom charsets" do
input = <<~INPUT
<standard-document xmlns="https://www.metanorma.org/ns/standoc" type="semantic">
<presentation-metadata><custom-charset-font>weather:"OGC Weather Symbols"</custom-charset-font></presentation-metadata>
<presentation-metadata><custom-charset-font>conscript:"Code 2000"</custom-charset-font></presentation-metadata>
<preface>
<foreword id="A">
<p id="_214f7090-c6d4-8fdc-5e6a-837ebb515871"><span custom-charset="weather">ﶀ</span></p>
</foreword></preface></standard-document>
INPUT
presxml = <<~OUTPUT
<standard-document xmlns="https://www.metanorma.org/ns/standoc" type="presentation">
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 2 spaces for indentation in a heredoc.

<presentation-metadata><custom-charset-font>weather:"OGC Weather Symbols"</custom-charset-font></presentation-metadata>
<presentation-metadata><custom-charset-font>conscript:"Code 2000"</custom-charset-font></presentation-metadata>
<preface><clause type="toc" id="_" displayorder="1"><title depth="1">Table of contents</title></clause>

<foreword id="A" displayorder="2">
<p id="_"><span custom-charset="weather" style=";font-family:&quot;OGC Weather Symbols&quot;">&#xFD80;</span></p>
</foreword></preface></standard-document>
OUTPUT
expect(strip_guid(IsoDoc::PresentationXMLConvert
.new(presxml_options)
.convert("test", input, true))
.sub(%r{<localized-strings>.*</localized-strings>}m, ""))
.to be_equivalent_to (presxml)
end


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line detected.

private

def mock_symbols
Expand Down