marklas 0.4.3__tar.gz → 0.4.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.4.3 → marklas-0.4.4}/PKG-INFO +1 -1
- {marklas-0.4.3 → marklas-0.4.4}/pyproject.toml +1 -1
- {marklas-0.4.3 → marklas-0.4.4}/src/marklas/md/parser.py +13 -13
- {marklas-0.4.3 → marklas-0.4.4}/src/marklas/md/renderer.py +12 -0
- {marklas-0.4.3 → marklas-0.4.4}/README.md +0 -0
- {marklas-0.4.3 → marklas-0.4.4}/src/marklas/__init__.py +0 -0
- {marklas-0.4.3 → marklas-0.4.4}/src/marklas/adf/__init__.py +0 -0
- {marklas-0.4.3 → marklas-0.4.4}/src/marklas/adf/parser.py +0 -0
- {marklas-0.4.3 → marklas-0.4.4}/src/marklas/adf/renderer.py +0 -0
- {marklas-0.4.3 → marklas-0.4.4}/src/marklas/adf/schema.py +0 -0
- {marklas-0.4.3 → marklas-0.4.4}/src/marklas/convert.py +0 -0
- {marklas-0.4.3 → marklas-0.4.4}/src/marklas/md/__init__.py +0 -0
- {marklas-0.4.3 → marklas-0.4.4}/src/marklas/nodes/__init__.py +0 -0
- {marklas-0.4.3 → marklas-0.4.4}/src/marklas/nodes/base.py +0 -0
- {marklas-0.4.3 → marklas-0.4.4}/src/marklas/nodes/blocks.py +0 -0
- {marklas-0.4.3 → marklas-0.4.4}/src/marklas/nodes/inlines.py +0 -0
- {marklas-0.4.3 → marklas-0.4.4}/src/marklas/py.typed +0 -0
|
@@ -4,6 +4,7 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import json
|
|
6
6
|
import re
|
|
7
|
+
import textwrap
|
|
7
8
|
from typing import Any, Literal, cast
|
|
8
9
|
|
|
9
10
|
import mistune
|
|
@@ -21,6 +22,7 @@ _tokenize = mistune.create_markdown(
|
|
|
21
22
|
renderer="ast",
|
|
22
23
|
plugins=["table", "strikethrough", "task_lists"],
|
|
23
24
|
)
|
|
25
|
+
_inline_parser = _tokenize.inline
|
|
24
26
|
|
|
25
27
|
|
|
26
28
|
# ---------------------------------------------------------------------------
|
|
@@ -112,18 +114,9 @@ def _split_block_html(raw: str) -> list[dict[str, Any]] | None:
|
|
|
112
114
|
if parsed:
|
|
113
115
|
synthetic_tokens.append({"type": "inline_html", "raw": part})
|
|
114
116
|
else:
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if leading:
|
|
119
|
-
synthetic_tokens.append({"type": "text", "raw": leading})
|
|
120
|
-
inner_tokens = cast(list[dict[str, Any]], _tokenize(part))
|
|
121
|
-
for tok in inner_tokens:
|
|
122
|
-
if tok["type"] == "paragraph":
|
|
123
|
-
children = cast(list[dict[str, Any]], tok.get("children", []))
|
|
124
|
-
synthetic_tokens.extend(children)
|
|
125
|
-
if trailing:
|
|
126
|
-
synthetic_tokens.append({"type": "text", "raw": trailing})
|
|
117
|
+
state = _inline_parser.state_cls(env={})
|
|
118
|
+
state.src = part
|
|
119
|
+
synthetic_tokens.extend(_inline_parser.parse(state))
|
|
127
120
|
|
|
128
121
|
if not synthetic_tokens:
|
|
129
122
|
return None
|
|
@@ -301,6 +294,7 @@ def _parse_code_block(token: dict[str, Any]) -> blocks.CodeBlock:
|
|
|
301
294
|
code = token.get("raw", "")
|
|
302
295
|
if code.endswith("\n"):
|
|
303
296
|
code = code[:-1]
|
|
297
|
+
code = textwrap.dedent(code)
|
|
304
298
|
info = token.get("attrs", {}).get("info", "")
|
|
305
299
|
language = info or None
|
|
306
300
|
return blocks.CodeBlock(code=code, language=language)
|
|
@@ -337,8 +331,14 @@ def _parse_list(token: dict[str, Any]) -> blocks.BulletList | blocks.OrderedList
|
|
|
337
331
|
def _parse_list_item_children(
|
|
338
332
|
item_token: dict[str, Any], tight: bool
|
|
339
333
|
) -> list[blocks.Block]:
|
|
334
|
+
matched = _match_block_annotations(item_token.get("children", []))
|
|
340
335
|
children: list[blocks.Block] = []
|
|
341
|
-
for child in
|
|
336
|
+
for child in matched:
|
|
337
|
+
if child.get("_annotated"):
|
|
338
|
+
node = _parse_block(child)
|
|
339
|
+
if node is not None:
|
|
340
|
+
children.append(node)
|
|
341
|
+
continue
|
|
342
342
|
match child["type"]:
|
|
343
343
|
case "paragraph":
|
|
344
344
|
children.append(_parse_paragraph(child))
|
|
@@ -181,11 +181,23 @@ def _render_ordered_list(node: blocks.OrderedList) -> str:
|
|
|
181
181
|
return sep.join(items)
|
|
182
182
|
|
|
183
183
|
|
|
184
|
+
def _is_whitespace_only_paragraph(node: blocks.Block) -> bool:
|
|
185
|
+
return (
|
|
186
|
+
isinstance(node, blocks.Paragraph)
|
|
187
|
+
and all(
|
|
188
|
+
isinstance(c, inlines.Text) and not c.text.strip() for c in node.children
|
|
189
|
+
)
|
|
190
|
+
and len(node.children) > 0
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
|
|
184
194
|
def _render_list_item_body(children: list[blocks.Block], tight: bool) -> str:
|
|
185
195
|
if tight and len(children) == 1 and isinstance(children[0], blocks.Paragraph):
|
|
186
196
|
return _render_inlines(children[0].children)
|
|
187
197
|
parts: list[str] = []
|
|
188
198
|
for child in children:
|
|
199
|
+
if _is_whitespace_only_paragraph(child):
|
|
200
|
+
continue
|
|
189
201
|
rendered = _render_block(child)
|
|
190
202
|
parts.append(rendered)
|
|
191
203
|
body = "\n\n".join(parts)
|
|
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
|
|
File without changes
|
|
File without changes
|