Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

fix: add util files

Sidney23311fb0a019927
diff --git a/mineru/model/utils/docx/mammoth/complex_fields.py b/mineru/model/utils/docx/mammoth/complex_fields.py
new file mode 100644
index 00000000..ac641812
--- /dev/null
+++ b/mineru/model/utils/docx/mammoth/complex_fields.py
@@ -0,0 +1,29 @@
+class unknown(object):
+ pass
+
+
+class Begin:
+ def __init__(self, *, fld_char):
+ self.fld_char = fld_char
+
+
+def begin(*, fld_char):
+ return Begin(fld_char=fld_char)
+
+
+class Hyperlink(object):
+ def __init__(self, kwargs):
+ self.kwargs = kwargs
+
+
+def hyperlink(kwargs):
+ return Hyperlink(kwargs=kwargs)
+
+
+class Checkbox:
+ def __init__(self, *, checked):
+ self.checked = checked
+
+
+def checkbox(*, checked):
+ return Checkbox(checked=checked)
diff --git a/mineru/model/utils/docx/mammoth/dingbats.py b/mineru/model/utils/docx/mammoth/dingbats.py
new file mode 100644
index 00000000..3edef51b
--- /dev/null
+++ b/mineru/model/utils/docx/mammoth/dingbats.py
@@ -0,0 +1,1065 @@
+# Generated by https://github.com/mwilliamson/dingbat-to-unicode
+
+dingbats = {
+ ('Symbol', 32): 32,
+ ('Symbol', 33): 33,
+ ('Symbol', 34): 8704,
+ ('Symbol', 35): 35,
+ ('Symbol', 36): 8707,
+ ('Symbol', 37): 37,
+ ('Symbol', 38): 38,
+ ('Symbol', 39): 8717,
+ ('Symbol', 40): 40,
+ ('Symbol', 41): 41,
+ ('Symbol', 42): 42,
+ ('Symbol', 43): 43,
+ ('Symbol', 44): 44,
+ ('Symbol', 45): 8722,
+ ('Symbol', 46): 46,
+ ('Symbol', 47): 47,
+ ('Symbol', 48): 48,
+ ('Symbol', 49): 49,
+ ('Symbol', 50): 50,
+ ('Symbol', 51): 51,
+ ('Symbol', 52): 52,
+ ('Symbol', 53): 53,
+ ('Symbol', 54): 54,
+ ('Symbol', 55): 55,
+ ('Symbol', 56): 56,
+ ('Symbol', 57): 57,
+ ('Symbol', 58): 58,
+ ('Symbol', 59): 59,
+ ('Symbol', 60): 60,
+ ('Symbol', 61): 61,
+ ('Symbol', 62): 62,
+ ('Symbol', 63): 63,
+ ('Symbol', 64): 8773,
+ ('Symbol', 65): 913,
+ ('Symbol', 66): 914,
+ ('Symbol', 67): 935,
+ ('Symbol', 68): 916,
+ ('Symbol', 69): 917,
+ ('Symbol', 70): 934,
+ ('Symbol', 71): 915,
+ ('Symbol', 72): 919,
+ ('Symbol', 73): 921,
+ ('Symbol', 74): 977,
+ ('Symbol', 75): 922,
+ ('Symbol', 76): 923,
+ ('Symbol', 77): 924,
+ ('Symbol', 78): 925,
+ ('Symbol', 79): 927,
+ ('Symbol', 80): 928,
+ ('Symbol', 81): 920,
+ ('Symbol', 82): 929,
+ ('Symbol', 83): 931,
+ ('Symbol', 84): 932,
+ ('Symbol', 85): 933,
+ ('Symbol', 86): 962,
+ ('Symbol', 87): 937,
+ ('Symbol', 88): 926,
+ ('Symbol', 89): 936,
+ ('Symbol', 90): 918,
+ ('Symbol', 91): 91,
+ ('Symbol', 92): 8756,
+ ('Symbol', 93): 93,
+ ('Symbol', 94): 8869,
+ ('Symbol', 95): 95,
+ ('Symbol', 96): 8254,
+ ('Symbol', 97): 945,
+ ('Symbol', 98): 946,
+ ('Symbol', 99): 967,
+ ('Symbol', 100): 948,
+ ('Symbol', 101): 949,
+ ('Symbol', 102): 966,
+ ('Symbol', 103): 947,
+ ('Symbol', 104): 951,
+ ('Symbol', 105): 953,
+ ('Symbol', 106): 981,
+ ('Symbol', 107): 954,
+ ('Symbol', 108): 955,
+ ('Symbol', 109): 956,
+ ('Symbol', 110): 957,
+ ('Symbol', 111): 959,
+ ('Symbol', 112): 960,
+ ('Symbol', 113): 952,
+ ('Symbol', 114): 961,
+ ('Symbol', 115): 963,
+ ('Symbol', 116): 964,
+ ('Symbol', 117): 965,
+ ('Symbol', 118): 982,
+ ('Symbol', 119): 969,
+ ('Symbol', 120): 958,
+ ('Symbol', 121): 968,
+ ('Symbol', 122): 950,
+ ('Symbol', 123): 123,
+ ('Symbol', 124): 124,
+ ('Symbol', 125): 125,
+ ('Symbol', 126): 126,
+ ('Symbol', 160): 8364,
+ ('Symbol', 161): 978,
+ ('Symbol', 162): 8242,
+ ('Symbol', 163): 8804,
+ ('Symbol', 164): 8260,
+ ('Symbol', 165): 8734,
+ ('Symbol', 166): 402,
+ ('Symbol', 167): 9827,
+ ('Symbol', 168): 9830,
+ ('Symbol', 169): 9829,
+ ('Symbol', 170): 9824,
+ ('Symbol', 171): 8596,
+ ('Symbol', 172): 8592,
+ ('Symbol', 173): 8593,
+ ('Symbol', 174): 8594,
+ ('Symbol', 175): 8595,
+ ('Symbol', 176): 176,
+ ('Symbol', 177): 177,
+ ('Symbol', 178): 8243,
+ ('Symbol', 179): 8805,
+ ('Symbol', 180): 215,
+ ('Symbol', 181): 8733,
+ ('Symbol', 182): 8706,
+ ('Symbol', 183): 8226,
+ ('Symbol', 184): 247,
+ ('Symbol', 185): 8800,
+ ('Symbol', 186): 8801,
+ ('Symbol', 187): 8776,
+ ('Symbol', 188): 8230,
+ ('Symbol', 189): 9168,
+ ('Symbol', 190): 9135,
+ ('Symbol', 191): 8629,
+ ('Symbol', 192): 8501,
+ ('Symbol', 193): 8465,
+ ('Symbol', 194): 8476,
+ ('Symbol', 195): 8472,
+ ('Symbol', 196): 8855,
+ ('Symbol', 197): 8853,
+ ('Symbol', 198): 8709,
+ ('Symbol', 199): 8745,
+ ('Symbol', 200): 8746,
+ ('Symbol', 201): 8835,
+ ('Symbol', 202): 8839,
+ ('Symbol', 203): 8836,
+ ('Symbol', 204): 8834,
+ ('Symbol', 205): 8838,
+ ('Symbol', 206): 8712,
+ ('Symbol', 207): 8713,
+ ('Symbol', 208): 8736,
+ ('Symbol', 209): 8711,
+ ('Symbol', 210): 174,
+ ('Symbol', 211): 169,
+ ('Symbol', 212): 8482,
+ ('Symbol', 213): 8719,
+ ('Symbol', 214): 8730,
+ ('Symbol', 215): 8901,
+ ('Symbol', 216): 172,
+ ('Symbol', 217): 8743,
+ ('Symbol', 218): 8744,
+ ('Symbol', 219): 8660,
+ ('Symbol', 220): 8656,
+ ('Symbol', 221): 8657,
+ ('Symbol', 222): 8658,
+ ('Symbol', 223): 8659,
+ ('Symbol', 224): 9674,
+ ('Symbol', 225): 12296,
+ ('Symbol', 226): 174,
+ ('Symbol', 227): 169,
+ ('Symbol', 228): 8482,
+ ('Symbol', 229): 8721,
+ ('Symbol', 230): 9115,
+ ('Symbol', 231): 9116,
+ ('Symbol', 232): 9117,
+ ('Symbol', 233): 9121,
+ ('Symbol', 234): 9122,
+ ('Symbol', 235): 9123,
+ ('Symbol', 236): 9127,
+ ('Symbol', 237): 9128,
+ ('Symbol', 238): 9129,
+ ('Symbol', 239): 9130,
+ ('Symbol', 240): 63743,
+ ('Symbol', 241): 12297,
+ ('Symbol', 242): 8747,
+ ('Symbol', 243): 8992,
+ ('Symbol', 244): 9134,
+ ('Symbol', 245): 8993,
+ ('Symbol', 246): 9118,
+ ('Symbol', 247): 9119,
+ ('Symbol', 248): 9120,
+ ('Symbol', 249): 9124,
+ ('Symbol', 250): 9125,
+ ('Symbol', 251): 9126,
+ ('Symbol', 252): 9131,
+ ('Symbol', 253): 9132,
+ ('Symbol', 254): 9133,
+ ('Webdings', 32): 32,
+ ('Webdings', 33): 128375,
+ ('Webdings', 34): 128376,
+ ('Webdings', 35): 128370,
+ ('Webdings', 36): 128374,
+ ('Webdings', 37): 127942,
+ ('Webdings', 38): 127894,
+ ('Webdings', 39): 128391,
+ ('Webdings', 40): 128488,
+ ('Webdings', 41): 128489,
+ ('Webdings', 42): 128496,
+ ('Webdings', 43): 128497,
+ ('Webdings', 44): 127798,
+ ('Webdings', 45): 127895,
+ ('Webdings', 46): 128638,
+ ('Webdings', 47): 128636,
+ ('Webdings', 48): 128469,
+ ('Webdings', 49): 128470,
+ ('Webdings', 50): 128471,
+ ('Webdings', 51): 9204,
+ ('Webdings', 52): 9205,
+ ('Webdings', 53): 9206,
+ ('Webdings', 54): 9207,
+ ('Webdings', 55): 9194,
+ ('Webdings', 56): 9193,
+ ('Webdings', 57): 9198,
+ ('Webdings', 58): 9197,
+ ('Webdings', 59): 9208,
+ ('Webdings', 60): 9209,
+ ('Webdings', 61): 9210,
+ ('Webdings', 62): 128474,
+ ('Webdings', 63): 128499,
+ ('Webdings', 64): 128736,
+ ('Webdings', 65): 127959,
+ ('Webdings', 66): 127960,
+ ('Webdings', 67): 127961,
+ ('Webdings', 68): 127962,
+ ('Webdings', 69): 127964,
+ ('Webdings', 70): 127981,
+ ('Webdings', 71): 127963,
+ ('Webdings', 72): 127968,
+ ('Webdings', 73): 127958,
+ ('Webdings', 74): 127965,
+ ('Webdings', 75): 128739,
+ ('Webdings', 76): 128269,
+ ('Webdings', 77): 127956,
+ ('Webdings', 78): 128065,
+ ('Webdings', 79): 128066,
+ ('Webdings', 80): 127966,
+ ('Webdings', 81): 127957,
+ ('Webdings', 82): 128740,
+ ('Webdings', 83): 127967,
+ ('Webdings', 84): 128755,
+ ('Webdings', 85): 128364,
+ ('Webdings', 86): 128363,
+ ('Webdings', 87): 128360,
+ ('Webdings', 88): 128264,
+ ('Webdings', 89): 127892,
+ ('Webdings', 90): 127893,
+ ('Webdings', 91): 128492,
+ ('Webdings', 92): 128637,
+ ('Webdings', 93): 128493,
+ ('Webdings', 94): 128490,
+ ('Webdings', 95): 128491,
+ ('Webdings', 96): 11156,
+ ('Webdings', 97): 10004,
+ ('Webdings', 98): 128690,
+ ('Webdings', 99): 11036,
+ ('Webdings', 100): 128737,
+ ('Webdings', 101): 128230,
+ ('Webdings', 102): 128753,
+ ('Webdings', 103): 11035,
+ ('Webdings', 104): 128657,
+ ('Webdings', 105): 128712,
+ ('Webdings', 106): 128745,
+ ('Webdings', 107): 128752,
+ ('Webdings', 108): 128968,
+ ('Webdings', 109): 128372,
+ ('Webdings', 110): 11044,
+ ('Webdings', 111): 128741,
+ ('Webdings', 112): 128660,
+ ('Webdings', 113): 128472,
+ ('Webdings', 114): 128473,
+ ('Webdings', 115): 10067,
+ ('Webdings', 116): 128754,
+ ('Webdings', 117): 128647,
+ ('Webdings', 118): 128653,
+ ('Webdings', 119): 9971,
+ ('Webdings', 120): 10680,
+ ('Webdings', 121): 8854,
+ ('Webdings', 122): 128685,
+ ('Webdings', 123): 128494,
+ ('Webdings', 124): 9168,
+ ('Webdings', 125): 128495,
+ ('Webdings', 126): 128498,
+ ('Webdings', 128): 128697,
+ ('Webdings', 129): 128698,
+ ('Webdings', 130): 128713,
+ ('Webdings', 131): 128714,
+ ('Webdings', 132): 128700,
+ ('Webdings', 133): 128125,
+ ('Webdings', 134): 127947,
+ ('Webdings', 135): 9975,
+ ('Webdings', 136): 127938,
+ ('Webdings', 137): 127948,
+ ('Webdings', 138): 127946,
+ ('Webdings', 139): 127940,
+ ('Webdings', 140): 127949,
+ ('Webdings', 141): 127950,
+ ('Webdings', 142): 128664,
+ ('Webdings', 143): 128480,
+ ('Webdings', 144): 128738,
+ ('Webdings', 145): 128176,
+ ('Webdings', 146): 127991,
+ ('Webdings', 147): 128179,
+ ('Webdings', 148): 128106,
+ ('Webdings', 149): 128481,
+ ('Webdings', 150): 128482,
+ ('Webdings', 151): 128483,
+ ('Webdings', 152): 10031,
+ ('Webdings', 153): 128388,
+ ('Webdings', 154): 128389,
+ ('Webdings', 155): 128387,
+ ('Webdings', 156): 128390,
+ ('Webdings', 157): 128441,
+ ('Webdings', 158): 128442,
+ ('Webdings', 159): 128443,
+ ('Webdings', 160): 128373,
+ ('Webdings', 161): 128368,
+ ('Webdings', 162): 128445,
+ ('Webdings', 163): 128446,
+ ('Webdings', 164): 128203,
+ ('Webdings', 165): 128466,
+ ('Webdings', 166): 128467,
+ ('Webdings', 167): 128366,
+ ('Webdings', 168): 128218,
+ ('Webdings', 169): 128478,
+ ('Webdings', 170): 128479,
+ ('Webdings', 171): 128451,
+ ('Webdings', 172): 128450,
+ ('Webdings', 173): 128444,
+ ('Webdings', 174): 127917,
+ ('Webdings', 175): 127900,
+ ('Webdings', 176): 127896,
+ ('Webdings', 177): 127897,
+ ('Webdings', 178): 127911,
+ ('Webdings', 179): 128191,
+ ('Webdings', 180): 127902,
+ ('Webdings', 181): 128247,
+ ('Webdings', 182): 127903,
+ ('Webdings', 183): 127916,
+ ('Webdings', 184): 128253,
+ ('Webdings', 185): 128249,
+ ('Webdings', 186): 128254,
+ ('Webdings', 187): 128251,
+ ('Webdings', 188): 127898,
+ ('Webdings', 189): 127899,
+ ('Webdings', 190): 128250,
+ ('Webdings', 191): 128187,
+ ('Webdings', 192): 128421,
+ ('Webdings', 193): 128422,
+ ('Webdings', 194): 128423,
+ ('Webdings', 195): 128377,
+ ('Webdings', 196): 127918,
+ ('Webdings', 197): 128379,
+ ('Webdings', 198): 128380,
+ ('Webdings', 199): 128223,
+ ('Webdings', 200): 128385,
+ ('Webdings', 201): 128384,
+ ('Webdings', 202): 128424,
+ ('Webdings', 203): 128425,
+ ('Webdings', 204): 128447,
+ ('Webdings', 205): 128426,
+ ('Webdings', 206): 128476,
+ ('Webdings', 207): 128274,
+ ('Webdings', 208): 128275,
+ ('Webdings', 209): 128477,
+ ('Webdings', 210): 128229,
+ ('Webdings', 211): 128228,
+ ('Webdings', 212): 128371,
+ ('Webdings', 213): 127779,
+ ('Webdings', 214): 127780,
+ ('Webdings', 215): 127781,
+ ('Webdings', 216): 127782,
+ ('Webdings', 217): 9729,
+ ('Webdings', 218): 127784,
+ ('Webdings', 219): 127783,
+ ('Webdings', 220): 127785,
+ ('Webdings', 221): 127786,
+ ('Webdings', 222): 127788,
+ ('Webdings', 223): 127787,
+ ('Webdings', 224): 127772,
+ ('Webdings', 225): 127777,
+ ('Webdings', 226): 128715,
+ ('Webdings', 227): 128719,
+ ('Webdings', 228): 127869,
+ ('Webdings', 229): 127864,
+ ('Webdings', 230): 128718,
+ ('Webdings', 231): 128717,
+ ('Webdings', 232): 9413,
+ ('Webdings', 233): 9855,
+ ('Webdings', 234): 128710,
+ ('Webdings', 235): 128392,
+ ('Webdings', 236): 127891,
+ ('Webdings', 237): 128484,
+ ('Webdings', 238): 128485,
+ ('Webdings', 239): 128486,
+ ('Webdings', 240): 128487,
+ ('Webdings', 241): 128746,
+ ('Webdings', 242): 128063,
+ ('Webdings', 243): 128038,
+ ('Webdings', 244): 128031,
+ ('Webdings', 245): 128021,
+ ('Webdings', 246): 128008,
+ ('Webdings', 247): 128620,
+ ('Webdings', 248): 128622,
+ ('Webdings', 249): 128621,
+ ('Webdings', 250): 128623,
+ ('Webdings', 251): 128506,
+ ('Webdings', 252): 127757,
+ ('Webdings', 253): 127759,
+ ('Webdings', 254): 127758,
+ ('Webdings', 255): 128330,
+ ('Wingdings', 32): 32,
+ ('Wingdings', 33): 128393,
+ ('Wingdings', 34): 9986,
+ ('Wingdings', 35): 9985,
+ ('Wingdings', 36): 128083,
+ ('Wingdings', 37): 128365,
+ ('Wingdings', 38): 128366,
+ ('Wingdings', 39): 128367,
+ ('Wingdings', 40): 128383,
+ ('Wingdings', 41): 9990,
+ ('Wingdings', 42): 128386,
+ ('Wingdings', 43): 128387,
+ ('Wingdings', 44): 128234,
+ ('Wingdings', 45): 128235,
+ ('Wingdings', 46): 128236,
+ ('Wingdings', 47): 128237,
+ ('Wingdings', 48): 128448,
+ ('Wingdings', 49): 128449,
+ ('Wingdings', 50): 128462,
+ ('Wingdings', 51): 128463,
+ ('Wingdings', 52): 128464,
+ ('Wingdings', 53): 128452,
+ ('Wingdings', 54): 8987,
+ ('Wingdings', 55): 128430,
+ ('Wingdings', 56): 128432,
+ ('Wingdings', 57): 128434,
+ ('Wingdings', 58): 128435,
+ ('Wingdings', 59): 128436,
+ ('Wingdings', 60): 128427,
+ ('Wingdings', 61): 128428,
+ ('Wingdings', 62): 9991,
+ ('Wingdings', 63): 9997,
+ ('Wingdings', 64): 128398,
+ ('Wingdings', 65): 9996,
+ ('Wingdings', 66): 128399,
+ ('Wingdings', 67): 128077,
+ ('Wingdings', 68): 128078,
+ ('Wingdings', 69): 9756,
+ ('Wingdings', 70): 9758,
+ ('Wingdings', 71): 9757,
+ ('Wingdings', 72): 9759,
+ ('Wingdings', 73): 128400,
+ ('Wingdings', 74): 9786,
+ ('Wingdings', 75): 128528,
+ ('Wingdings', 76): 9785,
+ ('Wingdings', 77): 128163,
+ ('Wingdings', 78): 128369,
+ ('Wingdings', 79): 127987,
+ ('Wingdings', 80): 127985,
+ ('Wingdings', 81): 9992,
+ ('Wingdings', 82): 9788,
+ ('Wingdings', 83): 127778,
+ ('Wingdings', 84): 10052,
+ ('Wingdings', 85): 128326,
+ ('Wingdings', 86): 10014,
+ ('Wingdings', 87): 128328,
+ ('Wingdings', 88): 10016,
+ ('Wingdings', 89): 10017,
+ ('Wingdings', 90): 9770,
+ ('Wingdings', 91): 9775,
+ ('Wingdings', 92): 128329,
+ ('Wingdings', 93): 9784,
+ ('Wingdings', 94): 9800,
+ ('Wingdings', 95): 9801,
+ ('Wingdings', 96): 9802,
+ ('Wingdings', 97): 9803,
+ ('Wingdings', 98): 9804,
+ ('Wingdings', 99): 9805,
+ ('Wingdings', 100): 9806,
+ ('Wingdings', 101): 9807,
+ ('Wingdings', 102): 9808,
+ ('Wingdings', 103): 9809,
+ ('Wingdings', 104): 9810,
+ ('Wingdings', 105): 9811,
+ ('Wingdings', 106): 128624,
+ ('Wingdings', 107): 128629,
+ ('Wingdings', 108): 9899,
+ ('Wingdings', 109): 128318,
+ ('Wingdings', 110): 9724,
+ ('Wingdings', 111): 128911,
+ ('Wingdings', 112): 128912,
+ ('Wingdings', 113): 10065,
+ ('Wingdings', 114): 10066,
+ ('Wingdings', 115): 128927,
+ ('Wingdings', 116): 10731,
+ ('Wingdings', 117): 9670,
+ ('Wingdings', 118): 10070,
+ ('Wingdings', 119): 11049,
+ ('Wingdings', 120): 8999,
+ ('Wingdings', 121): 11193,
+ ('Wingdings', 122): 8984,
+ ('Wingdings', 123): 127989,
+ ('Wingdings', 124): 127990,
+ ('Wingdings', 125): 128630,
+ ('Wingdings', 126): 128631,
+ ('Wingdings', 127): 9647,
+ ('Wingdings', 128): 127243,
+ ('Wingdings', 129): 10112,
+ ('Wingdings', 130): 10113,
+ ('Wingdings', 131): 10114,
+ ('Wingdings', 132): 10115,
+ ('Wingdings', 133): 10116,
+ ('Wingdings', 134): 10117,
+ ('Wingdings', 135): 10118,
+ ('Wingdings', 136): 10119,
+ ('Wingdings', 137): 10120,
+ ('Wingdings', 138): 10121,
+ ('Wingdings', 139): 127244,
+ ('Wingdings', 140): 10122,
+ ('Wingdings', 141): 10123,
+ ('Wingdings', 142): 10124,
+ ('Wingdings', 143): 10125,
+ ('Wingdings', 144): 10126,
+ ('Wingdings', 145): 10127,
+ ('Wingdings', 146): 10128,
+ ('Wingdings', 147): 10129,
+ ('Wingdings', 148): 10130,
+ ('Wingdings', 149): 10131,
+ ('Wingdings', 150): 128610,
+ ('Wingdings', 151): 128608,
+ ('Wingdings', 152): 128609,
+ ('Wingdings', 153): 128611,
+ ('Wingdings', 154): 128606,
+ ('Wingdings', 155): 128604,
+ ('Wingdings', 156): 128605,
+ ('Wingdings', 157): 128607,
+ ('Wingdings', 158): 8729,
+ ('Wingdings', 159): 8226,
+ ('Wingdings', 160): 11037,
+ ('Wingdings', 161): 11096,
+ ('Wingdings', 162): 128902,
+ ('Wingdings', 163): 128904,
+ ('Wingdings', 164): 128906,
+ ('Wingdings', 165): 128907,
+ ('Wingdings', 166): 128319,
+ ('Wingdings', 167): 9642,
+ ('Wingdings', 168): 128910,
+ ('Wingdings', 169): 128961,
+ ('Wingdings', 170): 128965,
+ ('Wingdings', 171): 9733,
+ ('Wingdings', 172): 128971,
+ ('Wingdings', 173): 128975,
+ ('Wingdings', 174): 128979,
+ ('Wingdings', 175): 128977,
+ ('Wingdings', 176): 11216,
+ ('Wingdings', 177): 8982,
+ ('Wingdings', 178): 11214,
+ ('Wingdings', 179): 11215,
+ ('Wingdings', 180): 11217,
+ ('Wingdings', 181): 10026,
+ ('Wingdings', 182): 10032,
+ ('Wingdings', 183): 128336,
+ ('Wingdings', 184): 128337,
+ ('Wingdings', 185): 128338,
+ ('Wingdings', 186): 128339,
+ ('Wingdings', 187): 128340,
+ ('Wingdings', 188): 128341,
+ ('Wingdings', 189): 128342,
+ ('Wingdings', 190): 128343,
+ ('Wingdings', 191): 128344,
+ ('Wingdings', 192): 128345,
+ ('Wingdings', 193): 128346,
+ ('Wingdings', 194): 128347,
+ ('Wingdings', 195): 11184,
+ ('Wingdings', 196): 11185,
+ ('Wingdings', 197): 11186,
+ ('Wingdings', 198): 11187,
+ ('Wingdings', 199): 11188,
+ ('Wingdings', 200): 11189,
+ ('Wingdings', 201): 11190,
+ ('Wingdings', 202): 11191,
+ ('Wingdings', 203): 128618,
+ ('Wingdings', 204): 128619,
+ ('Wingdings', 205): 128597,
+ ('Wingdings', 206): 128596,
+ ('Wingdings', 207): 128599,
+ ('Wingdings', 208): 128598,
+ ('Wingdings', 209): 128592,
+ ('Wingdings', 210): 128593,
+ ('Wingdings', 211): 128594,
+ ('Wingdings', 212): 128595,
+ ('Wingdings', 213): 9003,
+ ('Wingdings', 214): 8998,
+ ('Wingdings', 215): 11160,
+ ('Wingdings', 216): 11162,
+ ('Wingdings', 217): 11161,
+ ('Wingdings', 218): 11163,
+ ('Wingdings', 219): 11144,
+ ('Wingdings', 220): 11146,
+ ('Wingdings', 221): 11145,
+ ('Wingdings', 222): 11147,
+ ('Wingdings', 223): 129128,
+ ('Wingdings', 224): 129130,
+ ('Wingdings', 225): 129129,
+ ('Wingdings', 226): 129131,
+ ('Wingdings', 227): 129132,
+ ('Wingdings', 228): 129133,
+ ('Wingdings', 229): 129135,
+ ('Wingdings', 230): 129134,
+ ('Wingdings', 231): 129144,
+ ('Wingdings', 232): 129146,
+ ('Wingdings', 233): 129145,
+ ('Wingdings', 234): 129147,
+ ('Wingdings', 235): 129148,
+ ('Wingdings', 236): 129149,
+ ('Wingdings', 237): 129151,
+ ('Wingdings', 238): 129150,
+ ('Wingdings', 239): 8678,
+ ('Wingdings', 240): 8680,
+ ('Wingdings', 241): 8679,
+ ('Wingdings', 242): 8681,
+ ('Wingdings', 243): 11012,
+ ('Wingdings', 244): 8691,
+ ('Wingdings', 245): 11009,
+ ('Wingdings', 246): 11008,
+ ('Wingdings', 247): 11011,
+ ('Wingdings', 248): 11010,
+ ('Wingdings', 249): 129196,
+ ('Wingdings', 250): 129197,
+ ('Wingdings', 251): 128502,
+ ('Wingdings', 252): 10003,
+ ('Wingdings', 253): 128503,
+ ('Wingdings', 254): 128505,
+ ('Wingdings 2', 32): 32,
+ ('Wingdings 2', 33): 128394,
+ ('Wingdings 2', 34): 128395,
+ ('Wingdings 2', 35): 128396,
+ ('Wingdings 2', 36): 128397,
+ ('Wingdings 2', 37): 9988,
+ ('Wingdings 2', 38): 9984,
+ ('Wingdings 2', 39): 128382,
+ ('Wingdings 2', 40): 128381,
+ ('Wingdings 2', 41): 128453,
+ ('Wingdings 2', 42): 128454,
+ ('Wingdings 2', 43): 128455,
+ ('Wingdings 2', 44): 128456,
+ ('Wingdings 2', 45): 128457,
+ ('Wingdings 2', 46): 128458,
+ ('Wingdings 2', 47): 128459,
+ ('Wingdings 2', 48): 128460,
+ ('Wingdings 2', 49): 128461,
+ ('Wingdings 2', 50): 128203,
+ ('Wingdings 2', 51): 128465,
+ ('Wingdings 2', 52): 128468,
+ ('Wingdings 2', 53): 128437,
+ ('Wingdings 2', 54): 128438,
+ ('Wingdings 2', 55): 128439,
+ ('Wingdings 2', 56): 128440,
+ ('Wingdings 2', 57): 128429,
+ ('Wingdings 2', 58): 128431,
+ ('Wingdings 2', 59): 128433,
+ ('Wingdings 2', 60): 128402,
+ ('Wingdings 2', 61): 128403,
+ ('Wingdings 2', 62): 128408,
+ ('Wingdings 2', 63): 128409,
+ ('Wingdings 2', 64): 128410,
+ ('Wingdings 2', 65): 128411,
+ ('Wingdings 2', 66): 128072,
+ ('Wingdings 2', 67): 128073,
+ ('Wingdings 2', 68): 128412,
+ ('Wingdings 2', 69): 128413,
+ ('Wingdings 2', 70): 128414,
+ ('Wingdings 2', 71): 128415,
+ ('Wingdings 2', 72): 128416,
+ ('Wingdings 2', 73): 128417,
+ ('Wingdings 2', 74): 128070,
+ ('Wingdings 2', 75): 128071,
+ ('Wingdings 2', 76): 128418,
+ ('Wingdings 2', 77): 128419,
+ ('Wingdings 2', 78): 128401,
+ ('Wingdings 2', 79): 128500,
+ ('Wingdings 2', 80): 128504,
+ ('Wingdings 2', 81): 128501,
+ ('Wingdings 2', 82): 9745,
+ ('Wingdings 2', 83): 11197,
+ ('Wingdings 2', 84): 9746,
+ ('Wingdings 2', 85): 11198,
+ ('Wingdings 2', 86): 11199,
+ ('Wingdings 2', 87): 128711,
+ ('Wingdings 2', 88): 10680,
+ ('Wingdings 2', 89): 128625,
+ ('Wingdings 2', 90): 128628,
+ ('Wingdings 2', 91): 128626,
+ ('Wingdings 2', 92): 128627,
+ ('Wingdings 2', 93): 8253,
+ ('Wingdings 2', 94): 128633,
+ ('Wingdings 2', 95): 128634,
+ ('Wingdings 2', 96): 128635,
+ ('Wingdings 2', 97): 128614,
+ ('Wingdings 2', 98): 128612,
+ ('Wingdings 2', 99): 128613,
+ ('Wingdings 2', 100): 128615,
+ ('Wingdings 2', 101): 128602,
+ ('Wingdings 2', 102): 128600,
+ ('Wingdings 2', 103): 128601,
+ ('Wingdings 2', 104): 128603,
+ ('Wingdings 2', 105): 9450,
+ ('Wingdings 2', 106): 9312,
+ ('Wingdings 2', 107): 9313,
+ ('Wingdings 2', 108): 9314,
+ ('Wingdings 2', 109): 9315,
+ ('Wingdings 2', 110): 9316,
+ ('Wingdings 2', 111): 9317,
+ ('Wingdings 2', 112): 9318,
+ ('Wingdings 2', 113): 9319,
+ ('Wingdings 2', 114): 9320,
+ ('Wingdings 2', 115): 9321,
+ ('Wingdings 2', 116): 9471,
+ ('Wingdings 2', 117): 10102,
+ ('Wingdings 2', 118): 10103,
+ ('Wingdings 2', 119): 10104,
+ ('Wingdings 2', 120): 10105,
+ ('Wingdings 2', 121): 10106,
+ ('Wingdings 2', 122): 10107,
+ ('Wingdings 2', 123): 10108,
+ ('Wingdings 2', 124): 10109,
+ ('Wingdings 2', 125): 10110,
+ ('Wingdings 2', 126): 10111,
+ ('Wingdings 2', 128): 9737,
+ ('Wingdings 2', 129): 127765,
+ ('Wingdings 2', 130): 9789,
+ ('Wingdings 2', 131): 9790,
+ ('Wingdings 2', 132): 11839,
+ ('Wingdings 2', 133): 10013,
+ ('Wingdings 2', 134): 128327,
+ ('Wingdings 2', 135): 128348,
+ ('Wingdings 2', 136): 128349,
+ ('Wingdings 2', 137): 128350,
+ ('Wingdings 2', 138): 128351,
+ ('Wingdings 2', 139): 128352,
+ ('Wingdings 2', 140): 128353,
+ ('Wingdings 2', 141): 128354,
+ ('Wingdings 2', 142): 128355,
+ ('Wingdings 2', 143): 128356,
+ ('Wingdings 2', 144): 128357,
+ ('Wingdings 2', 145): 128358,
+ ('Wingdings 2', 146): 128359,
+ ('Wingdings 2', 147): 128616,
+ ('Wingdings 2', 148): 128617,
+ ('Wingdings 2', 149): 8901,
+ ('Wingdings 2', 150): 128900,
+ ('Wingdings 2', 151): 10625,
+ ('Wingdings 2', 152): 9679,
+ ('Wingdings 2', 153): 9675,
+ ('Wingdings 2', 154): 128901,
+ ('Wingdings 2', 155): 128903,
+ ('Wingdings 2', 156): 128905,
+ ('Wingdings 2', 157): 8857,
+ ('Wingdings 2', 158): 10687,
+ ('Wingdings 2', 159): 128908,
+ ('Wingdings 2', 160): 128909,
+ ('Wingdings 2', 161): 9726,
+ ('Wingdings 2', 162): 9632,
+ ('Wingdings 2', 163): 9633,
+ ('Wingdings 2', 164): 128913,
+ ('Wingdings 2', 165): 128914,
+ ('Wingdings 2', 166): 128915,
+ ('Wingdings 2', 167): 128916,
+ ('Wingdings 2', 168): 9635,
+ ('Wingdings 2', 169): 128917,
+ ('Wingdings 2', 170): 128918,
+ ('Wingdings 2', 171): 128919,
+ ('Wingdings 2', 172): 128920,
+ ('Wingdings 2', 173): 11049,
+ ('Wingdings 2', 174): 11045,
+ ('Wingdings 2', 175): 9671,
+ ('Wingdings 2', 176): 128922,
+ ('Wingdings 2', 177): 9672,
+ ('Wingdings 2', 178): 128923,
+ ('Wingdings 2', 179): 128924,
+ ('Wingdings 2', 180): 128925,
+ ('Wingdings 2', 181): 128926,
+ ('Wingdings 2', 182): 11050,
+ ('Wingdings 2', 183): 11047,
+ ('Wingdings 2', 184): 9674,
+ ('Wingdings 2', 185): 128928,
+ ('Wingdings 2', 186): 9686,
+ ('Wingdings 2', 187): 9687,
+ ('Wingdings 2', 188): 11210,
+ ('Wingdings 2', 189): 11211,
+ ('Wingdings 2', 190): 11200,
+ ('Wingdings 2', 191): 11201,
+ ('Wingdings 2', 192): 11039,
+ ('Wingdings 2', 193): 11202,
+ ('Wingdings 2', 194): 11043,
+ ('Wingdings 2', 195): 11042,
+ ('Wingdings 2', 196): 11203,
+ ('Wingdings 2', 197): 11204,
+ ('Wingdings 2', 198): 128929,
+ ('Wingdings 2', 199): 128930,
+ ('Wingdings 2', 200): 128931,
+ ('Wingdings 2', 201): 128932,
+ ('Wingdings 2', 202): 128933,
+ ('Wingdings 2', 203): 128934,
+ ('Wingdings 2', 204): 128935,
+ ('Wingdings 2', 205): 128936,
+ ('Wingdings 2', 206): 128937,
+ ('Wingdings 2', 207): 128938,
+ ('Wingdings 2', 208): 128939,
+ ('Wingdings 2', 209): 128940,
+ ('Wingdings 2', 210): 128941,
+ ('Wingdings 2', 211): 128942,
+ ('Wingdings 2', 212): 128943,
+ ('Wingdings 2', 213): 128944,
+ ('Wingdings 2', 214): 128945,
+ ('Wingdings 2', 215): 128946,
+ ('Wingdings 2', 216): 128947,
+ ('Wingdings 2', 217): 128948,
+ ('Wingdings 2', 218): 128949,
+ ('Wingdings 2', 219): 128950,
+ ('Wingdings 2', 220): 128951,
+ ('Wingdings 2', 221): 128952,
+ ('Wingdings 2', 222): 128953,
+ ('Wingdings 2', 223): 128954,
+ ('Wingdings 2', 224): 128955,
+ ('Wingdings 2', 225): 128956,
+ ('Wingdings 2', 226): 128957,
+ ('Wingdings 2', 227): 128958,
+ ('Wingdings 2', 228): 128959,
+ ('Wingdings 2', 229): 128960,
+ ('Wingdings 2', 230): 128962,
+ ('Wingdings 2', 231): 128964,
+ ('Wingdings 2', 232): 128966,
+ ('Wingdings 2', 233): 128969,
+ ('Wingdings 2', 234): 128970,
+ ('Wingdings 2', 235): 10038,
+ ('Wingdings 2', 236): 128972,
+ ('Wingdings 2', 237): 128974,
+ ('Wingdings 2', 238): 128976,
+ ('Wingdings 2', 239): 128978,
+ ('Wingdings 2', 240): 10041,
+ ('Wingdings 2', 241): 128963,
+ ('Wingdings 2', 242): 128967,
+ ('Wingdings 2', 243): 10031,
+ ('Wingdings 2', 244): 128973,
+ ('Wingdings 2', 245): 128980,
+ ('Wingdings 2', 246): 11212,
+ ('Wingdings 2', 247): 11213,
+ ('Wingdings 2', 248): 8251,
+ ('Wingdings 2', 249): 8258,
+ ('Wingdings 3', 32): 32,
+ ('Wingdings 3', 33): 11104,
+ ('Wingdings 3', 34): 11106,
+ ('Wingdings 3', 35): 11105,
+ ('Wingdings 3', 36): 11107,
+ ('Wingdings 3', 37): 11110,
+ ('Wingdings 3', 38): 11111,
+ ('Wingdings 3', 39): 11113,
+ ('Wingdings 3', 40): 11112,
+ ('Wingdings 3', 41): 11120,
+ ('Wingdings 3', 42): 11122,
+ ('Wingdings 3', 43): 11121,
+ ('Wingdings 3', 44): 11123,
+ ('Wingdings 3', 45): 11126,
+ ('Wingdings 3', 46): 11128,
+ ('Wingdings 3', 47): 11131,
+ ('Wingdings 3', 48): 11133,
+ ('Wingdings 3', 49): 11108,
+ ('Wingdings 3', 50): 11109,
+ ('Wingdings 3', 51): 11114,
+ ('Wingdings 3', 52): 11116,
+ ('Wingdings 3', 53): 11115,
+ ('Wingdings 3', 54): 11117,
+ ('Wingdings 3', 55): 11085,
+ ('Wingdings 3', 56): 11168,
+ ('Wingdings 3', 57): 11169,
+ ('Wingdings 3', 58): 11170,
+ ('Wingdings 3', 59): 11171,
+ ('Wingdings 3', 60): 11172,
+ ('Wingdings 3', 61): 11173,
+ ('Wingdings 3', 62): 11174,
+ ('Wingdings 3', 63): 11175,
+ ('Wingdings 3', 64): 11152,
+ ('Wingdings 3', 65): 11153,
+ ('Wingdings 3', 66): 11154,
+ ('Wingdings 3', 67): 11155,
+ ('Wingdings 3', 68): 11136,
+ ('Wingdings 3', 69): 11139,
+ ('Wingdings 3', 70): 11134,
+ ('Wingdings 3', 71): 11135,
+ ('Wingdings 3', 72): 11140,
+ ('Wingdings 3', 73): 11142,
+ ('Wingdings 3', 74): 11141,
+ ('Wingdings 3', 75): 11143,
+ ('Wingdings 3', 76): 11151,
+ ('Wingdings 3', 77): 11149,
+ ('Wingdings 3', 78): 11150,
+ ('Wingdings 3', 79): 11148,
+ ('Wingdings 3', 80): 11118,
+ ('Wingdings 3', 81): 11119,
+ ('Wingdings 3', 82): 9099,
+ ('Wingdings 3', 83): 8996,
+ ('Wingdings 3', 84): 8963,
+ ('Wingdings 3', 85): 8997,
+ ('Wingdings 3', 86): 9251,
+ ('Wingdings 3', 87): 9085,
+ ('Wingdings 3', 88): 8682,
+ ('Wingdings 3', 89): 11192,
+ ('Wingdings 3', 90): 129184,
+ ('Wingdings 3', 91): 129185,
+ ('Wingdings 3', 92): 129186,
+ ('Wingdings 3', 93): 129187,
+ ('Wingdings 3', 94): 129188,
+ ('Wingdings 3', 95): 129189,
+ ('Wingdings 3', 96): 129190,
+ ('Wingdings 3', 97): 129191,
+ ('Wingdings 3', 98): 129192,
+ ('Wingdings 3', 99): 129193,
+ ('Wingdings 3', 100): 129194,
+ ('Wingdings 3', 101): 129195,
+ ('Wingdings 3', 102): 129104,
+ ('Wingdings 3', 103): 129106,
+ ('Wingdings 3', 104): 129105,
+ ('Wingdings 3', 105): 129107,
+ ('Wingdings 3', 106): 129108,
+ ('Wingdings 3', 107): 129109,
+ ('Wingdings 3', 108): 129111,
+ ('Wingdings 3', 109): 129110,
+ ('Wingdings 3', 110): 129112,
+ ('Wingdings 3', 111): 129113,
+ ('Wingdings 3', 112): 9650,
+ ('Wingdings 3', 113): 9660,
+ ('Wingdings 3', 114): 9651,
+ ('Wingdings 3', 115): 9661,
+ ('Wingdings 3', 116): 9664,
+ ('Wingdings 3', 117): 9654,
+ ('Wingdings 3', 118): 9665,
+ ('Wingdings 3', 119): 9655,
+ ('Wingdings 3', 120): 9699,
+ ('Wingdings 3', 121): 9698,
+ ('Wingdings 3', 122): 9700,
+ ('Wingdings 3', 123): 9701,
+ ('Wingdings 3', 124): 128896,
+ ('Wingdings 3', 125): 128898,
+ ('Wingdings 3', 126): 128897,
+ ('Wingdings 3', 128): 128899,
+ ('Wingdings 3', 129): 11205,
+ ('Wingdings 3', 130): 11206,
+ ('Wingdings 3', 131): 11207,
+ ('Wingdings 3', 132): 11208,
+ ('Wingdings 3', 133): 11164,
+ ('Wingdings 3', 134): 11166,
+ ('Wingdings 3', 135): 11165,
+ ('Wingdings 3', 136): 11167,
+ ('Wingdings 3', 137): 129040,
+ ('Wingdings 3', 138): 129042,
+ ('Wingdings 3', 139): 129041,
+ ('Wingdings 3', 140): 129043,
+ ('Wingdings 3', 141): 129044,
+ ('Wingdings 3', 142): 129046,
+ ('Wingdings 3', 143): 129045,
+ ('Wingdings 3', 144): 129047,
+ ('Wingdings 3', 145): 129048,
+ ('Wingdings 3', 146): 129050,
+ ('Wingdings 3', 147): 129049,
+ ('Wingdings 3', 148): 129051,
+ ('Wingdings 3', 149): 129052,
+ ('Wingdings 3', 150): 129054,
+ ('Wingdings 3', 151): 129053,
+ ('Wingdings 3', 152): 129055,
+ ('Wingdings 3', 153): 129024,
+ ('Wingdings 3', 154): 129026,
+ ('Wingdings 3', 155): 129025,
+ ('Wingdings 3', 156): 129027,
+ ('Wingdings 3', 157): 129028,
+ ('Wingdings 3', 158): 129030,
+ ('Wingdings 3', 159): 129029,
+ ('Wingdings 3', 160): 129031,
+ ('Wingdings 3', 161): 129032,
+ ('Wingdings 3', 162): 129034,
+ ('Wingdings 3', 163): 129033,
+ ('Wingdings 3', 164): 129035,
+ ('Wingdings 3', 165): 129056,
+ ('Wingdings 3', 166): 129058,
+ ('Wingdings 3', 167): 129060,
+ ('Wingdings 3', 168): 129062,
+ ('Wingdings 3', 169): 129064,
+ ('Wingdings 3', 170): 129066,
+ ('Wingdings 3', 171): 129068,
+ ('Wingdings 3', 172): 129180,
+ ('Wingdings 3', 173): 129181,
+ ('Wingdings 3', 174): 129182,
+ ('Wingdings 3', 175): 129183,
+ ('Wingdings 3', 176): 129070,
+ ('Wingdings 3', 177): 129072,
+ ('Wingdings 3', 178): 129074,
+ ('Wingdings 3', 179): 129076,
+ ('Wingdings 3', 180): 129078,
+ ('Wingdings 3', 181): 129080,
+ ('Wingdings 3', 182): 129082,
+ ('Wingdings 3', 183): 129081,
+ ('Wingdings 3', 184): 129083,
+ ('Wingdings 3', 185): 129176,
+ ('Wingdings 3', 186): 129178,
+ ('Wingdings 3', 187): 129177,
+ ('Wingdings 3', 188): 129179,
+ ('Wingdings 3', 189): 129084,
+ ('Wingdings 3', 190): 129086,
+ ('Wingdings 3', 191): 129085,
+ ('Wingdings 3', 192): 129087,
+ ('Wingdings 3', 193): 129088,
+ ('Wingdings 3', 194): 129090,
+ ('Wingdings 3', 195): 129089,
+ ('Wingdings 3', 196): 129091,
+ ('Wingdings 3', 197): 129092,
+ ('Wingdings 3', 198): 129094,
+ ('Wingdings 3', 199): 129093,
+ ('Wingdings 3', 200): 129095,
+ ('Wingdings 3', 201): 11176,
+ ('Wingdings 3', 202): 11177,
+ ('Wingdings 3', 203): 11178,
+ ('Wingdings 3', 204): 11179,
+ ('Wingdings 3', 205): 11180,
+ ('Wingdings 3', 206): 11181,
+ ('Wingdings 3', 207): 11182,
+ ('Wingdings 3', 208): 11183,
+ ('Wingdings 3', 209): 129120,
+ ('Wingdings 3', 210): 129122,
+ ('Wingdings 3', 211): 129121,
+ ('Wingdings 3', 212): 129123,
+ ('Wingdings 3', 213): 129124,
+ ('Wingdings 3', 214): 129125,
+ ('Wingdings 3', 215): 129127,
+ ('Wingdings 3', 216): 129126,
+ ('Wingdings 3', 217): 129136,
+ ('Wingdings 3', 218): 129138,
+ ('Wingdings 3', 219): 129137,
+ ('Wingdings 3', 220): 129139,
+ ('Wingdings 3', 221): 129140,
+ ('Wingdings 3', 222): 129141,
+ ('Wingdings 3', 223): 129143,
+ ('Wingdings 3', 224): 129142,
+ ('Wingdings 3', 225): 129152,
+ ('Wingdings 3', 226): 129154,
+ ('Wingdings 3', 227): 129153,
+ ('Wingdings 3', 228): 129155,
+ ('Wingdings 3', 229): 129156,
+ ('Wingdings 3', 230): 129157,
+ ('Wingdings 3', 231): 129159,
+ ('Wingdings 3', 232): 129158,
+ ('Wingdings 3', 233): 129168,
+ ('Wingdings 3', 234): 129170,
+ ('Wingdings 3', 235): 129169,
+ ('Wingdings 3', 236): 129171,
+ ('Wingdings 3', 237): 129172,
+ ('Wingdings 3', 238): 129174,
+ ('Wingdings 3', 239): 129173,
+ ('Wingdings 3', 240): 129175,
+}
diff --git a/mineru/model/utils/docx/mammoth/documents.py b/mineru/model/utils/docx/mammoth/documents.py
new file mode 100644
index 00000000..fbd71baa
--- /dev/null
+++ b/mineru/model/utils/docx/mammoth/documents.py
@@ -0,0 +1,286 @@
+import cobble
+
+
+class Element(object):
+ def copy(self, **kwargs):
+ return cobble.copy(self, **kwargs)
+
+
+class HasChildren(Element):
+ children = cobble.field()
+
+
+class Document(HasChildren):
+ notes = cobble.field()
+ comments = cobble.field()
+
+class Paragraph(HasChildren):
+ style_id = cobble.field()
+ style_name = cobble.field()
+ numbering = cobble.field()
+ alignment = cobble.field()
+ indent = cobble.field()
+
+
+class ParagraphIndent(object):
+ start = cobble.field()
+ end = cobble.field()
+ first_line = cobble.field()
+ hanging = cobble.field()
+
+
+class Indent(object):
+ left = cobble.field()
+ right = cobble.field()
+ first_line = cobble.field()
+ hanging = cobble.field()
+
+
+class Run(HasChildren):
+ style_id = cobble.field()
+ style_name = cobble.field()
+ is_bold = cobble.field()
+ is_italic = cobble.field()
+ is_underline = cobble.field()
+ is_strikethrough = cobble.field()
+ is_all_caps = cobble.field()
+ is_small_caps = cobble.field()
+ vertical_alignment = cobble.field()
+ font = cobble.field()
+ font_size = cobble.field()
+ highlight = cobble.field()
+
+class Text(Element):
+ value = cobble.field()
+
+class Hyperlink(HasChildren):
+ href = cobble.field()
+ anchor = cobble.field()
+ target_frame = cobble.field()
+
+class Checkbox(Element):
+ checked = cobble.field()
+
+checkbox = Checkbox
+
+class Table(HasChildren):
+ style_id = cobble.field()
+ style_name = cobble.field()
+
+class TableRow(HasChildren):
+ is_header = cobble.field()
+
+class TableCell(HasChildren):
+ colspan = cobble.field()
+ rowspan = cobble.field()
+
+class TableCellUnmerged:
+ children = cobble.field()
+ colspan = cobble.field()
+ rowspan = cobble.field()
+ vmerge = cobble.field()
+
+ def _accept1(self, visitor, arg0):
+ return visitor.visit_table_cell(self, arg0)
+
+ def copy(self, **kwargs):
+ return cobble.copy(self, **kwargs)
+
+class Break(Element):
+ break_type = cobble.field()
+
+line_break = Break("line")
+page_break = Break("page")
+column_break = Break("column")
+
+
+class Tab(Element):
+ pass
+
+
+class Image(Element):
+ alt_text = cobble.field()
+ content_type = cobble.field()
+ open = cobble.field()
+
+
+def document(children, notes=None, comments=None):
+ if notes is None:
+ notes = Notes({})
+ if comments is None:
+ comments = []
+ return Document(children, notes, comments=comments)
+
+def paragraph(children, style_id=None, style_name=None, numbering=None, alignment=None, indent=None):
+ if indent is None:
+ indent = paragraph_indent()
+
+ return Paragraph(children, style_id, style_name, numbering, alignment=alignment, indent=indent)
+
+def paragraph_indent(start=None, end=None, first_line=None, hanging=None):
+ return ParagraphIndent(start=start, end=end, first_line=first_line, hanging=hanging)
+
+def run(
+ children,
+ style_id=None,
+ style_name=None,
+ is_bold=None,
+ is_italic=None,
+ is_underline=None,
+ is_strikethrough=None,
+ is_all_caps=None,
+ is_small_caps=None,
+ vertical_alignment=None,
+ font=None,
+ font_size=None,
+ highlight=None,
+):
+ if vertical_alignment is None:
+ vertical_alignment = VerticalAlignment.baseline
+ return Run(
+ children=children,
+ style_id=style_id,
+ style_name=style_name,
+ is_bold=bool(is_bold),
+ is_italic=bool(is_italic),
+ is_underline=bool(is_underline),
+ is_strikethrough=bool(is_strikethrough),
+ is_all_caps=bool(is_all_caps),
+ is_small_caps=bool(is_small_caps),
+ vertical_alignment=vertical_alignment,
+ font=font,
+ font_size=font_size,
+ highlight=highlight,
+ )
+
+class VerticalAlignment(object):
+ baseline = "baseline"
+ superscript = "superscript"
+ subscript = "subscript"
+
+text = Text
+
+_tab = Tab()
+
+def tab():
+ return _tab
+
+
+image = Image
+
+def hyperlink(children, href=None, anchor=None, target_frame=None):
+ return Hyperlink(href=href, anchor=anchor, target_frame=target_frame, children=children)
+
+
+class Bookmark(Element):
+ name = cobble.field()
+
+bookmark = Bookmark
+
+
+def table(children, style_id=None, style_name=None):
+ return Table(children=children, style_id=style_id, style_name=style_name)
+
+def table_row(children, is_header=None):
+ return TableRow(children=children, is_header=bool(is_header))
+
+def table_cell(children, colspan=None, rowspan=None):
+ if colspan is None:
+ colspan = 1
+ if rowspan is None:
+ rowspan = 1
+ return TableCell(children=children, colspan=colspan, rowspan=rowspan)
+
+def table_cell_unmerged(children, colspan, rowspan, vmerge):
+ return TableCellUnmerged(children=children, colspan=colspan, rowspan=rowspan, vmerge=vmerge)
+
+def numbering_level(level_index, is_ordered):
+ return _NumberingLevel(str(level_index), bool(is_ordered))
+
+class _NumberingLevel(object):
+ level_index = cobble.field()
+ is_ordered = cobble.field()
+
+class Note(Element):
+ note_type = cobble.field()
+ note_id = cobble.field()
+ body = cobble.field()
+
+
+note = Note
+
+
+class Notes(object):
+ def __init__(self, notes):
+ self._notes = notes
+
+ def find_note(self, note_type, note_id):
+ return self._notes[(note_type, note_id)]
+
+ def resolve(self, reference):
+ return self.find_note(reference.note_type, reference.note_id)
+
+ def __eq__(self, other):
+ return isinstance(other, Notes) and self._notes == other._notes
+
+ def __ne__(self, other):
+ return not (self == other)
+
+def notes(notes_list):
+ return Notes(dict(
+ (_note_key(note), note)
+ for note in notes_list
+ ))
+
+def _note_key(note):
+ return (note.note_type, note.note_id)
+
+class NoteReference(Element):
+ note_type = cobble.field()
+ note_id = cobble.field()
+
+note_reference = NoteReference
+
+
+class Comment(object):
+ comment_id = cobble.field()
+ body = cobble.field()
+ author_name = cobble.field()
+ author_initials = cobble.field()
+
+def comment(comment_id, body, author_name=None, author_initials=None):
+ return Comment(
+ comment_id=comment_id,
+ body=body,
+ author_name=author_name,
+ author_initials=author_initials,
+ )
+
+class CommentReference(Element):
+ comment_id = cobble.field()
+
+comment_reference = CommentReference
+
+def element_visitor(args):
+ return cobble.visitor(Element, args=args)
diff --git a/mineru/model/utils/docx/mammoth/html/__init__.py b/mineru/model/utils/docx/mammoth/html/__init__.py
new file mode 100644
index 00000000..2ad3791d
--- /dev/null
+++ b/mineru/model/utils/docx/mammoth/html/__init__.py
@@ -0,0 +1,135 @@
+from ..lists import flat_map
+from .nodes import TextNode, Tag, Element, ForceWrite, NodeVisitor
+
+
+def text(value):
+ return TextNode(value)
+
+
+def tag(tag_names, attributes=None, collapsible=None, separator=None):
+ if not isinstance(tag_names, list):
+ tag_names = [tag_names]
+ if attributes is None:
+ attributes = {}
+ return Tag(tag_names=tag_names, attributes=attributes, collapsible=bool(collapsible), separator=separator)
+
+
+def element(tag_names, attributes=None, children=None, collapsible=None, separator=None):
+ if children is None:
+ children = []
+
+ element_tag = tag(tag_names=tag_names, attributes=attributes, collapsible=collapsible, separator=separator)
+ return Element(element_tag, children)
+
+
+def collapsible_element(tag_names, attributes=None, children=None):
+ return element(tag_names, attributes, children, collapsible=True)
+
+
+force_write = ForceWrite()
+
+
+def strip_empty(nodes):
+ return flat_map(_strip_empty_node, nodes)
+
+
+def _strip_empty_node(node):
+ return StripEmpty().visit(node)
+
+
+class StripEmpty(NodeVisitor):
+ def visit_text_node(self, node):
+ if node.value:
+ return [node]
+ else:
+ return []
+
+ def visit_element(self, element):
+ children = strip_empty(element.children)
+ if len(children) == 0 and not element.is_void():
+ return []
+ else:
+ return [Element(element.tag, children)]
+
+ def visit_force_write(self, node):
+ return [node]
+
+
+def collapse(nodes):
+ collapsed = []
+
+ for node in nodes:
+ _collapsing_add(collapsed, node)
+
+ return collapsed
+
+class _CollapseNode(NodeVisitor):
+ def visit_text_node(self, node):
+ return node
+
+ def visit_element(self, element):
+ return Element(element.tag, collapse(element.children))
+
+ def visit_force_write(self, node):
+ return node
+
+_collapse_node = _CollapseNode().visit
+
+
+def _collapsing_add(collapsed, node):
+ collapsed_node = _collapse_node(node)
+ if not _try_collapse(collapsed, collapsed_node):
+ collapsed.append(collapsed_node)
+
+def _try_collapse(collapsed, node):
+ if not collapsed:
+ return False
+
+ last = collapsed[-1]
+ if not isinstance(last, Element) or not isinstance(node, Element):
+ return False
+
+ if not node.collapsible:
+ return False
+
+ if not _is_match(last, node):
+ return False
+
+ if node.separator:
+ last.children.append(text(node.separator))
+
+ for child in node.children:
+ _collapsing_add(last.children, child)
+
+ return True
+
+def _is_match(first, second):
+ return first.tag_name in second.tag_names and first.attributes == second.attributes
+
+
+def write(writer, nodes):
+ visitor = _NodeWriter(writer)
+ visitor.visit_all(nodes)
+
+
+class _NodeWriter(NodeVisitor):
+ def __init__(self, writer):
+ self._writer = writer
+
+ def visit_text_node(self, node):
+ self._writer.text(node.value)
+
+ def visit_element(self, element):
+ if element.is_void():
+ self._writer.self_closing(element.tag_name, element.attributes)
+ else:
+ self._writer.start(element.tag_name, element.attributes)
+ self.visit_all(element.children)
+ self._writer.end(element.tag_name)
+
+ def visit_force_write(self, element):
+ pass
+
+ def visit_all(self, nodes):
+ for node in nodes:
+ self.visit(node)
diff --git a/mineru/model/utils/docx/mammoth/html/nodes.py b/mineru/model/utils/docx/mammoth/html/nodes.py
new file mode 100644
index 00000000..321aee24
--- /dev/null
+++ b/mineru/model/utils/docx/mammoth/html/nodes.py
@@ -0,0 +1,61 @@
+import cobble
+
+
+class Node(object):
+ pass
+
+
+class TextNode(Node):
+ value = cobble.field()
+
+
+class Tag(object):
+ tag_names = cobble.field()
+ attributes = cobble.field()
+ collapsible = cobble.field()
+ separator = cobble.field()
+
+ @property
+ def tag_name(self):
+ return self.tag_names[0]
+
+
+class Element(Node):
+ tag = cobble.field()
+ children = cobble.field()
+
+ @property
+ def tag_name(self):
+ return self.tag.tag_name
+
+ @property
+ def tag_names(self):
+ return self.tag.tag_names
+
+ @property
+ def attributes(self):
+ return self.tag.attributes
+
+ @property
+ def collapsible(self):
+ return self.tag.collapsible
+
+ @property
+ def separator(self):
+ return self.tag.separator
+
+ _VOID_TAG_NAMES = set(["br", "hr", "img", "input"])
+
+ def is_void(self):
+ return not self.children and self.tag_name in self._VOID_TAG_NAMES
+
+
+class ForceWrite(Node):
+ pass
+
+
+NodeVisitor = cobble.visitor(Node)
diff --git a/mineru/model/utils/docx/mammoth/html_paths.py b/mineru/model/utils/docx/mammoth/html_paths.py
new file mode 100644
index 00000000..4da5c058
--- /dev/null
+++ b/mineru/model/utils/docx/mammoth/html_paths.py
@@ -0,0 +1,58 @@
+import cobble
+
+from . import html
+
+
+def path(elements):
+ return HtmlPath(elements)
+
+
+def element(names, attributes=None, class_names=None, fresh=None, separator=None):
+ if attributes is None:
+ attributes = {}
+ if class_names is None:
+ class_names = []
+ if fresh is None:
+ fresh = False
+ if class_names:
+ attributes["class"] = " ".join(class_names)
+
+ return HtmlPathElement(html.tag(
+ tag_names=names,
+ attributes=attributes,
+ collapsible=not fresh,
+ separator=separator,
+ ))
+
+
+class HtmlPath(object):
+ elements = cobble.field()
+
+ def wrap(self, generate_nodes):
+ nodes = generate_nodes()
+
+ for element in reversed(self.elements):
+ nodes = element.wrap_nodes(nodes)
+
+ return nodes
+
+
+class HtmlPathElement(object):
+ tag = cobble.field()
+
+ def wrap(self, generate_nodes):
+ return self.wrap_nodes(generate_nodes())
+
+ def wrap_nodes(self, nodes):
+ element = html.Element(self.tag, nodes)
+ return [element]
+
+empty = path([])
+
+
+class ignore(object):
+ @staticmethod
+ def wrap(generate_nodes):
+ return []
diff --git a/mineru/model/utils/docx/mammoth/lists.py b/mineru/model/utils/docx/mammoth/lists.py
new file mode 100644
index 00000000..90a6940d
--- /dev/null
+++ b/mineru/model/utils/docx/mammoth/lists.py
@@ -0,0 +1,40 @@
+import sys
+
+
+def flatten(values):
+ return flat_map(lambda x: x, values)
+
+
+def unique(values):
+ output = []
+ seen = set()
+ for value in values:
+ if value not in seen:
+ seen.add(value)
+ output.append(value)
+ return output
+
+
+def flat_map(func, values):
+ return [
+ element
+ for value in values
+ for element in func(value)
+ ]
+
+
+def find_index(predicate, values):
+ for index, value in enumerate(values):
+ if predicate(value):
+ return index
+
+
+if sys.version_info[0] == 2:
+ map = map
+ filter = filter
+else:
+ import builtins
+ def map(*args, **kwargs):
+ return list(builtins.map(*args, **kwargs))
+ def filter(*args, **kwargs):
+ return list(builtins.filter(*args, **kwargs))
diff --git a/mineru/model/utils/docx/mammoth/results.py b/mineru/model/utils/docx/mammoth/results.py
new file mode 100644
index 00000000..fb12ee33
--- /dev/null
+++ b/mineru/model/utils/docx/mammoth/results.py
@@ -0,0 +1,42 @@
+import collections
+
+from .lists import unique
+
+
+class Result(object):
+ def __init__(self, value, messages):
+ self.value = value
+ self.messages = unique(messages)
+
+ def map(self, func):
+ return Result(func(self.value), self.messages)
+
+ def bind(self, func):
+ result = func(self.value)
+ return Result(result.value, self.messages + result.messages)
+
+
+Message = collections.namedtuple("Message", ["type", "message"])
+
+
+def warning(message):
+ return Message("warning", message)
+
+
+def success(value):
+ return Result(value, [])
+
+
+def combine(results):
+ values = []
+ messages = []
+ for result in results:
+ values.append(result.value)
+ for message in result.messages:
+ messages.append(message)
+
+ return Result(values, messages)
+
+
+def map(func, *args):
+ return combine(args).map(lambda values: func(*values))
diff --git a/mineru/model/utils/docx/mammoth/styles_xml.py b/mineru/model/utils/docx/mammoth/styles_xml.py
new file mode 100644
index 00000000..31d0f2e0
--- /dev/null
+++ b/mineru/model/utils/docx/mammoth/styles_xml.py
@@ -0,0 +1,117 @@
+import collections
+
+
+class Styles(object):
+ @staticmethod
+ def create(paragraph_styles=None, character_styles=None, table_styles=None, numbering_styles=None):
+ if paragraph_styles is None:
+ paragraph_styles = {}
+ if character_styles is None:
+ character_styles = {}
+ if table_styles is None:
+ table_styles = {}
+ if numbering_styles is None:
+ numbering_styles = {}
+
+ return Styles(
+ paragraph_styles=paragraph_styles,
+ character_styles=character_styles,
+ table_styles=table_styles,
+ numbering_styles=numbering_styles,
+ )
+
+ def __init__(self, paragraph_styles, character_styles, table_styles, numbering_styles):
+ self._paragraph_styles = paragraph_styles
+ self._character_styles = character_styles
+ self._table_styles = table_styles
+ self._numbering_styles = numbering_styles
+
+ def find_paragraph_style_by_id(self, style_id):
+ return self._paragraph_styles.get(style_id)
+
+ def find_character_style_by_id(self, style_id):
+ return self._character_styles.get(style_id)
+
+ def find_table_style_by_id(self, style_id):
+ return self._table_styles.get(style_id)
+
+ def find_numbering_style_by_id(self, style_id):
+ return self._numbering_styles.get(style_id)
+
+
+Styles.EMPTY = Styles(
+ paragraph_styles={},
+ character_styles={},
+ table_styles={},
+ numbering_styles={},
+)
+
+
+def read_styles_xml_element(element):
+ paragraph_styles = {}
+ character_styles = {}
+ table_styles = {}
+ numbering_styles = {}
+ styles = {
+ "paragraph": paragraph_styles,
+ "character": character_styles,
+ "table": table_styles,
+ "numbering": numbering_styles,
+ }
+
+ for style_element in element.find_children("w:style"):
+ element_type = style_element.attributes["w:type"]
+ if element_type == "numbering":
+ style = _read_numbering_style_element(style_element)
+ else:
+ style = _read_style_element(style_element)
+
+ style_set = styles.get(element_type)
+
+ # Per 17.7.4.17 style (Style Definition) of ECMA-376 4th edition Part 1:
+ #
+ # > If multiple style definitions each declare the same value for their
+ # > styleId, then the first such instance shall keep its current
+ # > identifier with all other instances being reassigned in any manner
+ # > desired.
+ #
+ # For the purpose of conversion, there's no point holding onto styles
+ # with reassigned style IDs, so we ignore such style definitions.
+
+ if style_set is not None and style.style_id not in style_set:
+ style_set[style.style_id] = style
+
+ return Styles(
+ paragraph_styles=paragraph_styles,
+ character_styles=character_styles,
+ table_styles=table_styles,
+ numbering_styles=numbering_styles,
+ )
+
+
+Style = collections.namedtuple("Style", ["style_id", "name"])
+
+
+def _read_style_element(element):
+ style_id = _read_style_id(element)
+ name = element.find_child_or_null("w:name").attributes.get("w:val")
+ return Style(style_id=style_id, name=name)
+
+
+NumberingStyle = collections.namedtuple("NumberingStyle", ["style_id", "num_id"])
+
+
+def _read_numbering_style_element(element):
+ style_id = _read_style_id(element)
+
+ num_id = element \
+ .find_child_or_null("w:pPr") \
+ .find_child_or_null("w:numPr") \
+ .find_child_or_null("w:numId") \
+ .attributes.get("w:val")
+
+ return NumberingStyle(style_id=style_id, num_id=num_id)
+
+
+def _read_style_id(element):
+ return element.attributes["w:styleId"]
diff --git a/mineru/model/utils/docx/mammoth/transforms.py b/mineru/model/utils/docx/mammoth/transforms.py
new file mode 100644
index 00000000..c03bace2
--- /dev/null
+++ b/mineru/model/utils/docx/mammoth/transforms.py
@@ -0,0 +1,56 @@
+from . import documents
+
+
+def paragraph(transform_paragraph):
+ return element_of_type(documents.Paragraph, transform_paragraph)
+
+
+def run(transform_run):
+ return element_of_type(documents.Run, transform_run)
+
+
+def element_of_type(element_type, transform):
+ def transform_element(element):
+ if isinstance(element, element_type):
+ return transform(element)
+ else:
+ return element
+
+ return _each_element(transform_element)
+
+
+def _each_element(transform_element):
+ def transform_element_and_children(element):
+ if isinstance(element, (documents.HasChildren, documents.TableCellUnmerged)):
+ children = list(map(transform_element_and_children, element.children))
+ element = element.copy(children=children)
+
+ return transform_element(element)
+
+ return transform_element_and_children
+
+
+def get_descendants_of_type(element, element_type):
+ return list(filter(
+ lambda descendant: isinstance(descendant, element_type),
+ get_descendants(element),
+ ))
+
+
+def get_descendants(element):
+ descendants = []
+
+ def visit(element):
+ descendants.append(element)
+
+ _visit_descendants(element, visit)
+
+ return descendants
+
+
+def _visit_descendants(element, visit):
+ if isinstance(element, documents.HasChildren):
+ for child in element.children:
+ _visit_descendants(child, visit)
+ visit(child)
+
diff --git a/mineru/model/utils/docx/mammoth/uris.py b/mineru/model/utils/docx/mammoth/uris.py
new file mode 100644
index 00000000..255dabe2
--- /dev/null
+++ b/mineru/model/utils/docx/mammoth/uris.py
@@ -0,0 +1,12 @@
+def uri_to_zip_entry_name(base, uri):
+ if uri.startswith("/"):
+ return uri[1:]
+ else:
+ return base + "/" + uri
+
+
+def replace_fragment(uri, fragment):
+ hash_index = uri.find("#")
+ if hash_index != -1:
+ uri = uri[:hash_index]
+ return uri + "#" + fragment
diff --git a/mineru/model/utils/docx/mammoth/writers/__init__.py b/mineru/model/utils/docx/mammoth/writers/__init__.py
new file mode 100644
index 00000000..08ac3a88
--- /dev/null
+++ b/mineru/model/utils/docx/mammoth/writers/__init__.py
@@ -0,0 +1,19 @@
+from .html import HtmlWriter
+from .markdown import MarkdownWriter
+
+
+def writer(output_format=None):
+ if output_format is None:
+ output_format = "html"
+
+ return _writers[output_format]()
+
+
+def formats():
+ return _writers.keys()
+
+
+_writers = {
+ "html": HtmlWriter,
+ "markdown": MarkdownWriter,
+}
diff --git a/mineru/model/utils/docx/mammoth/writers/abc.py b/mineru/model/utils/docx/mammoth/writers/abc.py
new file mode 100644
index 00000000..48358221
--- /dev/null
+++ b/mineru/model/utils/docx/mammoth/writers/abc.py
@@ -0,0 +1,31 @@
+from __future__ import absolute_import
+
+import abc
+
+
+class Writer(object):
+ __metaclass__ = abc.ABCMeta
+
+ @abc.abstractmethod
+ def text(self, text):
+ pass
+
+ @abc.abstractmethod
+ def start(self, name, attributes=None):
+ pass
+
+ @abc.abstractmethod
+ def end(self, name):
+ pass
+
+ @abc.abstractmethod
+ def self_closing(self, name, attributes=None):
+ pass
+
+ @abc.abstractmethod
+ def append(self, html):
+ pass
+
+ @abc.abstractmethod
+ def as_string(self):
+ pass
diff --git a/mineru/model/utils/docx/mammoth/writers/html.py b/mineru/model/utils/docx/mammoth/writers/html.py
new file mode 100644
index 00000000..53eb9201
--- /dev/null
+++ b/mineru/model/utils/docx/mammoth/writers/html.py
@@ -0,0 +1,43 @@
+from __future__ import unicode_literals
+from xml.sax.saxutils import escape
+
+from .abc import Writer
+
+
+class HtmlWriter(Writer):
+ def __init__(self):
+ self._fragments = []
+
+ def text(self, text):
+ self._fragments.append(_escape_html(text))
+
+ def start(self, name, attributes=None):
+ attribute_string = _generate_attribute_string(attributes)
+ self._fragments.append("<{0}{1}>".format(name, attribute_string))
+
+ def end(self, name):
+ self._fragments.append("</{0}>".format(name))
+
+ def self_closing(self, name, attributes=None):
+ attribute_string = _generate_attribute_string(attributes)
+ self._fragments.append("<{0}{1} />".format(name, attribute_string))
+
+ def append(self, html):
+ self._fragments.append(html)
+
+ def as_string(self):
+ return "".join(self._fragments)
+
+
+def _escape_html(text):
+ return escape(text, {'"': "&quot;"})
+
+
+def _generate_attribute_string(attributes):
+ if attributes is None:
+ return ""
+ else:
+ return "".join(
+ ' {0}="{1}"'.format(key, _escape_html(attributes[key]))
+ for key in sorted(attributes)
+ )
diff --git a/mineru/model/utils/docx/mammoth/writers/markdown.py b/mineru/model/utils/docx/mammoth/writers/markdown.py
new file mode 100644
index 00000000..7c203c2e
--- /dev/null
+++ b/mineru/model/utils/docx/mammoth/writers/markdown.py
@@ -0,0 +1,203 @@
+from __future__ import unicode_literals
+
+from .abc import Writer
+
+import re
+
+
+class _WriterOutput(object):
+ def __init__(self, start, end=None, generate_end=None, anchor_position=None):
+ if generate_end is None:
+ generate_end = _constant(end)
+
+ self.start = start
+ self.generate_end = generate_end
+ self.anchor_position = anchor_position
+
+
+def _constant(value):
+ def get():
+ return value
+
+ return get
+
+
+class _MarkdownState(object):
+ def __init__(self):
+ self._list_state_stack = []
+ self.list_state = None
+ self.list_item_has_closed = False
+
+ def update_list_state(self, list_state):
+ self._list_state_stack.append(self.list_state)
+ self.list_state = list_state
+
+ def pop_list_state(self):
+ self.list_state = self._list_state_stack.pop()
+
+
+class _MarkdownListState(object):
+ def __init__(self, ordered, indentation):
+ self.ordered = ordered
+ self.count = 0
+ self.indentation = indentation
+
+
+def _symmetric_wrapped(end):
+ return _Wrapped(end, end)
+
+
+class _Wrapped(object):
+ def __init__(self, start, end):
+ self._start = start
+ self._end = end
+
+ def __call__(self, attributes, markdown_state):
+ return _WriterOutput(self._start, self._end)
+
+
+def _hyperlink(attributes, markdown_state):
+ href = attributes.get("href", "")
+ if href:
+ return _WriterOutput(
+ "[", "]({0})".format(href),
+ anchor_position="before",
+ )
+ else:
+ return _default_output
+
+
+def _image(attributes, markdown_state):
+ src = attributes.get("src", "")
+ alt_text = attributes.get("alt", "")
+ if src or alt_text:
+ return _WriterOutput("![{0}]({1})".format(alt_text, src), "")
+ else:
+ return _default_output
+
+
+def _list(ordered):
+ def call(attributes, markdown_state):
+ if markdown_state.list_state is None:
+ start = ""
+ end_text = "\n"
+ indentation = 0
+ else:
+ start = "\n"
+ end_text = ""
+ indentation = markdown_state.list_state.indentation + 1
+
+ def generate_end():
+ markdown_state.pop_list_state()
+ return end_text
+
+ markdown_state.update_list_state(_MarkdownListState(
+ ordered=ordered,
+ indentation=indentation,
+ ))
+
+ return _WriterOutput(start, generate_end=generate_end)
+
+ return call
+
+
+def _list_item(attributes, markdown_state):
+ markdown_state.list_item_has_closed = False
+
+ list_state = markdown_state.list_state or _MarkdownListState(ordered=False, indentation=0)
+ list_state.count += 1
+
+ if list_state.ordered:
+ bullet = "{0}.".format(list_state.count)
+ else:
+ bullet = "-"
+
+ def generate_end():
+ if markdown_state.list_item_has_closed:
+ return ""
+ else:
+ markdown_state.list_item_has_closed = True
+ return "\n"
+
+ return _WriterOutput(
+ start=("\t" * list_state.indentation) + bullet + " ",
+ generate_end=generate_end
+ )
+
+
+def _init_writers():
+ writers = {
+ "p": _Wrapped("", "\n\n"),
+ "br": _Wrapped("", " \n"),
+ "strong": _symmetric_wrapped("__"),
+ "em": _symmetric_wrapped("*"),
+ "a": _hyperlink,
+ "img": _image,
+ "ol": _list(ordered=True),
+ "ul": _list(ordered=False),
+ "li": _list_item,
+ }
+
+ for level in range(1, 7):
+ writers["h{0}".format(level)] = _Wrapped("#" * level + " ", "\n\n")
+
+ return writers
+
+
+_writers = _init_writers()
+_default_output = _WriterOutput("", "")
+
+def _default_writer(attributes, markdown_state):
+ return _default_output
+
+
+class MarkdownWriter(Writer):
+ def __init__(self):
+ self._fragments = []
+ self._element_stack = []
+ self._markdown_state = _MarkdownState()
+
+ def text(self, text):
+ self._fragments.append(_escape_markdown(text))
+
+ def start(self, name, attributes=None):
+ if attributes is None:
+ attributes = {}
+
+ output = _writers.get(name, _default_writer)(attributes, self._markdown_state)
+ self._element_stack.append(output.generate_end)
+
+ anchor_before_start = output.anchor_position == "before"
+ if anchor_before_start:
+ self._write_anchor(attributes)
+
+ self._fragments.append(output.start)
+
+ if not anchor_before_start:
+ self._write_anchor(attributes)
+
+
+
+ def end(self, name):
+ end = self._element_stack.pop()
+ output = end()
+ self._fragments.append(output)
+
+ def self_closing(self, name, attributes=None):
+ self.start(name, attributes)
+ self.end(name)
+
+ def append(self, other):
+ self._fragments.append(other)
+
+ def as_string(self):
+ return "".join(self._fragments)
+
+ def _write_anchor(self, attributes):
+ html_id = attributes.get("id")
+ if html_id:
+ self._fragments.append('<a id="{0}"></a>'.format(html_id))
+
+
+def _escape_markdown(value):
+ return re.sub(r"([\`\*_\{\}\[\]\(\)\#\+\-\.\!])", r"\\\1", re.sub("\\\\", "\\\\\\\\", value))
diff --git a/mineru/model/utils/docx/mammoth/xmlparser.py b/mineru/model/utils/docx/mammoth/xmlparser.py
new file mode 100644
index 00000000..abbc0790
--- /dev/null
+++ b/mineru/model/utils/docx/mammoth/xmlparser.py
@@ -0,0 +1,167 @@
+import xml.dom.minidom
+
+import cobble
+
+
+class XmlElement(object):
+ name = cobble.field()
+ attributes = cobble.field()
+ children = cobble.field()
+
+ def find_child_or_null(self, name):
+ return self.find_child(name) or null_xml_element
+
+ def find_child(self, name):
+ for child in self.children:
+ if isinstance(child, XmlElement) and child.name == name:
+ return child
+
+
+ def find_children(self, name):
+ return XmlElementList(filter(
+ lambda child: child.node_type == node_types.element and child.name == name,
+ self.children
+ ))
+
+
+class XmlElementList(object):
+ def __init__(self, elements):
+ self._elements = elements
+
+ def __iter__(self):
+ return iter(self._elements)
+
+ def find_children(self, name):
+ children = []
+ for element in self._elements:
+ for child in element.find_children(name):
+ children.append(child)
+ return XmlElementList(children)
+
+
+class NullXmlElement(object):
+ attributes = {}
+ children = []
+
+ def find_child_or_null(self, name):
+ return self
+
+ def find_child(self, name):
+ return None
+
+
+null_xml_element = NullXmlElement()
+
+
+class XmlText(object):
+ value = cobble.field()
+
+
+def element(name, attributes=None, children=None):
+ return XmlElement(name, attributes or {}, children or [])
+
+text = XmlText
+
+
+class node_types(object):
+ element = 1
+ text = 3
+
+
+XmlElement.node_type = node_types.element
+XmlText.node_type = node_types.text
+
+
+
+def parse_xml(fileobj, namespace_mapping=None):
+ if namespace_mapping is None:
+ namespace_prefixes = {}
+ else:
+ namespace_prefixes = dict((uri, prefix) for prefix, uri in namespace_mapping)
+
+ document = xml.dom.minidom.parse(fileobj)
+
+ def convert_node(node):
+ if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+ return convert_element(node)
+ elif node.nodeType == xml.dom.Node.TEXT_NODE:
+ return XmlText(node.nodeValue)
+ else:
+ return None
+
+ def convert_element(element):
+ converted_name = convert_name(element)
+
+ converted_attributes = dict(
+ (convert_name(attribute), attribute.value)
+ for attribute in element.attributes.values()
+ if attribute.namespaceURI != "http://www.w3.org/2000/xmlns/"
+ )
+
+ converted_children = []
+ for child_node in element.childNodes:
+ converted_child_node = convert_node(child_node)
+ if converted_child_node is not None:
+ converted_children.append(converted_child_node)
+
+ return XmlElement(converted_name, converted_attributes, converted_children)
+
+ def convert_name(node):
+ if node.namespaceURI is None:
+ return node.localName
+ else:
+ prefix = namespace_prefixes.get(node.namespaceURI)
+ if prefix is None:
+ return "{%s}%s" % (node.namespaceURI, node.localName)
+ else:
+ return "%s:%s" % (prefix, node.localName)
+
+ return convert_node(document.documentElement)
+
+
+def parse_xml_str(xml_str, namespace_mapping=None):
+ if namespace_mapping is None:
+ namespace_prefixes = {}
+ else:
+ namespace_prefixes = dict((uri, prefix) for prefix, uri in namespace_mapping)
+
+ document = xml.dom.minidom.parseString(xml_str)
+
+ def convert_node(node):
+ if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+ return convert_element(node)
+ elif node.nodeType == xml.dom.Node.TEXT_NODE:
+ return XmlText(node.nodeValue)
+ else:
+ return None
+
+ def convert_element(element):
+ converted_name = convert_name(element)
+
+ converted_attributes = dict(
+ (convert_name(attribute), attribute.value)
+ for attribute in element.attributes.values()
+ if attribute.namespaceURI != "http://www.w3.org/2000/xmlns/"
+ )
+
+ converted_children = []
+ for child_node in element.childNodes:
+ converted_child_node = convert_node(child_node)
+ if converted_child_node is not None:
+ converted_children.append(converted_child_node)
+
+ return XmlElement(converted_name, converted_attributes, converted_children)
+
+ def convert_name(node):
+ if node.namespaceURI is None:
+ return node.localName
+ else:
+ prefix = namespace_prefixes.get(node.namespaceURI)
+ if prefix is None:
+ return "{%s}%s" % (node.namespaceURI, node.localName)
+ else:
+ return "%s:%s" % (prefix, node.localName)
+
+ return convert_node(document.documentElement)