html2doc 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/html2doc/math.rb +28 -3
- data/lib/html2doc/mml2omml.xsl +26 -6
- data/lib/html2doc/version.rb +1 -1
- data/spec/html2doc_spec.rb +20 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6616c37575b4bd09b8b7bf7a89beffece7388f3e2a4039610825a030ffb72318
|
4
|
+
data.tar.gz: f29a3348e0b9260c4178af9a7f939e8ec39c2401cdc321346e5a6321e862cbad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4dee0b6541178293833caf2d55e1ec382ea16692b4efe4455ff0fd627e89ef5e67be747248cefd6c56ff151d8f9ea46f54633241d90996055e3574604eed175e
|
7
|
+
data.tar.gz: da5201fa1568f34e0638947d6dcfb5df1b7cf4303de1f74323122fcf92f6060cc7d5ddcc483cbfbfcb70798d12afc95c89b48d0274a34114fd8b18d7c1d58692
|
data/lib/html2doc/math.rb
CHANGED
@@ -27,15 +27,40 @@ module Html2Doc
|
|
27
27
|
|
28
28
|
# random fixes to MathML input that OOXML needs to render properly
|
29
29
|
def self.ooxml_cleanup(m, docnamespaces)
|
30
|
+
m = mathml_preserve_space(mathml_insert_rows(m, docnamespaces), docnamespaces)
|
31
|
+
m.add_namespace(nil, "http://www.w3.org/1998/Math/MathML")
|
32
|
+
m
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.mathml_insert_rows(m, docnamespaces)
|
30
36
|
m.xpath(%w(msup msub msubsup munder mover munderover).
|
31
37
|
map { |m| ".//xmlns:#{m}" }.join(" | "), docnamespaces).each do |x|
|
32
38
|
next unless x.next_element && x.next_element != "mrow"
|
33
39
|
x.next_element.wrap("<mrow/>")
|
34
40
|
end
|
41
|
+
m
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.mathml_preserve_space(m, docnamespaces)
|
35
45
|
m.xpath(".//xmlns:mtext", docnamespaces).each do |x|
|
36
46
|
x.children = x.children.to_xml.gsub(/^\s/, " ").gsub(/\s$/, " ")
|
37
47
|
end
|
38
|
-
m
|
48
|
+
m
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.unitalic(m)
|
52
|
+
m.xpath(".//xmlns:r[xmlns:rPr/xmlns:sty[@m:val = 'p']]").each do |x|
|
53
|
+
x.wrap("<span style='font-style:normal;'></span>")
|
54
|
+
end
|
55
|
+
m.xpath(".//xmlns:r[xmlns:rPr/xmlns:sty[@m:val = 'bi']]").each do |x|
|
56
|
+
x.wrap("<span style='font-style:italic;font-weight:bold;'></span>")
|
57
|
+
end
|
58
|
+
m.xpath(".//xmlns:r[xmlns:rPr/xmlns:sty[@m:val = 'i']]").each do |x|
|
59
|
+
x.wrap("<span class='nostem'><em></em></span>")
|
60
|
+
end
|
61
|
+
m.xpath(".//xmlns:r[xmlns:rPr/xmlns:sty[@m:val = 'b']]").each do |x|
|
62
|
+
x.wrap("<span style='font-style:normal;font-weight:bold;'></span>")
|
63
|
+
end
|
39
64
|
m
|
40
65
|
end
|
41
66
|
|
@@ -48,10 +73,10 @@ module Html2Doc
|
|
48
73
|
element = ooxml_cleanup(x, docnamespaces)
|
49
74
|
doc = Nokogiri::XML::Document::new()
|
50
75
|
doc.root = element
|
51
|
-
ooxml = (esc_space(@xsltemplate.transform(doc))).to_s.
|
76
|
+
ooxml = (unitalic(esc_space(@xsltemplate.transform(doc)))).to_s.
|
52
77
|
gsub(/<\?[^>]+>\s*/, "").
|
53
78
|
gsub(/ xmlns(:[^=]+)?="[^"]+"/, "").
|
54
|
-
gsub(%r{<(/)?([a-z])}, "<\\1m:\\2")
|
79
|
+
gsub(%r{<(/)?(?!span)(?!em)([a-z])}, "<\\1m:\\2")
|
55
80
|
ooxml = uncenter(x, ooxml)
|
56
81
|
x.swap(ooxml)
|
57
82
|
end
|
data/lib/html2doc/mml2omml.xsl
CHANGED
@@ -878,9 +878,21 @@
|
|
878
878
|
</xsl:otherwise>
|
879
879
|
</xsl:choose>
|
880
880
|
</xsl:if>
|
881
|
-
|
881
|
+
</xsl:variable>
|
882
|
+
<!-- NN 20200831 https://github.com/metanorma/metanorma-nist/issues/155 Read in ancestor mstyle -->
|
883
|
+
<xsl:variable name="mathvariant2">
|
884
|
+
<xsl:choose>
|
885
|
+
<xsl:when test="$mathvariant=''">
|
886
|
+
<xsl:value-of select="$ndCur/ancestor::mml:mstyle[@mathvariant][1]/@mathvariant"/>
|
887
|
+
</xsl:when>
|
888
|
+
<xsl:otherwise>
|
889
|
+
<xsl:value-of select="$mathvariant"/>
|
890
|
+
</xsl:otherwise>
|
891
|
+
</xsl:choose>
|
892
|
+
</xsl:variable>
|
893
|
+
<!-- END NN -->
|
882
894
|
<xsl:call-template name="CreateMathRPR">
|
883
|
-
<xsl:with-param name="mathvariant" select="$
|
895
|
+
<xsl:with-param name="mathvariant" select="$mathvariant2"/>
|
884
896
|
<xsl:with-param name="fontstyle" select="$fontstyle"/>
|
885
897
|
<xsl:with-param name="fontweight" select="$fontweight"/>
|
886
898
|
<xsl:with-param name="ndCur" select="$ndCur"/>
|
@@ -905,7 +917,7 @@
|
|
905
917
|
<xsl:with-param name="fontweight" select="$fontweight"/>
|
906
918
|
<xsl:with-param name="ndCur" select="$ndCur"/>
|
907
919
|
</xsl:call-template>
|
908
|
-
|
920
|
+
</xsl:variable>
|
909
921
|
<xsl:if test="$fLit=1 or $fNor=1 or ($sFontCur!='italic' and $sFontCur!='')">
|
910
922
|
<rPr>
|
911
923
|
<xsl:if test="$fNor=1">
|
@@ -919,7 +931,7 @@
|
|
919
931
|
<xsl:with-param name="fNor" select="$fNor"/>
|
920
932
|
</xsl:call-template>
|
921
933
|
</rPr>
|
922
|
-
|
934
|
+
</xsl:if>
|
923
935
|
</xsl:template>
|
924
936
|
|
925
937
|
<!-- %%Template: GetFontCur
|
@@ -935,8 +947,10 @@
|
|
935
947
|
</xsl:when>
|
936
948
|
<xsl:when test="not($ndCur)">
|
937
949
|
<xsl:value-of select="'italic'"/>
|
938
|
-
|
939
|
-
|
950
|
+
</xsl:when>
|
951
|
+
<!--<xsl:when test="$ndCur/self::mml:mi and (string-length(normalize-space($ndCur)) <= 1) or $ndCur/self::mml:mn and string(number($ndCur/text()))!='NaN' or $ndCur/self::mml:mo">-->
|
952
|
+
<!-- https://github.com/metanorma/metanorma-nist/issues/155 : DO NOT italicise mml:mo -->
|
953
|
+
<xsl:when test="$ndCur/self::mml:mi and (string-length(normalize-space($ndCur)) <= 1) or $ndCur/self::mml:mn and string(number($ndCur/text()))!='NaN'">
|
940
954
|
|
941
955
|
<!-- The default for the above three cases is fontstyle=italic fontweight=normal.-->
|
942
956
|
<xsl:choose>
|
@@ -1000,6 +1014,12 @@
|
|
1000
1014
|
</sty>
|
1001
1015
|
</xsl:when>
|
1002
1016
|
<xsl:when test="$font='italic'">
|
1017
|
+
<!-- NN 20200901 https://github.com/metanorma/metanorma-itu/issues/173 italic needs to be added explicitly to mtext -->
|
1018
|
+
<xsl:if test="$fNor=1">
|
1019
|
+
<sty>
|
1020
|
+
<xsl:attribute name="m:val">i</xsl:attribute>
|
1021
|
+
</sty>
|
1022
|
+
</xsl:if>
|
1003
1023
|
</xsl:when>
|
1004
1024
|
<xsl:when test="$font='script'">
|
1005
1025
|
<scr>
|
data/lib/html2doc/version.rb
CHANGED
data/spec/html2doc_spec.rb
CHANGED
@@ -374,7 +374,21 @@ RSpec.describe Html2Doc do
|
|
374
374
|
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
375
375
|
#{word_body(%{
|
376
376
|
<div><m:oMath>
|
377
|
-
<m:nary><m:naryPr><m:chr m:val="∑"></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><m:r><m:t>=</m:t></m:r><m:sSup><m:e><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:f><m:fPr><m:type m:val="bar"></m:type></m:fPr><m:num><m:r><m:t>n</m:t></m:r><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:r><m:t>n+1</m:t></m:r></m:e></m:d></m:num><m:den><m:r><m:t>2</m:t></m:r></m:den></m:f></m:e></m:d></m:e><m:sup><m:r><m:t>2</m:t></m:r></m:sup></m:sSup><m:r><m:rPr><m:nor></m:nor></m:rPr><m:t>"integer"</m:t></m:r><m:r><m:t>)</m:t></m:r>
|
377
|
+
<m:nary><m:naryPr><m:chr m:val="∑"></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><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:f><m:fPr><m:type m:val="bar"></m:type></m:fPr><m:num><m:r><m:t>n</m:t></m:r><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:r><m:t>n+1</m:t></m:r></m:e></m:d></m:num><m:den><m:r><m:t>2</m:t></m:r></m:den></m:f></m:e></m:d></m:e><m:sup><m:r><m:t>2</m:t></m:r></m:sup></m:sSup><m:r><m:rPr><m:nor></m:nor></m:rPr><m:t>"integer"</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>
|
378
|
+
</m:oMath>
|
379
|
+
</div>}, '<div style="mso-element:footnote-list"/>')}
|
380
|
+
#{WORD_FTR1}
|
381
|
+
OUTPUT
|
382
|
+
end
|
383
|
+
|
384
|
+
it "processes mstyle" do
|
385
|
+
Html2Doc.process(html_input(%[<div>{{bb (-log_2 (p_u)) bb "AA" bbb "AA" cc "AA" tt "AA" fr "AA" sf "AA" ii "AA"}}</div>]), filename: "test", asciimathdelims: ["{{", "}}"])
|
386
|
+
expect(guid_clean(File.read("test.doc", encoding: "utf-8"))).
|
387
|
+
to match_fuzzy(<<~OUTPUT)
|
388
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
389
|
+
#{word_body(%{
|
390
|
+
<div><m:oMath>
|
391
|
+
<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>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:sSub><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><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></m:e></m:d><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>AA</m:t></m:r></span><span style="font-style:normal;"><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>AA</m:t></m:r></span><m:r><m:rPr><m:nor></m:nor><m:scr m:val="script"></m:scr></m:rPr><m:t>AA</m:t></m:r><m:r><m:rPr><m:nor></m:nor></m:rPr><m:t>AA</m:t></m:r><span style="font-style:normal;"><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>AA</m:t></m:r></span><span style="font-style:normal;"><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>AA</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>AA</m:t></m:r></span>
|
378
392
|
</m:oMath>
|
379
393
|
</div>}, '<div style="mso-element:footnote-list"/>')}
|
380
394
|
#{WORD_FTR1}
|
@@ -386,11 +400,11 @@ RSpec.describe Html2Doc do
|
|
386
400
|
expect(guid_clean(File.read("test.doc", encoding: "utf-8"))).
|
387
401
|
to match_fuzzy(<<~OUTPUT)
|
388
402
|
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
389
|
-
#{word_body(
|
403
|
+
#{word_body('
|
390
404
|
<div><m:oMath>
|
391
|
-
<m:r><m:t>text</m:t></m:r><m:r><m:rPr><m:nor></m:nor></m:rPr><m:t> integer </m:t></m:r><m:r><m:t>)</m:t></m:r>
|
405
|
+
<m:r><m:t>text</m:t></m:r><m:r><m:rPr><m:nor></m:nor></m:rPr><m:t> integer </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>
|
392
406
|
</m:oMath>
|
393
|
-
</div>
|
407
|
+
</div>', '<div style="mso-element:footnote-list"/>')}
|
394
408
|
#{WORD_FTR1}
|
395
409
|
OUTPUT
|
396
410
|
end
|
@@ -417,7 +431,7 @@ RSpec.describe Html2Doc do
|
|
417
431
|
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
418
432
|
#{word_body(%{
|
419
433
|
<div style="text-align:left;"><m:oMathPara><m:oMathParaPr><m:jc m:val="left"/></m:oMathParaPr><m:oMath>
|
420
|
-
<m:nary><m:naryPr><m:chr m:val="∑"></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><m:r><m:t>=</m:t></m:r><m:sSup><m:e><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:f><m:fPr><m:type m:val="bar"></m:type></m:fPr><m:num><m:r><m:t>n</m:t></m:r><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:r><m:t>n+1</m:t></m:r></m:e></m:d></m:num><m:den><m:r><m:t>2</m:t></m:r></m:den></m:f></m:e></m:d></m:e><m:sup><m:r><m:t>2</m:t></m:r></m:sup></m:sSup>
|
434
|
+
<m:nary><m:naryPr><m:chr m:val="∑"></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><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:f><m:fPr><m:type m:val="bar"></m:type></m:fPr><m:num><m:r><m:t>n</m:t></m:r><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:r><m:t>n+1</m:t></m:r></m:e></m:d></m:num><m:den><m:r><m:t>2</m:t></m:r></m:den></m:f></m:e></m:d></m:e><m:sup><m:r><m:t>2</m:t></m:r></m:sup></m:sSup>
|
421
435
|
</m:oMath>
|
422
436
|
</m:oMathPara></div>}, '<div style="mso-element:footnote-list"/>')}
|
423
437
|
#{WORD_FTR1}
|
@@ -431,7 +445,7 @@ RSpec.describe Html2Doc do
|
|
431
445
|
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
432
446
|
#{word_body(%{
|
433
447
|
<div style="text-align:right;"><m:oMathPara><m:oMathParaPr><m:jc m:val="right"/></m:oMathParaPr><m:oMath>
|
434
|
-
<m:nary><m:naryPr><m:chr m:val="∑"></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><m:r><m:t>=</m:t></m:r><m:sSup><m:e><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:f><m:fPr><m:type m:val="bar"></m:type></m:fPr><m:num><m:r><m:t>n</m:t></m:r><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:r><m:t>n+1</m:t></m:r></m:e></m:d></m:num><m:den><m:r><m:t>2</m:t></m:r></m:den></m:f></m:e></m:d></m:e><m:sup><m:r><m:t>2</m:t></m:r></m:sup></m:sSup>
|
448
|
+
<m:nary><m:naryPr><m:chr m:val="∑"></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><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:f><m:fPr><m:type m:val="bar"></m:type></m:fPr><m:num><m:r><m:t>n</m:t></m:r><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:r><m:t>n+1</m:t></m:r></m:e></m:d></m:num><m:den><m:r><m:t>2</m:t></m:r></m:den></m:f></m:e></m:d></m:e><m:sup><m:r><m:t>2</m:t></m:r></m:sup></m:sSup>
|
435
449
|
</m:oMath>
|
436
450
|
</m:oMathPara></div>}, '<div style="mso-element:footnote-list"/>')}
|
437
451
|
#{WORD_FTR1}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html2doc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: htmlentities
|