docmarq 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.
- docmarq/__init__.py +54 -0
- docmarq/constants.py +77 -0
- docmarq/core.py +936 -0
- docmarq/fonts.py +19 -0
- docmarq/inline.py +98 -0
- docmarq/layout.py +42 -0
- docmarq/md/__init__.py +33 -0
- docmarq/md/image_utils.py +241 -0
- docmarq/md/mermaid.py +140 -0
- docmarq/md/presets.py +119 -0
- docmarq/md/render.py +219 -0
- docmarq/md/renderer.py +1210 -0
- docmarq/md/slug.py +59 -0
- docmarq/md/style.py +124 -0
- docmarq/md/tokens.py +69 -0
- docmarq/structure.py +36 -0
- docmarq/styles.py +111 -0
- docmarq/tables.py +135 -0
- docmarq/tests/__init__.py +0 -0
- docmarq/tests/conftest.py +25 -0
- docmarq/tests/test_md_smoke.py +87 -0
- docmarq/tests/test_smoke.py +82 -0
- docmarq/tests/test_units.py +116 -0
- docmarq/utils.py +174 -0
- docmarq-0.1.0.dist-info/METADATA +104 -0
- docmarq-0.1.0.dist-info/RECORD +28 -0
- docmarq-0.1.0.dist-info/WHEEL +5 -0
- docmarq-0.1.0.dist-info/top_level.txt +1 -0
docmarq/__init__.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# docmarq/__init__.py
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
DOCX generation with fluent API. Built on `python-docx`.
|
|
5
|
+
|
|
6
|
+
Mirror of `pdfmarq` philosophy: thin fluent layer over a heavy backend.
|
|
7
|
+
We use `python-docx` for OOXML zip plumbing, content types, and
|
|
8
|
+
relationships - everything user-facing is our own API.
|
|
9
|
+
|
|
10
|
+
Example:
|
|
11
|
+
>>> from docmarq import DOCX, Align
|
|
12
|
+
>>> with DOCX("out.docx") as doc:
|
|
13
|
+
... doc.heading("Tytuł", level=1)
|
|
14
|
+
... doc.para("Pierwszy akapit.")
|
|
15
|
+
... doc.text("Drugi z ").text("bold", bold=True).text(" tekstem.")
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
#----------------------------------------------------------------------- Metadata for auto-toml
|
|
19
|
+
|
|
20
|
+
__version__ = "0.1.0"
|
|
21
|
+
__repo__ = "Xaeian/docmarq"
|
|
22
|
+
__python__ = ">=3.10"
|
|
23
|
+
__description__ = "DOCX generation library with fluent API"
|
|
24
|
+
__author__ = "Xaeian"
|
|
25
|
+
__keywords__ = ["docx", "word", "ooxml", "document", "generation"]
|
|
26
|
+
__dependencies__ = ["python-docx"]
|
|
27
|
+
# pip-name → import-name mapping. `python-docx` is the pip package but
|
|
28
|
+
# the import is `import docx`; the hint surfaces in dependency diagnostics
|
|
29
|
+
# so users debugging `No module named 'docx'` see the right install command.
|
|
30
|
+
__import_names__ = {"python-docx": "docx"}
|
|
31
|
+
|
|
32
|
+
#----------------------------------------------------------------------------------- Public API
|
|
33
|
+
|
|
34
|
+
from .constants import (
|
|
35
|
+
Unit, PageSize, Align, Colors, Defaults,
|
|
36
|
+
A4, A3, A5, LETTER, LEGAL, EMU_PER_MM, EMU_PER_PT,
|
|
37
|
+
)
|
|
38
|
+
from .styles import Style, TableStyle, Styles
|
|
39
|
+
from .layout import PageGeometry
|
|
40
|
+
from .structure import Metadata, Bookmark
|
|
41
|
+
from .utils import to_mm, mm_to_emu, pt_to_emu, parse_color, parse_margin, color_hex, rgb255
|
|
42
|
+
from .inline import RichSegment
|
|
43
|
+
from .core import DOCX
|
|
44
|
+
|
|
45
|
+
__all__ = [
|
|
46
|
+
"DOCX",
|
|
47
|
+
"Unit", "PageSize", "Align", "Colors", "Defaults",
|
|
48
|
+
"A4", "A3", "A5", "LETTER", "LEGAL", "EMU_PER_MM", "EMU_PER_PT",
|
|
49
|
+
"Style", "TableStyle", "Styles",
|
|
50
|
+
"PageGeometry",
|
|
51
|
+
"Metadata", "Bookmark",
|
|
52
|
+
"to_mm", "mm_to_emu", "pt_to_emu", "parse_color", "parse_margin", "color_hex", "rgb255",
|
|
53
|
+
"RichSegment",
|
|
54
|
+
]
|
docmarq/constants.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# docmarq/constants.py
|
|
2
|
+
|
|
3
|
+
"""Constants for DOCX library - units, page sizes, alignment, defaults."""
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
|
|
6
|
+
# OOXML uses EMU (English Metric Units): 1 inch = 914400 EMU = 25.4 mm
|
|
7
|
+
EMU_PER_MM = 36000
|
|
8
|
+
EMU_PER_PT = 12700 # 1 pt = 1/72 inch
|
|
9
|
+
|
|
10
|
+
#---------------------------------------------------------------------------------------- Units
|
|
11
|
+
|
|
12
|
+
class Unit:
|
|
13
|
+
"""Unit conversion factors to millimeters."""
|
|
14
|
+
MM = 1.0
|
|
15
|
+
CM = 10.0
|
|
16
|
+
INCH = 25.4
|
|
17
|
+
PT = 25.4 / 72
|
|
18
|
+
PX = 25.4 / 96
|
|
19
|
+
|
|
20
|
+
#------------------------------------------------------------------------------------- PageSize
|
|
21
|
+
|
|
22
|
+
@dataclass
|
|
23
|
+
class PageSize:
|
|
24
|
+
"""Common page sizes in mm."""
|
|
25
|
+
width: float
|
|
26
|
+
height: float
|
|
27
|
+
def landscape(self) -> "PageSize":
|
|
28
|
+
"""Return a copy with width/height swapped (landscape orientation)."""
|
|
29
|
+
return PageSize(self.height, self.width)
|
|
30
|
+
|
|
31
|
+
A4 = PageSize(210, 297)
|
|
32
|
+
A3 = PageSize(297, 420)
|
|
33
|
+
A5 = PageSize(148, 210)
|
|
34
|
+
LETTER = PageSize(215.9, 279.4)
|
|
35
|
+
LEGAL = PageSize(215.9, 355.6)
|
|
36
|
+
|
|
37
|
+
#---------------------------------------------------------------------------------------- Align
|
|
38
|
+
|
|
39
|
+
class Align:
|
|
40
|
+
"""Text/element alignment constants. Match pdfmarq values for cross-lib reuse."""
|
|
41
|
+
LEFT = "L"
|
|
42
|
+
RIGHT = "R"
|
|
43
|
+
CENTER = "C"
|
|
44
|
+
JUSTIFY = "J"
|
|
45
|
+
|
|
46
|
+
#--------------------------------------------------------------------------------------- Colors
|
|
47
|
+
|
|
48
|
+
class Colors:
|
|
49
|
+
"""Predefined colors as (r, g, b) tuples (0-1 range)."""
|
|
50
|
+
BLACK = (0, 0, 0)
|
|
51
|
+
WHITE = (1, 1, 1)
|
|
52
|
+
RED = (1, 0, 0)
|
|
53
|
+
GREEN = (0, 1, 0)
|
|
54
|
+
BLUE = (0, 0, 1)
|
|
55
|
+
GREY = (0.5, 0.5, 0.5)
|
|
56
|
+
LIGHT_GREY = (0.8, 0.8, 0.8)
|
|
57
|
+
DARK_GREY = (0.3, 0.3, 0.3)
|
|
58
|
+
|
|
59
|
+
#------------------------------------------------------------------------------------- Defaults
|
|
60
|
+
|
|
61
|
+
class Defaults:
|
|
62
|
+
"""Default values for DOCX generation."""
|
|
63
|
+
PAGE_WIDTH = 210
|
|
64
|
+
PAGE_HEIGHT = 297
|
|
65
|
+
MARGIN = 20
|
|
66
|
+
FONT_FAMILY = "Calibri"
|
|
67
|
+
FONT_SIZE = 11
|
|
68
|
+
FONT_MODE = "Regular"
|
|
69
|
+
LINE_HEIGHT = 1.15
|
|
70
|
+
UNIT = "mm"
|
|
71
|
+
# Heading palette - GitHub-light, mirrors `pdfmarq.MarkdownStyle`
|
|
72
|
+
HEAD_COLOR = (0.09, 0.11, 0.13) # near-black #1f2328
|
|
73
|
+
RULE_COLOR = (0.82, 0.84, 0.87) # light grey #d0d7de (h1/h2 underline)
|
|
74
|
+
# h1..h6 sizes in pt. Matches `pdfmarq.MarkdownStyle.h{1-6}_size` so
|
|
75
|
+
# the same markdown source renders at the same scale in both libs.
|
|
76
|
+
HEAD_SIZES = (20, 16, 13, 11, 11, 11)
|
|
77
|
+
HEAD_UNDERLINE_LEVELS = (1, 2) # which heading levels get bottom border
|