marklas 0.8.2__tar.gz → 0.8.4__tar.gz
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.
- {marklas-0.8.2 → marklas-0.8.4}/PKG-INFO +1 -1
- {marklas-0.8.2 → marklas-0.8.4}/pyproject.toml +1 -1
- {marklas-0.8.2 → marklas-0.8.4}/src/marklas/adf/parser.py +6 -4
- {marklas-0.8.2 → marklas-0.8.4}/src/marklas/adf/renderer.py +12 -0
- {marklas-0.8.2 → marklas-0.8.4}/src/marklas/ast.py +42 -1
- {marklas-0.8.2 → marklas-0.8.4}/src/marklas/md/parser/block.py +6 -0
- {marklas-0.8.2 → marklas-0.8.4}/src/marklas/md/parser/cell.py +7 -1
- {marklas-0.8.2 → marklas-0.8.4}/src/marklas/md/parser/inline.py +17 -1
- {marklas-0.8.2 → marklas-0.8.4}/src/marklas/md/parser/normalize.py +7 -0
- {marklas-0.8.2 → marklas-0.8.4}/src/marklas/md/renderer/block.py +28 -0
- {marklas-0.8.2 → marklas-0.8.4}/README.md +0 -0
- {marklas-0.8.2 → marklas-0.8.4}/src/marklas/__init__.py +0 -0
- {marklas-0.8.2 → marklas-0.8.4}/src/marklas/adf/__init__.py +0 -0
- {marklas-0.8.2 → marklas-0.8.4}/src/marklas/convert.py +0 -0
- {marklas-0.8.2 → marklas-0.8.4}/src/marklas/md/__init__.py +0 -0
- {marklas-0.8.2 → marklas-0.8.4}/src/marklas/md/parser/__init__.py +0 -0
- {marklas-0.8.2 → marklas-0.8.4}/src/marklas/md/parser/ir.py +0 -0
- {marklas-0.8.2 → marklas-0.8.4}/src/marklas/md/renderer/__init__.py +0 -0
- {marklas-0.8.2 → marklas-0.8.4}/src/marklas/md/renderer/cell.py +0 -0
- {marklas-0.8.2 → marklas-0.8.4}/src/marklas/py.typed +0 -0
- {marklas-0.8.2 → marklas-0.8.4}/src/marklas/transform.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: marklas
|
|
3
|
-
Version: 0.8.
|
|
3
|
+
Version: 0.8.4
|
|
4
4
|
Summary: Bidirectional converter between GitHub Flavored Markdown and Atlassian Document Format
|
|
5
5
|
Keywords: markdown,adf,atlassian,jira,confluence,converter,atlassian-document-format
|
|
6
6
|
Author: byExist
|
|
@@ -4,6 +4,7 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import re
|
|
6
6
|
from collections.abc import Sequence
|
|
7
|
+
from copy import deepcopy
|
|
7
8
|
from typing import Any, cast
|
|
8
9
|
|
|
9
10
|
from marklas import ast
|
|
@@ -71,11 +72,12 @@ def _parse_mark(mark: dict[str, Any]) -> ast.Mark | None:
|
|
|
71
72
|
return ast.BorderMark(
|
|
72
73
|
size=attrs.get("size", 1), color=attrs.get("color", "")
|
|
73
74
|
)
|
|
75
|
+
case "fontSize":
|
|
76
|
+
return ast.FontSizeMark(size=attrs.get("fontSize", ""))
|
|
74
77
|
case "fragment":
|
|
75
78
|
return None # lossy: editor runtime metadata
|
|
76
79
|
case _:
|
|
77
|
-
|
|
78
|
-
raise ValueError(msg)
|
|
80
|
+
return ast.UnknownMark(type=mark.get("type", ""), attrs=mark.get("attrs"))
|
|
79
81
|
|
|
80
82
|
|
|
81
83
|
def _parse_marks(marks: list[dict[str, Any]]) -> list[ast.Mark]:
|
|
@@ -139,7 +141,7 @@ def _parse_block(node: dict[str, Any]) -> ast.Node | None:
|
|
|
139
141
|
case "bodiedSyncBlock":
|
|
140
142
|
return _parse_bodied_sync_block(node)
|
|
141
143
|
case _:
|
|
142
|
-
return
|
|
144
|
+
return ast.UnknownBlock(raw=deepcopy(node))
|
|
143
145
|
|
|
144
146
|
|
|
145
147
|
# ── Block parsers ────────────────────────────────────────────────────────────
|
|
@@ -609,7 +611,7 @@ def _parse_inline(node: dict[str, Any]) -> ast.Inline | None:
|
|
|
609
611
|
case "inlineExtension":
|
|
610
612
|
return _parse_inline_extension(node)
|
|
611
613
|
case _:
|
|
612
|
-
return
|
|
614
|
+
return ast.UnknownInline(raw=deepcopy(node))
|
|
613
615
|
|
|
614
616
|
|
|
615
617
|
# ── Inline parsers ───────────────────────────────────────────────────────────
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
from collections.abc import Sequence
|
|
6
|
+
from copy import deepcopy
|
|
6
7
|
from typing import Any
|
|
7
8
|
from uuid import uuid4
|
|
8
9
|
|
|
@@ -108,6 +109,13 @@ def _render_mark(mark: ast.Mark) -> dict[str, Any]:
|
|
|
108
109
|
return {"type": "dataConsumer", "attrs": {"sources": mark.sources}}
|
|
109
110
|
case ast.BorderMark():
|
|
110
111
|
return {"type": "border", "attrs": {"size": mark.size, "color": mark.color}}
|
|
112
|
+
case ast.FontSizeMark():
|
|
113
|
+
return {"type": "fontSize", "attrs": {"fontSize": mark.size}}
|
|
114
|
+
case ast.UnknownMark():
|
|
115
|
+
result: dict[str, Any] = {"type": mark.type}
|
|
116
|
+
if mark.attrs is not None:
|
|
117
|
+
result["attrs"] = mark.attrs
|
|
118
|
+
return result
|
|
111
119
|
case _:
|
|
112
120
|
msg = f"Unknown mark type: {type(mark)}"
|
|
113
121
|
raise ValueError(msg)
|
|
@@ -167,6 +175,8 @@ def render_block(node: ast.Node) -> dict[str, Any] | None:
|
|
|
167
175
|
return _render_sync_block(node)
|
|
168
176
|
case ast.BodiedSyncBlock():
|
|
169
177
|
return _render_bodied_sync_block(node)
|
|
178
|
+
case ast.UnknownBlock():
|
|
179
|
+
return deepcopy(node.raw)
|
|
170
180
|
case _:
|
|
171
181
|
msg = f"Unknown block node: {type(node)}"
|
|
172
182
|
raise ValueError(msg)
|
|
@@ -563,6 +573,8 @@ def _render_inline(node: ast.Inline) -> dict[str, Any]:
|
|
|
563
573
|
return _render_media_inline(node)
|
|
564
574
|
case ast.InlineExtension():
|
|
565
575
|
return _render_inline_extension(node)
|
|
576
|
+
case ast.UnknownInline():
|
|
577
|
+
return deepcopy(node.raw)
|
|
566
578
|
case _:
|
|
567
579
|
msg = f"Unknown inline node: {type(node)}"
|
|
568
580
|
raise ValueError(msg)
|
|
@@ -64,6 +64,11 @@ class EmMark(Mark):
|
|
|
64
64
|
pass
|
|
65
65
|
|
|
66
66
|
|
|
67
|
+
@dataclass
|
|
68
|
+
class FontSizeMark(Mark):
|
|
69
|
+
size: str
|
|
70
|
+
|
|
71
|
+
|
|
67
72
|
# @dataclass
|
|
68
73
|
# class FragmentMark(Mark):
|
|
69
74
|
# name: str | None = None
|
|
@@ -108,6 +113,12 @@ class UnderlineMark(Mark):
|
|
|
108
113
|
pass
|
|
109
114
|
|
|
110
115
|
|
|
116
|
+
@dataclass
|
|
117
|
+
class UnknownMark(Mark):
|
|
118
|
+
type: str
|
|
119
|
+
attrs: dict[str, Any] | None = None
|
|
120
|
+
|
|
121
|
+
|
|
111
122
|
# ── Inline Nodes ──────────────────────────────────────────────────────────────
|
|
112
123
|
|
|
113
124
|
|
|
@@ -184,6 +195,15 @@ class InlineExtension(Node):
|
|
|
184
195
|
marks: Sequence[Mark] = field(default_factory=list[Mark])
|
|
185
196
|
|
|
186
197
|
|
|
198
|
+
@dataclass
|
|
199
|
+
class UnknownInline(Node):
|
|
200
|
+
raw: dict[str, Any]
|
|
201
|
+
|
|
202
|
+
@property
|
|
203
|
+
def type(self) -> str:
|
|
204
|
+
return self.raw.get("type", "")
|
|
205
|
+
|
|
206
|
+
|
|
187
207
|
# ── Inline Type Aliases ───────────────────────────────────────────────────────
|
|
188
208
|
|
|
189
209
|
Inline: TypeAlias = Union[
|
|
@@ -197,6 +217,7 @@ Inline: TypeAlias = Union[
|
|
|
197
217
|
Placeholder,
|
|
198
218
|
MediaInline,
|
|
199
219
|
InlineExtension,
|
|
220
|
+
UnknownInline,
|
|
200
221
|
]
|
|
201
222
|
|
|
202
223
|
CaptionContent: TypeAlias = Union[
|
|
@@ -208,6 +229,7 @@ CaptionContent: TypeAlias = Union[
|
|
|
208
229
|
Status,
|
|
209
230
|
InlineCard,
|
|
210
231
|
Placeholder,
|
|
232
|
+
UnknownInline,
|
|
211
233
|
]
|
|
212
234
|
|
|
213
235
|
|
|
@@ -511,6 +533,15 @@ class BodiedSyncBlock(Node):
|
|
|
511
533
|
marks: Sequence[BreakoutMark] = field(default_factory=list[BreakoutMark])
|
|
512
534
|
|
|
513
535
|
|
|
536
|
+
@dataclass
|
|
537
|
+
class UnknownBlock(Node):
|
|
538
|
+
raw: dict[str, Any]
|
|
539
|
+
|
|
540
|
+
@property
|
|
541
|
+
def type(self) -> str:
|
|
542
|
+
return self.raw.get("type", "")
|
|
543
|
+
|
|
544
|
+
|
|
514
545
|
@dataclass
|
|
515
546
|
class Doc(Node):
|
|
516
547
|
content: Sequence[DocContent]
|
|
@@ -527,6 +558,7 @@ BlockquoteContent: TypeAlias = Union[
|
|
|
527
558
|
MediaSingle,
|
|
528
559
|
MediaGroup,
|
|
529
560
|
Extension,
|
|
561
|
+
UnknownBlock,
|
|
530
562
|
]
|
|
531
563
|
|
|
532
564
|
ListItemContent: TypeAlias = Union[
|
|
@@ -537,6 +569,7 @@ ListItemContent: TypeAlias = Union[
|
|
|
537
569
|
MediaSingle,
|
|
538
570
|
CodeBlock,
|
|
539
571
|
Extension,
|
|
572
|
+
UnknownBlock,
|
|
540
573
|
]
|
|
541
574
|
|
|
542
575
|
PanelContent: TypeAlias = Union[
|
|
@@ -552,6 +585,7 @@ PanelContent: TypeAlias = Union[
|
|
|
552
585
|
Rule,
|
|
553
586
|
DecisionList,
|
|
554
587
|
Extension,
|
|
588
|
+
UnknownBlock,
|
|
555
589
|
]
|
|
556
590
|
|
|
557
591
|
TableCellContent: TypeAlias = Union[
|
|
@@ -571,6 +605,7 @@ TableCellContent: TypeAlias = Union[
|
|
|
571
605
|
EmbedCard,
|
|
572
606
|
Extension,
|
|
573
607
|
NestedExpand,
|
|
608
|
+
UnknownBlock,
|
|
574
609
|
]
|
|
575
610
|
|
|
576
611
|
NestedExpandContent: TypeAlias = Union[
|
|
@@ -587,6 +622,7 @@ NestedExpandContent: TypeAlias = Union[
|
|
|
587
622
|
Panel,
|
|
588
623
|
Blockquote,
|
|
589
624
|
Extension,
|
|
625
|
+
UnknownBlock,
|
|
590
626
|
]
|
|
591
627
|
|
|
592
628
|
ExpandContent: TypeAlias = Union[
|
|
@@ -607,9 +643,10 @@ ExpandContent: TypeAlias = Union[
|
|
|
607
643
|
EmbedCard,
|
|
608
644
|
Extension,
|
|
609
645
|
NestedExpand,
|
|
646
|
+
UnknownBlock,
|
|
610
647
|
]
|
|
611
648
|
|
|
612
|
-
BlockTaskItemContent: TypeAlias = Union[Paragraph, Extension]
|
|
649
|
+
BlockTaskItemContent: TypeAlias = Union[Paragraph, Extension, UnknownBlock]
|
|
613
650
|
|
|
614
651
|
TaskListContent: TypeAlias = Union[TaskItem, BlockTaskItem, TaskList]
|
|
615
652
|
|
|
@@ -630,6 +667,7 @@ NonNestableBlockContent: TypeAlias = Union[
|
|
|
630
667
|
BlockCard,
|
|
631
668
|
EmbedCard,
|
|
632
669
|
Extension,
|
|
670
|
+
UnknownBlock,
|
|
633
671
|
]
|
|
634
672
|
|
|
635
673
|
BlockContent: TypeAlias = Union[
|
|
@@ -651,6 +689,7 @@ BlockContent: TypeAlias = Union[
|
|
|
651
689
|
DecisionList,
|
|
652
690
|
Extension,
|
|
653
691
|
BodiedExtension,
|
|
692
|
+
UnknownBlock,
|
|
654
693
|
]
|
|
655
694
|
|
|
656
695
|
BodiedSyncBlockContent: TypeAlias = Union[
|
|
@@ -671,6 +710,7 @@ BodiedSyncBlockContent: TypeAlias = Union[
|
|
|
671
710
|
Rule,
|
|
672
711
|
Table,
|
|
673
712
|
TaskList,
|
|
713
|
+
UnknownBlock,
|
|
674
714
|
]
|
|
675
715
|
|
|
676
716
|
DocContent: TypeAlias = Union[
|
|
@@ -695,4 +735,5 @@ DocContent: TypeAlias = Union[
|
|
|
695
735
|
BodiedExtension,
|
|
696
736
|
SyncBlock,
|
|
697
737
|
BodiedSyncBlock,
|
|
738
|
+
UnknownBlock,
|
|
698
739
|
]
|
|
@@ -194,6 +194,8 @@ def build_html_void(token: HtmlVoid) -> ast.Node | None:
|
|
|
194
194
|
return _build_sync_block(token.attrs)
|
|
195
195
|
case "bodiedSyncBlock":
|
|
196
196
|
return _build_bodied_sync_block(token.attrs)
|
|
197
|
+
case "unknownBlock":
|
|
198
|
+
return _build_unknown_block(token.attrs)
|
|
197
199
|
case _:
|
|
198
200
|
return None
|
|
199
201
|
|
|
@@ -743,6 +745,10 @@ def _build_bodied_sync_block(attrs: Mapping[str, str]) -> ast.BodiedSyncBlock:
|
|
|
743
745
|
)
|
|
744
746
|
|
|
745
747
|
|
|
748
|
+
def _build_unknown_block(attrs: Mapping[str, str]) -> ast.UnknownBlock:
|
|
749
|
+
return ast.UnknownBlock(raw=get_params(attrs))
|
|
750
|
+
|
|
751
|
+
|
|
746
752
|
def _adf_dict_nodes(nodes: list[Any]) -> list[ast.Node]:
|
|
747
753
|
"""Convert raw ADF JSON node dicts into AST nodes via the ADF parser.
|
|
748
754
|
|
|
@@ -230,7 +230,13 @@ def _promote_paired(
|
|
|
230
230
|
# "<div ...></div>" into open/close tokens. Their content (if any) is
|
|
231
231
|
# already encoded in attrs.params, so route them through the void
|
|
232
232
|
# dispatch like at top level.
|
|
233
|
-
if adf_type in {
|
|
233
|
+
if adf_type in {
|
|
234
|
+
"extension",
|
|
235
|
+
"bodiedExtension",
|
|
236
|
+
"syncBlock",
|
|
237
|
+
"bodiedSyncBlock",
|
|
238
|
+
"unknownBlock",
|
|
239
|
+
}:
|
|
234
240
|
node = block.build_html_void(HtmlVoid(tag=tag, attrs=attrs))
|
|
235
241
|
if node is not None and is_table_cell(node):
|
|
236
242
|
return node
|
|
@@ -214,7 +214,16 @@ def _build_paired_inline(
|
|
|
214
214
|
return [_build_media_inline(token.attrs)]
|
|
215
215
|
case "inlineExtension":
|
|
216
216
|
return [_build_inline_extension(token.attrs)]
|
|
217
|
-
case "
|
|
217
|
+
case "unknownInline":
|
|
218
|
+
return [_build_unknown_inline(token.attrs)]
|
|
219
|
+
case (
|
|
220
|
+
"underline"
|
|
221
|
+
| "textColor"
|
|
222
|
+
| "bgColor"
|
|
223
|
+
| "subSup"
|
|
224
|
+
| "annotation"
|
|
225
|
+
| "unknownMark"
|
|
226
|
+
):
|
|
218
227
|
return _apply_html_mark(
|
|
219
228
|
token.tag, token.adf_type, token.attrs, token.inner, parent_marks
|
|
220
229
|
)
|
|
@@ -251,6 +260,9 @@ def _apply_html_mark(
|
|
|
251
260
|
id=p.get("id", ""),
|
|
252
261
|
annotation_type=p.get("annotationType", "inlineComment"),
|
|
253
262
|
)
|
|
263
|
+
case "unknownMark":
|
|
264
|
+
p = get_params(attrs)
|
|
265
|
+
mark = ast.UnknownMark(type=p.get("type", ""), attrs=p.get("attrs"))
|
|
254
266
|
case _:
|
|
255
267
|
content = inline_text(inner)
|
|
256
268
|
text = ast.Text(text=content)
|
|
@@ -330,3 +342,7 @@ def _build_inline_extension(attrs: Mapping[str, str]) -> ast.InlineExtension:
|
|
|
330
342
|
parameters=p.get("parameters"),
|
|
331
343
|
text=p.get("text"),
|
|
332
344
|
)
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
def _build_unknown_inline(attrs: Mapping[str, str]) -> ast.UnknownInline:
|
|
348
|
+
return ast.UnknownInline(raw=get_params(attrs))
|
|
@@ -427,4 +427,11 @@ def parse_block_marks(params: dict[str, Any]) -> list[ast.Mark]:
|
|
|
427
427
|
size=params["borderSize"], color=params.get("borderColor", "")
|
|
428
428
|
)
|
|
429
429
|
)
|
|
430
|
+
if "fontSize" in params:
|
|
431
|
+
marks.append(ast.FontSizeMark(size=params["fontSize"]))
|
|
432
|
+
if "unknownMarks" in params:
|
|
433
|
+
for um in params["unknownMarks"]:
|
|
434
|
+
marks.append(
|
|
435
|
+
ast.UnknownMark(type=um.get("type", ""), attrs=um.get("attrs"))
|
|
436
|
+
)
|
|
430
437
|
return marks
|
|
@@ -226,6 +226,15 @@ def block_marks_params(marks: Sequence[ast.Mark]) -> dict[str, Any]:
|
|
|
226
226
|
case ast.BorderMark(size=size, color=color):
|
|
227
227
|
d["borderSize"] = size
|
|
228
228
|
d["borderColor"] = color
|
|
229
|
+
case ast.FontSizeMark(size=fsize):
|
|
230
|
+
d["fontSize"] = fsize
|
|
231
|
+
case ast.UnknownMark(type=type_, attrs=attrs):
|
|
232
|
+
entry = (
|
|
233
|
+
{"type": type_}
|
|
234
|
+
if attrs is None
|
|
235
|
+
else {"type": type_, "attrs": attrs}
|
|
236
|
+
)
|
|
237
|
+
d.setdefault("unknownMarks", []).append(entry)
|
|
229
238
|
case _:
|
|
230
239
|
pass
|
|
231
240
|
return d
|
|
@@ -302,6 +311,8 @@ def render_block(node: ast.Node) -> str:
|
|
|
302
311
|
return _render_sync_block(node)
|
|
303
312
|
case ast.BodiedSyncBlock():
|
|
304
313
|
return _render_bodied_sync_block(node)
|
|
314
|
+
case ast.UnknownBlock():
|
|
315
|
+
return _render_unknown_block(node)
|
|
305
316
|
case _:
|
|
306
317
|
raise ValueError(f"Unknown block: {type(node).__name__}")
|
|
307
318
|
|
|
@@ -793,6 +804,10 @@ def _render_bodied_sync_block(node: ast.BodiedSyncBlock) -> str:
|
|
|
793
804
|
return _data("bodiedSyncBlock", params)
|
|
794
805
|
|
|
795
806
|
|
|
807
|
+
def _render_unknown_block(node: ast.UnknownBlock) -> str:
|
|
808
|
+
return _data("unknownBlock", build_params(node.raw))
|
|
809
|
+
|
|
810
|
+
|
|
796
811
|
# ── Table ──────────────────────────────────────────────────────────────────────
|
|
797
812
|
|
|
798
813
|
|
|
@@ -990,6 +1005,8 @@ def _render_inline(node: ast.Inline) -> str:
|
|
|
990
1005
|
return _render_media_inline(node)
|
|
991
1006
|
case ast.InlineExtension():
|
|
992
1007
|
return _render_inline_extension(node)
|
|
1008
|
+
case ast.UnknownInline():
|
|
1009
|
+
return _render_unknown_inline(node)
|
|
993
1010
|
case _:
|
|
994
1011
|
raise ValueError(f"Unknown inline: {type(node).__name__}")
|
|
995
1012
|
|
|
@@ -1129,6 +1146,10 @@ def _render_inline_extension(node: ast.InlineExtension) -> str:
|
|
|
1129
1146
|
return el("span", "", adf="inlineExtension", params=params)
|
|
1130
1147
|
|
|
1131
1148
|
|
|
1149
|
+
def _render_unknown_inline(node: ast.UnknownInline) -> str:
|
|
1150
|
+
return el("span", "", adf="unknownInline", params=build_params(node.raw))
|
|
1151
|
+
|
|
1152
|
+
|
|
1132
1153
|
# ── Mark rendering ─────────────────────────────────────────────────────────────
|
|
1133
1154
|
|
|
1134
1155
|
|
|
@@ -1189,6 +1210,13 @@ def _wrap_html_mark(text: str, mark: ast.Mark) -> str:
|
|
|
1189
1210
|
adf="annotation",
|
|
1190
1211
|
params=build_params({"id": id_}),
|
|
1191
1212
|
)
|
|
1213
|
+
case ast.UnknownMark(type=type_, attrs=attrs):
|
|
1214
|
+
return el(
|
|
1215
|
+
"span",
|
|
1216
|
+
text,
|
|
1217
|
+
adf="unknownMark",
|
|
1218
|
+
params=build_params({"type": type_, "attrs": attrs}),
|
|
1219
|
+
)
|
|
1192
1220
|
case _:
|
|
1193
1221
|
return text
|
|
1194
1222
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|