Class: IsoDoc::HtmlFunction::MathvariantToPlain

Inherits:
Object
  • Object
show all
Defined in:
lib/isodoc/html_function/mathvariant_to_plain.rb

Overview

Class for recursively converting mathvariant text into plain text symbols

Constant Summary collapse

MATHML =
{ "m" => "http://www.w3.org/1998/Math/MathML" }.freeze
MATHVARIANT_SPECIAL_CASE_MAPPINGS_1 =
%w[bold italic sans-serif]
.permutation
.each_with_object(:sansbolditalic)
.map { |n, y| [n, y] }
.to_h
.freeze
MATHVARIANT_SPECIAL_CASE_MAPPINGS_2 =
{
  %w[bold fraktur] => :frakturbold,
  %w[bold script] => :scriptbold,
  %w[sans-serif bold] => :sansbold,
  %w[sans-serif italic] => :sansitalic,
  %w[sans-serif bold-italic] => :sansbolditalic,
  %w[bold-sans-serif italic] => :sansbolditalic,
  %w[sans-serif-italic bold] => :sansbolditalic,
}.freeze
MATHVARIANT_TO_PLANE_MAPPINGS =
{
  %w[double-struck] => :doublestruck,
  %w[bold-fraktur] => :frakturbold,
  %w[script] => :script,
  %w[bold-script] => :scriptbold,
  %w[fraktur] => :fraktur,
  %w[sans-serif] => :sans,
  %w[bold-sans-serif] => :sansbold,
  %w[sans-serif-italic] => :sansitalic,
  %w[sans-serif-bold-italic] => :sansbolditalic,
  %w[monospace] => :monospace,
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(docxml) ⇒ MathvariantToPlain

Returns a new instance of MathvariantToPlain.

Parameters:

  • docxml (Nokogiri::Document)


37
38
39
# File 'lib/isodoc/html_function/mathvariant_to_plain.rb', line 37

def initialize(docxml)
  @docxml = docxml
end

Instance Attribute Details

#docxmlObject (readonly)

Returns the value of attribute docxml.



34
35
36
# File 'lib/isodoc/html_function/mathvariant_to_plain.rb', line 34

def docxml
  @docxml
end

Instance Method Details

#convertObject



41
42
43
44
45
46
47
48
# File 'lib/isodoc/html_function/mathvariant_to_plain.rb', line 41

def convert
  docxml.xpath("//m:math", MATHML).each do |elem|
    next if nothing_to_style(elem)

    mathml1(elem)
  end
  docxml
end