Skip to content

Commit 2450458

Browse files
committed
v1.0.0
1 parent b8eb976 commit 2450458

19 files changed

+1814
-3
lines changed

.github/workflows/tests.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: Tests
5+
6+
on:
7+
push:
8+
branches: [ master ]
9+
pull_request:
10+
branches: [ master ]
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
matrix:
18+
os: [ubuntu-latest, macos-latest, windows-latest]
19+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
- name: Set up Python ${{ matrix.python-version }}
24+
uses: actions/setup-python@v4
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
cache: 'pip'
28+
- name: Install dependencies
29+
run: |
30+
python -m pip install --upgrade pip
31+
pip install flake8
32+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
33+
- name: Lint with flake8
34+
run: |
35+
# stop the build if there are Python syntax errors or undefined names
36+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
37+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
38+
flake8 . --count --exit-zero --statistics
39+
- name: Run tests
40+
run: |
41+
python -m tests.test
42+
python -m tests.test_tables
43+
python -m tests.test_code
44+
python -m doctest -v html4docx/h4d.py
45+
- name: Upload test artifacts
46+
uses: actions/[email protected]
47+
with:
48+
name: test_outputs
49+
path: |
50+
tests/test.docx
51+
tests/new_docx_file_tables2.html.docx
52+
tests/new_docx_file_code.html.docx

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ coverage.xml
5050
.hypothesis/
5151
.pytest_cache/
5252
cover/
53+
tests/**/*.docx
5354

5455
# Translations
5556
*.mo
@@ -85,7 +86,7 @@ ipython_config.py
8586
# pyenv
8687
# For a library or package, you might want to ignore these files since the code is
8788
# intended to run in multiple environments; otherwise, check them in:
88-
# .python-version
89+
.python-version
8990

9091
# pipenv
9192
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
@@ -152,6 +153,9 @@ dmypy.json
152153
# Cython debug symbols
153154
cython_debug/
154155

156+
# Mac OS
157+
.DS_Store
158+
155159
# PyCharm
156160
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157161
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore

README.md

+36-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,36 @@
1-
# html2docx
2-
Convert html to docx
1+
# HTML FOR DOCX
2+
Convert html to docx, this project is a fork from descontinued [pqzx/html2docx](https://github.com/pqzx/html2docx).
3+
4+
### To install
5+
6+
`pip install html-for-docx`
7+
8+
### Usage
9+
10+
Take a look on [pqzx/html2docx](https://github.com/pqzx/html2docx) project to see examples of usage.
11+
12+
### Why
13+
14+
My goal to fork and fix/update this package was to complete my current task at work that envolves manipulating a html to docs which the original couldn't complete because was lacking of few features and bugs, so instead creating a package from zero, I prefer update this one.
15+
16+
### Differences (fixes and new features)
17+
18+
**Fixes**
19+
- Handle missing run for leading br tag | [dashingdove](https://github.com/dashingdove) from [PR](https://github.com/pqzx/html2docx/pull/53)
20+
- Fix base64 images | [djplaner](https://github.com/djplaner) from [Issue](https://github.com/pqzx/html2docx/issues/28#issuecomment-1052736896)
21+
- Handle img tag without src attribute | [johnjor](https://github.com/johnjor) from [PR](https://github.com/pqzx/html2docx/pull/63)
22+
- Fix text-align bug when `!important` | [Dfop02](https://github.com/dfop02)
23+
- Fix background-color always set default color | [Dfop02](https://github.com/dfop02)
24+
- Fix 'style lookup by style_id is deprecated.' | [Dfop02](https://github.com/dfop02)
25+
26+
**New Features**
27+
- Add Witdh/Height style to images | [maifeeulasad](https://github.com/maifeeulasad) from [PR](https://github.com/pqzx/html2docx/pull/29)
28+
- Support px, cm and % for style margin-left to paragraphs | [Dfop02](https://github.com/dfop02)
29+
- Improve performance on large tables | [dashingdove](https://github.com/dashingdove) from [PR](https://github.com/pqzx/html2docx/pull/58)
30+
- Support for HTML Pagination | [Evilran](https://github.com/Evilran) from [PR](https://github.com/pqzx/html2docx/pull/39)
31+
- Support Table style | [Evilran](https://github.com/Evilran) from [PR](https://github.com/pqzx/html2docx/pull/39)
32+
- Support alternative encoding | [HebaElwazzan](https://github.com/HebaElwazzan) from [PR](https://github.com/pqzx/html2docx/pull/59)
33+
34+
## License
35+
36+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details

html4docx/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .h4d import HtmlToDocx

html4docx/colors.py

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
import enum
2+
3+
# Reference colors from W3
4+
# https://www.w3.org/wiki/CSS/Properties/color/keywords
5+
class Color(enum.Enum):
6+
aliceblue = [240, 248, 255]
7+
antiquewhite = [250, 235, 215]
8+
aqua = [0, 255, 255]
9+
aquamarine = [127, 255, 212]
10+
azure = [240, 255, 255]
11+
beige = [245, 245, 220]
12+
bisque = [255, 228, 196]
13+
black = [0, 0, 0]
14+
blanchedalmond = [255, 235, 205]
15+
blue = [0, 0, 255]
16+
blueviolet = [138, 43, 226]
17+
brown = [165, 42, 42]
18+
burlywood = [222, 184, 135]
19+
cadetblue = [95, 158, 160]
20+
chartreuse = [127, 255, 0]
21+
chocolate = [210, 105, 30]
22+
coral = [255, 127, 80]
23+
cornflowerblue = [100, 149, 237]
24+
cornsilk = [255, 248, 220]
25+
crimson = [220, 20, 60]
26+
cyan = [0, 255, 255]
27+
darkblue = [0, 0, 139]
28+
darkcyan = [0, 139, 139]
29+
darkgoldenrod = [184, 134, 11]
30+
darkgray = [169, 169, 169]
31+
darkgreen = [0, 100, 0]
32+
darkgrey = [169, 169, 169]
33+
darkkhaki = [189, 183, 107]
34+
darkmagenta = [139, 0, 139]
35+
darkolivegreen = [85, 107, 47]
36+
darkorange = [255, 140, 0]
37+
darkorchid = [153, 50, 204]
38+
darkred = [139, 0, 0]
39+
darksalmon = [233, 150, 122]
40+
darkseagreen = [143, 188, 143]
41+
darkslateblue = [72, 61, 139]
42+
darkslategray = [47, 79, 79]
43+
darkslategrey = [47, 79, 79]
44+
darkturquoise = [0, 206, 209]
45+
darkviolet = [148, 0, 211]
46+
deeppink = [255, 20, 147]
47+
deepskyblue = [0, 191, 255]
48+
dimgray = [105, 105, 105]
49+
dimgrey = [105, 105, 105]
50+
dodgerblue = [30, 144, 255]
51+
firebrick = [178, 34, 34]
52+
floralwhite = [255, 250, 240]
53+
forestgreen = [34, 139, 34]
54+
fuchsia = [255, 0, 255]
55+
gainsboro = [220, 220, 220]
56+
ghostwhite = [248, 248, 255]
57+
gold = [255, 215, 0]
58+
goldenrod = [218, 165, 32]
59+
gray = [128, 128, 128]
60+
green = [0, 128, 0]
61+
greenyellow = [173, 255, 47]
62+
grey = [128, 128, 128]
63+
honeydew = [240, 255, 240]
64+
hotpink = [255, 105, 180]
65+
indianred = [205, 92, 92]
66+
indigo = [75, 0, 130]
67+
ivory = [255, 255, 240]
68+
khaki = [240, 230, 140]
69+
lavender = [230, 230, 250]
70+
lavenderblush = [255, 240, 245]
71+
lawngreen = [124, 252, 0]
72+
lemonchiffon = [255, 250, 205]
73+
lightblue = [173, 216, 230]
74+
lightcoral = [240, 128, 128]
75+
lightcyan = [224, 255, 255]
76+
lightgoldenrodyellow = [250, 250, 210]
77+
lightgray = [211, 211, 211]
78+
lightgreen = [144, 238, 144]
79+
lightgrey = [211, 211, 211]
80+
lightpink = [255, 182, 193]
81+
lightsalmon = [255, 160, 122]
82+
lightseagreen = [32, 178, 170]
83+
lightskyblue = [135, 206, 250]
84+
lightslategray = [119, 136, 153]
85+
lightslategrey = [119, 136, 153]
86+
lightsteelblue = [176, 196, 222]
87+
lightyellow = [255, 255, 224]
88+
lime = [0, 255, 0]
89+
limegreen = [50, 205, 50]
90+
linen = [250, 240, 230]
91+
magenta = [255, 0, 255]
92+
maroon = [128, 0, 0]
93+
mediumaquamarine = [102, 205, 170]
94+
mediumblue = [0, 0, 205]
95+
mediumorchid = [186, 85, 211]
96+
mediumpurple = [147, 112, 219]
97+
mediumseagreen = [60, 179, 113]
98+
mediumslateblue = [123, 104, 238]
99+
mediumspringgreen = [0, 250, 154]
100+
mediumturquoise = [72, 209, 204]
101+
mediumvioletred = [199, 21, 133]
102+
midnightblue = [25, 25, 112]
103+
mintcream = [245, 255, 250]
104+
mistyrose = [255, 228, 225]
105+
moccasin = [255, 228, 181]
106+
navajowhite = [255, 222, 173]
107+
navy = [0, 0, 128]
108+
oldlace = [253, 245, 230]
109+
olive = [128, 128, 0]
110+
olivedrab = [107, 142, 35]
111+
orange = [255, 165, 0]
112+
orangered = [255, 69, 0]
113+
orchid = [218, 112, 214]
114+
palegoldenrod = [238, 232, 170]
115+
palegreen = [152, 251, 152]
116+
paleturquoise = [175, 238, 238]
117+
palevioletred = [219, 112, 147]
118+
papayawhip = [255, 239, 213]
119+
peachpuff = [255, 218, 185]
120+
peru = [205, 133, 63]
121+
pink = [255, 192, 203]
122+
plum = [221, 160, 221]
123+
powderblue = [176, 224, 230]
124+
purple = [128, 0, 128]
125+
red = [255, 0, 0]
126+
rosybrown = [188, 143, 143]
127+
royalblue = [65, 105, 225]
128+
saddlebrown = [139, 69, 19]
129+
salmon = [250, 128, 114]
130+
sandybrown = [244, 164, 96]
131+
seagreen = [46, 139, 87]
132+
seashell = [255, 245, 238]
133+
sienna = [160, 82, 45]
134+
silver = [192, 192, 192]
135+
skyblue = [135, 206, 235]
136+
slateblue = [106, 90, 205]
137+
slategray = [112, 128, 144]
138+
slategrey = [112, 128, 144]
139+
snow = [255, 250, 250]
140+
springgreen = [0, 255, 127]
141+
steelblue = [70, 130, 180]
142+
tan = [210, 180, 140]
143+
teal = [0, 128, 128]
144+
thistle = [216, 191, 216]
145+
tomato = [255, 99, 71]
146+
turquoise = [64, 224, 208]
147+
violet = [238, 130, 238]
148+
wheat = [245, 222, 179]
149+
white = [255, 255, 255]
150+
whitesmoke = [245, 245, 245]
151+
yellow = [255, 255, 0]
152+
yellowgreen = [154, 205, 50]

0 commit comments

Comments
 (0)