Skip to content

Commit

Permalink
no space around asciimath
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Mar 18, 2023
1 parent f35c3d0 commit c30ca6f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/html2doc/math.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Html2Doc
def asciimath_to_mathml1(expr, retain_asciimath)
ret = Plurimath::Math.parse(HTMLEntities.new.decode(expr), "asciimath").to_mathml
.gsub(/<math>/, "<math xmlns='http://www.w3.org/1998/Math/MathML'>")
.gsub(/<math>/, "<math xmlns='http://www.w3.org/1998/Math/MathML'>").strip
retain_asciimath and
ret += "<asciimath>#{@c.encode(@c.decode(expr), :basic)}</asciimath>"
ret
Expand Down
2 changes: 1 addition & 1 deletion lib/html2doc/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class Html2Doc
VERSION = "1.5.1".freeze
VERSION = "1.5.2".freeze
end
31 changes: 11 additions & 20 deletions spec/html2doc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,10 @@ def image_clean(xml)
encoding: "utf-8")))
.to match_fuzzy(<<~OUTPUT)
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
#{word_body(%{<div>
<m:oMath>
#{word_body(%{<div><m:oMath>
<m:nary><m:naryPr><m:chr m:val="&#x2211;"></m:chr><m:limLoc m:val="undOvr"></m:limLoc><m:grow m:val="on"></m:grow><m:subHide m:val="off"></m:subHide><m:supHide m:val="off"></m:supHide></m:naryPr><m:sub><m:r><m:t>i=1</m:t></m:r></m:sub><m:sup><m:r><m:t>n</m:t></m:r></m:sup><m:e><m:sSup><m:e><m:r><m:t>i</m:t></m:r></m:e><m:sup><m:r><m:t>3</m:t></m:r></m:sup></m:sSup></m:e></m:nary><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>=</m:t></m:r></span><m:sSup><m:e><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>(</m:t></m:r></span><m:f><m:fPr><m:type m:val="bar"></m:type></m:fPr><m:num><m:r><m:t>n</m:t></m:r><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>(</m:t></m:r></span><m:r><m:t>n+1)</m:t></m:r></m:num><m:den><m:r><m:t>2</m:t></m:r></m:den></m:f><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>)</m:t></m:r></span></m:e><m:sup><m:r><m:t>2</m:t></m:r></m:sup></m:sSup><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>)</m:t></m:r></span>
</m:oMath>
</div> }, '<div style="mso-element:footnote-list"/>')}
</div>}, '<div style="mso-element:footnote-list"/>')}
#{WORD_FTR1}
OUTPUT
end
Expand All @@ -432,8 +431,7 @@ def image_clean(xml)
x = Html2Doc.new({})
.asciimath_to_mathml(input, ["{{", "}}"], retain_asciimath: true)
expect(x).to match_fuzzy(<<~OUTPUT)
abc
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
abc<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mstyle displaystyle="true">
<munderover>
<mo>&#x2211;</mo>
Expand Down Expand Up @@ -472,16 +470,13 @@ def image_clean(xml)
<mtext>"integer"</mtext>
<mo>)</mo>
</mstyle>
</math>
<asciimath>sum_(i=1)^n i^3=((n(n+1))/2)^2 text(&quot;integer&quot;))</asciimath>def
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
</math><asciimath>sum_(i=1)^n i^3=((n(n+1))/2)^2 text(&quot;integer&quot;))</asciimath>def<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mstyle displaystyle="true">
<mi>x</mi>
<mo>&#x3c;</mo>
<mi>y</mi>
</mstyle>
</math>
<asciimath>x&lt;y</asciimath>ghi
</math><asciimath>x&lt;y</asciimath>ghi
OUTPUT
end

Expand All @@ -492,8 +487,7 @@ def image_clean(xml)
.to match_fuzzy(<<~OUTPUT)
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
#{word_body(%{
<div>
<m:oMath>
<div><m:oMath>
<span style="font-style:normal;font-weight:bold;"><m:r><m:rPr><m:sty m:val="b"></m:sty></m:rPr><m:t>&#x2212;</m:t></m:r></span><m:sSubSup><m:e><span style="font-style:normal;font-weight:bold;"><m:r><m:rPr><m:sty m:val="b"></m:sty></m:rPr><m:t>log</m:t></m:r></span></m:e><m:sub><span style="font-style:normal;font-weight:bold;"><m:r><m:rPr><m:sty m:val="b"></m:sty></m:rPr><m:t>2</m:t></m:r></span></m:sub><m:sup></m:sup></m:sSubSup><span style="font-style:normal;font-weight:bold;"><m:r><m:rPr><m:sty m:val="b"></m:sty></m:rPr><m:t>(</m:t></m:r></span><m:sSub><m:e><span style="font-style:normal;font-weight:bold;"><m:r><m:rPr><m:sty m:val="b"></m:sty></m:rPr><m:t>p</m:t></m:r></span></m:e><m:sub><span style="font-style:normal;font-weight:bold;"><m:r><m:rPr><m:sty m:val="b"></m:sty></m:rPr><m:t>u</m:t></m:r></span></m:sub></m:sSub><span style="font-style:normal;font-weight:bold;"><m:r><m:rPr><m:sty m:val="b"></m:sty></m:rPr><m:t>)</m:t></m:r></span><span style="font-style:normal;font-weight:bold;"><m:r><m:rPr><m:nor></m:nor><m:sty m:val="b"></m:sty></m:rPr><m:t>BB</m:t></m:r></span><m:r><m:rPr><m:nor></m:nor><m:scr m:val="double-struck"></m:scr><m:sty m:val="p"></m:sty></m:rPr><m:t>&#x1D539;&#x1D539;&#x1D539;</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="script"></m:scr></m:rPr><m:t>&#x1D49E;&#x1D49E;</m:t></m:r><m:r><m:t>b</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="script"></m:scr></m:rPr><m:t>&#x212C;&#x1D49E;&#x1D49E;</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="monospace"></m:scr><m:sty m:val="p"></m:sty></m:rPr><m:t>&#x1D683;&#x1D683;</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="fraktur"></m:scr><m:sty m:val="p"></m:sty></m:rPr><m:t>&#x1D509;&#x211C;</m:t></m:r><m:r><m:t>b</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="fraktur"></m:scr><m:sty m:val="p"></m:sty></m:rPr><m:t>&#x1D505;&#x1D509;&#x211C;</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="sans-serif"></m:scr><m:sty m:val="p"></m:sty></m:rPr><m:t>&#x1D5B2;&#x1D5A5;</m:t></m:r><m:r><m:t>b</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="sans-serif"></m:scr><m:sty m:val="p"></m:sty></m:rPr><m:t>&#x1D5A1;&#x1D5B2;&#x1D5A5;&#x3B1;</m:t></m:r><m:r><m:rPr><m:scr m:val="sans-serif"></m:scr><m:sty m:val="p"></m:sty></m:rPr><m:t>&#x1D5C2;</m:t></m:r><m:r><m:rPr><m:nor></m:nor></m:rPr><m:t>SFI</m:t></m:r><m:r><m:rPr><m:scr m:val="sans-serif"></m:scr><m:sty m:val="p"></m:sty></m:rPr><m:t>&#x1D5BB;</m:t></m:r><m:r><m:t>i</m:t></m:r><m:r><m:rPr><m:nor></m:nor></m:rPr><m:t>SFBI&#x3B1;</m:t></m:r><m:r><m:t>b</m:t></m:r><span class="nostem"><em></em><m:r><m:rPr><m:nor></m:nor><m:sty m:val="i"></m:sty></m:rPr><m:t>BII</m:t></m:r></span><span class="nostem"><em></em><m:r><m:rPr><m:nor></m:nor><m:sty m:val="i"></m:sty></m:rPr><m:t>II</m:t></m:r></span>
</m:oMath>
</div>}, '<div style="mso-element:footnote-list"/>')}
Expand All @@ -508,8 +502,7 @@ def image_clean(xml)
.to match_fuzzy(<<~OUTPUT)
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
#{word_body('
<div>
<m:oMath>
<div><m:oMath>
<m:r><m:rPr><m:nor></m:nor></m:rPr><m:t>" integer "</m:t></m:r>
</m:oMath>
</div>', '<div style="mso-element:footnote-list"/>')}
Expand Down Expand Up @@ -555,11 +548,10 @@ def image_clean(xml)
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
.to match_fuzzy(<<~OUTPUT)
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
#{word_body(%{<div style="text-align:left;">
<m:oMath>
#{word_body(%{<div style="text-align:left;"><m:oMathPara><m:oMathParaPr><m:jc m:val="left"/></m:oMathParaPr><m:oMath>
<m:nary><m:naryPr><m:chr m:val="&#x2211;"></m:chr><m:limLoc m:val="undOvr"></m:limLoc><m:grow m:val="on"></m:grow><m:subHide m:val="off"></m:subHide><m:supHide m:val="off"></m:supHide></m:naryPr><m:sub><m:r><m:t>i=1</m:t></m:r></m:sub><m:sup><m:r><m:t>n</m:t></m:r></m:sup><m:e><m:sSup><m:e><m:r><m:t>i</m:t></m:r></m:e><m:sup><m:r><m:t>3</m:t></m:r></m:sup></m:sSup></m:e></m:nary><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>=</m:t></m:r></span><m:sSup><m:e><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>(</m:t></m:r></span><m:f><m:fPr><m:type m:val="bar"></m:type></m:fPr><m:num><m:r><m:t>n</m:t></m:r><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>(</m:t></m:r></span><m:r><m:t>n+1)</m:t></m:r></m:num><m:den><m:r><m:t>2</m:t></m:r></m:den></m:f><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>)</m:t></m:r></span></m:e><m:sup><m:r><m:t>2</m:t></m:r></m:sup></m:sSup>
</m:oMath>
</div>}, '<div style="mso-element:footnote-list"/>')}
</m:oMathPara></div>}, '<div style="mso-element:footnote-list"/>')}
#{WORD_FTR1}
OUTPUT
end
Expand All @@ -572,11 +564,10 @@ def image_clean(xml)
encoding: "utf-8")))
.to match_fuzzy(<<~OUTPUT)
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
#{word_body(%{<div style="text-align:right;">
<m:oMath>
#{word_body(%{<div style="text-align:right;"><m:oMathPara><m:oMathParaPr><m:jc m:val="right"/></m:oMathParaPr><m:oMath>
<m:nary><m:naryPr><m:chr m:val="&#x2211;"></m:chr><m:limLoc m:val="undOvr"></m:limLoc><m:grow m:val="on"></m:grow><m:subHide m:val="off"></m:subHide><m:supHide m:val="off"></m:supHide></m:naryPr><m:sub><m:r><m:t>i=1</m:t></m:r></m:sub><m:sup><m:r><m:t>n</m:t></m:r></m:sup><m:e><m:sSup><m:e><m:r><m:t>i</m:t></m:r></m:e><m:sup><m:r><m:t>3</m:t></m:r></m:sup></m:sSup></m:e></m:nary><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>=</m:t></m:r></span><m:sSup><m:e><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>(</m:t></m:r></span><m:f><m:fPr><m:type m:val="bar"></m:type></m:fPr><m:num><m:r><m:t>n</m:t></m:r><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>(</m:t></m:r></span><m:r><m:t>n+1)</m:t></m:r></m:num><m:den><m:r><m:t>2</m:t></m:r></m:den></m:f><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>)</m:t></m:r></span></m:e><m:sup><m:r><m:t>2</m:t></m:r></m:sup></m:sSup>
</m:oMath>
</div>}, '<div style="mso-element:footnote-list"/>')}
</m:oMathPara></div>}, '<div style="mso-element:footnote-list"/>')}
#{WORD_FTR1}
OUTPUT
end
Expand Down

0 comments on commit c30ca6f

Please sign in to comment.