marklas 0.4.0__tar.gz → 0.4.2__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.4.0 → marklas-0.4.2}/PKG-INFO +12 -3
- {marklas-0.4.0 → marklas-0.4.2}/README.md +11 -2
- {marklas-0.4.0 → marklas-0.4.2}/pyproject.toml +1 -1
- {marklas-0.4.0 → marklas-0.4.2}/src/marklas/adf/parser.py +15 -8
- {marklas-0.4.0 → marklas-0.4.2}/src/marklas/adf/renderer.py +92 -37
- {marklas-0.4.0 → marklas-0.4.2}/src/marklas/adf/schema.py +2 -2
- {marklas-0.4.0 → marklas-0.4.2}/src/marklas/convert.py +2 -2
- marklas-0.4.2/src/marklas/md/parser.py +1224 -0
- marklas-0.4.2/src/marklas/md/renderer.py +802 -0
- {marklas-0.4.0 → marklas-0.4.2}/src/marklas/nodes/blocks.py +10 -10
- {marklas-0.4.0 → marklas-0.4.2}/src/marklas/nodes/inlines.py +4 -4
- marklas-0.4.0/src/marklas/md/parser.py +0 -654
- marklas-0.4.0/src/marklas/md/renderer.py +0 -610
- {marklas-0.4.0 → marklas-0.4.2}/src/marklas/__init__.py +0 -0
- {marklas-0.4.0 → marklas-0.4.2}/src/marklas/adf/__init__.py +0 -0
- {marklas-0.4.0 → marklas-0.4.2}/src/marklas/md/__init__.py +0 -0
- {marklas-0.4.0 → marklas-0.4.2}/src/marklas/nodes/__init__.py +0 -0
- {marklas-0.4.0 → marklas-0.4.2}/src/marklas/nodes/base.py +0 -0
- {marklas-0.4.0 → marklas-0.4.2}/src/marklas/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: marklas
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.2
|
|
4
4
|
Summary: Bidirectional converter between GitHub Flavored Markdown and Atlassian Document Format
|
|
5
5
|
Author: byExist
|
|
6
6
|
Author-email: byExist <jongbeom.kwon@gmail.com>
|
|
@@ -27,7 +27,7 @@ Description-Content-Type: text/markdown
|
|
|
27
27
|
</p>
|
|
28
28
|
|
|
29
29
|
<p align="center">
|
|
30
|
-
|
|
30
|
+
Bidirectional converter between <b>Markdown</b> and <b>Atlassian Document Format (ADF)</b>.
|
|
31
31
|
</p>
|
|
32
32
|
|
|
33
33
|
---
|
|
@@ -114,6 +114,16 @@ Do **not** deploy on Fridays.
|
|
|
114
114
|
<!-- /adf:panel -->
|
|
115
115
|
```
|
|
116
116
|
|
|
117
|
+
To get clean Markdown without annotations, pass `annotate=False`. ADF-only attributes are stripped and only standard Markdown elements remain:
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
clean_md = to_md(adf_with_panel, annotate=False)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
```markdown
|
|
124
|
+
Do **not** deploy on Fridays.
|
|
125
|
+
```
|
|
126
|
+
|
|
117
127
|
### Roundtrip
|
|
118
128
|
|
|
119
129
|
```python
|
|
@@ -144,5 +154,4 @@ Markdown is significantly more compact than ADF JSON — critical for LLM-based
|
|
|
144
154
|
```bash
|
|
145
155
|
uv sync --extra dev
|
|
146
156
|
uv run pytest -v
|
|
147
|
-
uv run black src/ tests/
|
|
148
157
|
```
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
</p>
|
|
9
9
|
|
|
10
10
|
<p align="center">
|
|
11
|
-
|
|
11
|
+
Bidirectional converter between <b>Markdown</b> and <b>Atlassian Document Format (ADF)</b>.
|
|
12
12
|
</p>
|
|
13
13
|
|
|
14
14
|
---
|
|
@@ -95,6 +95,16 @@ Do **not** deploy on Fridays.
|
|
|
95
95
|
<!-- /adf:panel -->
|
|
96
96
|
```
|
|
97
97
|
|
|
98
|
+
To get clean Markdown without annotations, pass `annotate=False`. ADF-only attributes are stripped and only standard Markdown elements remain:
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
clean_md = to_md(adf_with_panel, annotate=False)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
```markdown
|
|
105
|
+
Do **not** deploy on Fridays.
|
|
106
|
+
```
|
|
107
|
+
|
|
98
108
|
### Roundtrip
|
|
99
109
|
|
|
100
110
|
```python
|
|
@@ -125,5 +135,4 @@ Markdown is significantly more compact than ADF JSON — critical for LLM-based
|
|
|
125
135
|
```bash
|
|
126
136
|
uv sync --extra dev
|
|
127
137
|
uv run pytest -v
|
|
128
|
-
uv run black src/ tests/
|
|
129
138
|
```
|
|
@@ -261,10 +261,12 @@ def _parse_table(node: schema.Table) -> blocks.Table:
|
|
|
261
261
|
|
|
262
262
|
if not rows:
|
|
263
263
|
return blocks.Table(
|
|
264
|
-
head=[],
|
|
264
|
+
head=[],
|
|
265
|
+
body=[],
|
|
265
266
|
display_mode=display_mode,
|
|
266
267
|
is_number_column_enabled=is_number_column_enabled,
|
|
267
|
-
layout=layout,
|
|
268
|
+
layout=layout,
|
|
269
|
+
width=width,
|
|
268
270
|
)
|
|
269
271
|
|
|
270
272
|
num_rows = len(rows)
|
|
@@ -305,10 +307,12 @@ def _parse_table(node: schema.Table) -> blocks.Table:
|
|
|
305
307
|
head = grid[0] if is_header else []
|
|
306
308
|
body = grid[1:] if is_header else grid
|
|
307
309
|
return blocks.Table(
|
|
308
|
-
head=head,
|
|
310
|
+
head=head,
|
|
311
|
+
body=body,
|
|
309
312
|
display_mode=display_mode,
|
|
310
313
|
is_number_column_enabled=is_number_column_enabled,
|
|
311
|
-
layout=layout,
|
|
314
|
+
layout=layout,
|
|
315
|
+
width=width,
|
|
312
316
|
)
|
|
313
317
|
|
|
314
318
|
|
|
@@ -336,7 +340,12 @@ def _parse_inlines(nodes: list[schema.Inline]) -> list[inlines.Inline]:
|
|
|
336
340
|
return _merge_adjacent(result)
|
|
337
341
|
|
|
338
342
|
|
|
339
|
-
_MERGEABLE = (
|
|
343
|
+
_MERGEABLE = (
|
|
344
|
+
inlines.Strong,
|
|
345
|
+
inlines.Emphasis,
|
|
346
|
+
inlines.Strikethrough,
|
|
347
|
+
inlines.Underline,
|
|
348
|
+
)
|
|
340
349
|
|
|
341
350
|
|
|
342
351
|
def _merge_adjacent(nodes: list[inlines.Inline]) -> list[inlines.Inline]:
|
|
@@ -493,9 +502,7 @@ def _wrap_marks(
|
|
|
493
502
|
case "em":
|
|
494
503
|
return [inlines.Emphasis(children=_wrap_marks(text, marks, index + 1))]
|
|
495
504
|
case "strike":
|
|
496
|
-
return [
|
|
497
|
-
inlines.Strikethrough(children=_wrap_marks(text, marks, index + 1))
|
|
498
|
-
]
|
|
505
|
+
return [inlines.Strikethrough(children=_wrap_marks(text, marks, index + 1))]
|
|
499
506
|
case "underline":
|
|
500
507
|
return [inlines.Underline(children=_wrap_marks(text, marks, index + 1))]
|
|
501
508
|
case "textColor":
|
|
@@ -82,7 +82,12 @@ def _render_block(node: blocks.Block) -> dict[str, Any] | None:
|
|
|
82
82
|
return _render_block_card(node)
|
|
83
83
|
case blocks.EmbedCard():
|
|
84
84
|
return _render_embed_card(node)
|
|
85
|
-
case
|
|
85
|
+
case (
|
|
86
|
+
blocks.Extension()
|
|
87
|
+
| blocks.BodiedExtension()
|
|
88
|
+
| blocks.SyncBlock()
|
|
89
|
+
| blocks.BodiedSyncBlock()
|
|
90
|
+
):
|
|
86
91
|
return node.raw
|
|
87
92
|
case _:
|
|
88
93
|
return None
|
|
@@ -92,7 +97,7 @@ def _render_block(node: blocks.Block) -> dict[str, Any] | None:
|
|
|
92
97
|
|
|
93
98
|
|
|
94
99
|
def _render_paragraph(node: blocks.Paragraph) -> dict[str, Any]:
|
|
95
|
-
#
|
|
100
|
+
# Single Image → mediaSingle conversion (intersection reverse-mapping)
|
|
96
101
|
if len(node.children) == 1 and isinstance(node.children[0], inlines.Image):
|
|
97
102
|
img = node.children[0]
|
|
98
103
|
media: dict[str, Any] = {
|
|
@@ -101,7 +106,10 @@ def _render_paragraph(node: blocks.Paragraph) -> dict[str, Any]:
|
|
|
101
106
|
}
|
|
102
107
|
return {"type": "mediaSingle", "content": [media]}
|
|
103
108
|
|
|
104
|
-
result: dict[str, Any] = {
|
|
109
|
+
result: dict[str, Any] = {
|
|
110
|
+
"type": "paragraph",
|
|
111
|
+
"content": _render_inlines(node.children),
|
|
112
|
+
}
|
|
105
113
|
_apply_block_marks(result, node.alignment, node.indentation)
|
|
106
114
|
return result
|
|
107
115
|
|
|
@@ -129,7 +137,7 @@ def _render_blockquote(node: blocks.BlockQuote) -> dict[str, Any]:
|
|
|
129
137
|
|
|
130
138
|
|
|
131
139
|
def _render_bullet_list(node: blocks.BulletList) -> dict[str, Any]:
|
|
132
|
-
#
|
|
140
|
+
# Convert to taskList if any items have checked state (intersection reverse-mapping)
|
|
133
141
|
if any(item.checked is not None for item in node.items):
|
|
134
142
|
task_items: list[dict[str, Any]] = []
|
|
135
143
|
for item in node.items:
|
|
@@ -214,14 +222,20 @@ def _render_panel(node: blocks.Panel) -> dict[str, Any]:
|
|
|
214
222
|
|
|
215
223
|
|
|
216
224
|
def _render_expand(node: blocks.Expand) -> dict[str, Any]:
|
|
217
|
-
result: dict[str, Any] = {
|
|
225
|
+
result: dict[str, Any] = {
|
|
226
|
+
"type": "expand",
|
|
227
|
+
"content": _render_children(node.children),
|
|
228
|
+
}
|
|
218
229
|
if node.title:
|
|
219
230
|
result["attrs"] = {"title": node.title}
|
|
220
231
|
return result
|
|
221
232
|
|
|
222
233
|
|
|
223
234
|
def _render_nested_expand(node: blocks.NestedExpand) -> dict[str, Any]:
|
|
224
|
-
result: dict[str, Any] = {
|
|
235
|
+
result: dict[str, Any] = {
|
|
236
|
+
"type": "nestedExpand",
|
|
237
|
+
"content": _render_children(node.children),
|
|
238
|
+
}
|
|
225
239
|
if node.title:
|
|
226
240
|
result["attrs"] = {"title": node.title}
|
|
227
241
|
return result
|
|
@@ -231,11 +245,13 @@ def _render_layout_section(node: blocks.LayoutSection) -> dict[str, Any]:
|
|
|
231
245
|
columns: list[dict[str, Any]] = []
|
|
232
246
|
for col in node.columns:
|
|
233
247
|
width = col.width if col.width is not None else 100 / len(node.columns)
|
|
234
|
-
columns.append(
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
248
|
+
columns.append(
|
|
249
|
+
{
|
|
250
|
+
"type": "layoutColumn",
|
|
251
|
+
"attrs": {"width": width},
|
|
252
|
+
"content": _render_children(col.children),
|
|
253
|
+
}
|
|
254
|
+
)
|
|
239
255
|
return {"type": "layoutSection", "content": columns}
|
|
240
256
|
|
|
241
257
|
|
|
@@ -257,7 +273,10 @@ def _render_media(media: blocks.Media) -> dict[str, Any]:
|
|
|
257
273
|
|
|
258
274
|
|
|
259
275
|
def _render_media_single(node: blocks.MediaSingle) -> dict[str, Any]:
|
|
260
|
-
result: dict[str, Any] = {
|
|
276
|
+
result: dict[str, Any] = {
|
|
277
|
+
"type": "mediaSingle",
|
|
278
|
+
"content": [_render_media(node.media)],
|
|
279
|
+
}
|
|
261
280
|
attrs: dict[str, Any] = {}
|
|
262
281
|
if node.layout is not None:
|
|
263
282
|
attrs["layout"] = node.layout
|
|
@@ -298,7 +317,7 @@ def _render_embed_card(node: blocks.EmbedCard) -> dict[str, Any]:
|
|
|
298
317
|
|
|
299
318
|
|
|
300
319
|
def _render_table(node: blocks.Table) -> dict[str, Any]:
|
|
301
|
-
#
|
|
320
|
+
# Collect all rows
|
|
302
321
|
all_cell_rows: list[list[blocks.TableCell]] = []
|
|
303
322
|
if node.head:
|
|
304
323
|
all_cell_rows.append(node.head)
|
|
@@ -308,7 +327,7 @@ def _render_table(node: blocks.Table) -> dict[str, Any]:
|
|
|
308
327
|
num_rows = len(all_cell_rows)
|
|
309
328
|
num_cols = max((len(cells) for cells in all_cell_rows), default=0)
|
|
310
329
|
|
|
311
|
-
# colspan/rowspan
|
|
330
|
+
# Calculate positions occupied by colspan/rowspan (excluding origin)
|
|
312
331
|
occupied: list[list[bool]] = [[False] * num_cols for _ in range(num_rows)]
|
|
313
332
|
for r, cells in enumerate(all_cell_rows):
|
|
314
333
|
for col_idx, cell in enumerate(cells):
|
|
@@ -316,17 +335,23 @@ def _render_table(node: blocks.Table) -> dict[str, Any]:
|
|
|
316
335
|
rs = cell.rowspan or 1
|
|
317
336
|
for dr in range(rs):
|
|
318
337
|
for dc in range(cs):
|
|
319
|
-
if (
|
|
338
|
+
if (
|
|
339
|
+
(dr > 0 or dc > 0)
|
|
340
|
+
and r + dr < num_rows
|
|
341
|
+
and col_idx + dc < num_cols
|
|
342
|
+
):
|
|
320
343
|
occupied[r + dr][col_idx + dc] = True
|
|
321
344
|
|
|
322
|
-
#
|
|
345
|
+
# Render while skipping occupied cells
|
|
323
346
|
rows: list[dict[str, Any]] = []
|
|
324
347
|
for r, cells in enumerate(all_cell_rows):
|
|
325
348
|
row_cells: list[dict[str, Any]] = []
|
|
326
349
|
for col_idx, cell in enumerate(cells):
|
|
327
350
|
if col_idx < num_cols and occupied[r][col_idx]:
|
|
328
351
|
continue
|
|
329
|
-
cell_type =
|
|
352
|
+
cell_type = (
|
|
353
|
+
"tableHeader" if isinstance(cell, blocks.TableHeader) else "tableCell"
|
|
354
|
+
)
|
|
330
355
|
cell_json: dict[str, Any] = {
|
|
331
356
|
"type": cell_type,
|
|
332
357
|
"content": _render_children(cell.children),
|
|
@@ -379,7 +404,7 @@ def _render_inlines(nodes: list[inlines.Inline]) -> list[dict[str, Any]]:
|
|
|
379
404
|
def _render_inlines_from_blocks(
|
|
380
405
|
block_nodes: list[blocks.Block],
|
|
381
406
|
) -> list[dict[str, Any]]:
|
|
382
|
-
"""ListItem.children(
|
|
407
|
+
"""Extract inlines from ListItem.children (block list) for taskItem content."""
|
|
383
408
|
result: list[dict[str, Any]] = []
|
|
384
409
|
for block in block_nodes:
|
|
385
410
|
if isinstance(block, blocks.Paragraph):
|
|
@@ -401,22 +426,30 @@ def _flatten_inline(
|
|
|
401
426
|
|
|
402
427
|
case inlines.Strong():
|
|
403
428
|
new_marks: list[dict[str, Any]] = [*marks, {"type": "strong"}]
|
|
404
|
-
return [
|
|
429
|
+
return [
|
|
430
|
+
child for c in node.children for child in _flatten_inline(c, new_marks)
|
|
431
|
+
]
|
|
405
432
|
|
|
406
433
|
case inlines.Emphasis():
|
|
407
434
|
new_marks: list[dict[str, Any]] = [*marks, {"type": "em"}]
|
|
408
|
-
return [
|
|
435
|
+
return [
|
|
436
|
+
child for c in node.children for child in _flatten_inline(c, new_marks)
|
|
437
|
+
]
|
|
409
438
|
|
|
410
439
|
case inlines.Strikethrough():
|
|
411
440
|
new_marks: list[dict[str, Any]] = [*marks, {"type": "strike"}]
|
|
412
|
-
return [
|
|
441
|
+
return [
|
|
442
|
+
child for c in node.children for child in _flatten_inline(c, new_marks)
|
|
443
|
+
]
|
|
413
444
|
|
|
414
445
|
case inlines.Link():
|
|
415
446
|
link_mark: dict[str, Any] = {"type": "link", "attrs": {"href": node.url}}
|
|
416
447
|
if node.title:
|
|
417
448
|
link_mark["attrs"]["title"] = node.title
|
|
418
449
|
new_marks: list[dict[str, Any]] = [*marks, link_mark]
|
|
419
|
-
return [
|
|
450
|
+
return [
|
|
451
|
+
child for c in node.children for child in _flatten_inline(c, new_marks)
|
|
452
|
+
]
|
|
420
453
|
|
|
421
454
|
case inlines.CodeSpan():
|
|
422
455
|
text = {"type": "text", "text": node.code}
|
|
@@ -431,7 +464,7 @@ def _flatten_inline(
|
|
|
431
464
|
return [{"type": "text", "text": " "}]
|
|
432
465
|
|
|
433
466
|
case inlines.Image():
|
|
434
|
-
#
|
|
467
|
+
# Inline Image → fallback to link mark + alt text
|
|
435
468
|
link_mark = {"type": "link", "attrs": {"href": node.url}}
|
|
436
469
|
if node.title:
|
|
437
470
|
link_mark["attrs"]["title"] = node.title
|
|
@@ -441,7 +474,7 @@ def _flatten_inline(
|
|
|
441
474
|
text["marks"] = _sort_marks(new_marks)
|
|
442
475
|
return [text]
|
|
443
476
|
|
|
444
|
-
#
|
|
477
|
+
# Difference-set inline nodes
|
|
445
478
|
case inlines.Mention():
|
|
446
479
|
attrs: dict[str, Any] = {"id": node.id}
|
|
447
480
|
if node.text is not None:
|
|
@@ -498,29 +531,51 @@ def _flatten_inline(
|
|
|
498
531
|
case inlines.InlineExtension():
|
|
499
532
|
return [node.raw]
|
|
500
533
|
|
|
501
|
-
#
|
|
534
|
+
# Difference-set wrapping marks
|
|
502
535
|
case inlines.Underline():
|
|
503
536
|
new_marks: list[dict[str, Any]] = [*marks, {"type": "underline"}]
|
|
504
|
-
return [
|
|
537
|
+
return [
|
|
538
|
+
child for c in node.children for child in _flatten_inline(c, new_marks)
|
|
539
|
+
]
|
|
505
540
|
|
|
506
541
|
case inlines.TextColor():
|
|
507
|
-
new_marks: list[dict[str, Any]] = [
|
|
508
|
-
|
|
542
|
+
new_marks: list[dict[str, Any]] = [
|
|
543
|
+
*marks,
|
|
544
|
+
{"type": "textColor", "attrs": {"color": node.color}},
|
|
545
|
+
]
|
|
546
|
+
return [
|
|
547
|
+
child for c in node.children for child in _flatten_inline(c, new_marks)
|
|
548
|
+
]
|
|
509
549
|
|
|
510
550
|
case inlines.BackgroundColor():
|
|
511
|
-
new_marks: list[dict[str, Any]] = [
|
|
512
|
-
|
|
551
|
+
new_marks: list[dict[str, Any]] = [
|
|
552
|
+
*marks,
|
|
553
|
+
{"type": "backgroundColor", "attrs": {"color": node.color}},
|
|
554
|
+
]
|
|
555
|
+
return [
|
|
556
|
+
child for c in node.children for child in _flatten_inline(c, new_marks)
|
|
557
|
+
]
|
|
513
558
|
|
|
514
559
|
case inlines.SubSup():
|
|
515
|
-
new_marks: list[dict[str, Any]] = [
|
|
516
|
-
|
|
560
|
+
new_marks: list[dict[str, Any]] = [
|
|
561
|
+
*marks,
|
|
562
|
+
{"type": "subsup", "attrs": {"type": node.type}},
|
|
563
|
+
]
|
|
564
|
+
return [
|
|
565
|
+
child for c in node.children for child in _flatten_inline(c, new_marks)
|
|
566
|
+
]
|
|
517
567
|
|
|
518
568
|
case inlines.Annotation():
|
|
519
|
-
new_marks: list[dict[str, Any]] = [
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
569
|
+
new_marks: list[dict[str, Any]] = [
|
|
570
|
+
*marks,
|
|
571
|
+
{
|
|
572
|
+
"type": "annotation",
|
|
573
|
+
"attrs": {"id": node.id, "annotationType": node.annotation_type},
|
|
574
|
+
},
|
|
575
|
+
]
|
|
576
|
+
return [
|
|
577
|
+
child for c in node.children for child in _flatten_inline(c, new_marks)
|
|
578
|
+
]
|
|
524
579
|
|
|
525
580
|
case _:
|
|
526
581
|
return []
|
|
@@ -539,8 +539,8 @@ class Doc(TypedDict):
|
|
|
539
539
|
|
|
540
540
|
|
|
541
541
|
# ── Mark ordering ─────────────────────────────────────────────────────
|
|
542
|
-
# code
|
|
543
|
-
#
|
|
542
|
+
# code must be last since it terminates recursion (returns CodeSpan).
|
|
543
|
+
# This ordering is shared by both the parser and the renderer.
|
|
544
544
|
|
|
545
545
|
MARK_ORDER: dict[str, int] = {
|
|
546
546
|
"link": 0,
|
|
@@ -12,5 +12,5 @@ def to_adf(markdown: str) -> dict[str, Any]:
|
|
|
12
12
|
return _render_adf(_parse_md(markdown))
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
def to_md(adf: dict[str, Any]) -> str:
|
|
16
|
-
return _render_md(_parse_adf(adf))
|
|
15
|
+
def to_md(adf: dict[str, Any], *, annotate: bool = True) -> str:
|
|
16
|
+
return _render_md(_parse_adf(adf), annotate=annotate)
|