docs-html-konwerter 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ from .doc_konwerter import parsehtml
2
+
3
+ __all__ = [
4
+ "parsehtml",
5
+ ]
@@ -0,0 +1,85 @@
1
+ import shutil
2
+ import os
3
+ import subprocess
4
+ from tempfile import NamedTemporaryFile
5
+
6
+ import xml.etree.ElementTree as et
7
+
8
+ from xml_konwerter import konwertujdok
9
+
10
+ _LINIE = ""
11
+ _LINIE1 = "1"
12
+ _LINIE2 = "2"
13
+ _LINIE3 = "3"
14
+ _LINIE4 = "4"
15
+ _LINIETPOD = "TPOD"
16
+ _LINIETNAD = "TNAD"
17
+
18
+ _LISTA = "linie"
19
+ _LISTA1 = "linie1"
20
+ _LISTA2 = "linie2"
21
+ _LISTA3 = "linie3"
22
+ _LISTA4 = "linie4"
23
+ _LISTATPOD = "linietpod"
24
+ _LISTATNAD = "linietnad"
25
+
26
+ _LI_CH = ["nbsp", "oacute", "hellip", "Oacute"]
27
+
28
+ _htmlkeypairing = [
29
+ (_LINIE, _LISTA),
30
+ (_LINIE1, _LISTA1),
31
+ (_LINIE2, _LISTA2),
32
+ (_LINIE3, _LISTA3),
33
+ (_LINIE4, _LISTA4),
34
+ (_LINIETPOD, _LISTATPOD),
35
+ (_LINIETNAD, _LISTATNAD)
36
+ ]
37
+
38
+
39
+ def _replace_ch(tname, ch):
40
+ command = ["sed", "-i", "-e", f's/\&{ch};/{ch};/g', tname]
41
+ subprocess.call(command)
42
+
43
+
44
+ def _replace_ch_back(tname, ch):
45
+ command = ["sed", "-i", "-e", f's/{ch};/\&{ch};/g', tname]
46
+ subprocess.call(command)
47
+
48
+
49
+ def _replace_tag(tname, tag):
50
+ pars = f's/<{tag}\([^>]*\)>/<{tag}\\1\\/>/g'
51
+ command = ["sed", "-i", "-e", pars, tname]
52
+ subprocess.call(command)
53
+
54
+
55
+ def _replace_page_break(tname):
56
+ before = "page-break-before:always;display:none;"
57
+ after = "page-break-before:always;"
58
+ pars = f's/{before}/{after}/g'
59
+ command = ["sed", "-i", "-e", pars, tname]
60
+ subprocess.call(command)
61
+
62
+
63
+ def _remove_meta(htmltemplate, tname):
64
+ shutil.copyfile(htmltemplate, tname)
65
+ _replace_tag(tname, "meta")
66
+ _replace_tag(tname, "img")
67
+ _replace_tag(tname, "hr")
68
+ _replace_page_break(tname)
69
+ for ch in _LI_CH:
70
+ _replace_ch(tname, ch)
71
+
72
+
73
+ def _restore_nbsp(output):
74
+ for ch in _LI_CH:
75
+ _replace_ch_back(output, ch)
76
+
77
+
78
+ def parsehtml(htmltemplate: str, outputdir: str, outputhtml: str, d: dict):
79
+ with NamedTemporaryFile() as tfile:
80
+ tname = tfile.name
81
+ _remove_meta(htmltemplate, tname)
82
+ htmloutputfile = os.path.join(outputdir, outputhtml)
83
+ konwertujdok(tname, htmloutputfile, d,
84
+ htmlkeypairing=_htmlkeypairing)
85
+ _restore_nbsp(htmloutputfile)
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.4
2
+ Name: docs-html-konwerter
3
+ Version: 0.1.0
4
+ Project-URL: Repository, https://github.com/stanislawbartkowski/docs-html-konwerter
5
+ Requires-Python: >=3.10
6
+ Requires-Dist: xml-konwerter
@@ -0,0 +1,6 @@
1
+ docs_html_konwerter/__init__.py,sha256=C9KTbmcL_e2Io7Jc4gtBPbCjVznYBhXONlTyI2XvPpk,69
2
+ docs_html_konwerter/doc_konwerter.py,sha256=V9bUKz3PoRlT3Q3GB1oFU-F1G4GFJvODhPLTHJ25iMs,2034
3
+ docs_html_konwerter-0.1.0.dist-info/METADATA,sha256=y7cGxPPm8v1-XYQMsYnL0XwIZ-tnv42Zp9dq3PrXIe8,200
4
+ docs_html_konwerter-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
5
+ docs_html_konwerter-0.1.0.dist-info/top_level.txt,sha256=JyC1eI2-iufyS0FluDADYXlOz-ElWU8NJOWbhG-2o08,20
6
+ docs_html_konwerter-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ docs_html_konwerter