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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: marklas
3
- Version: 0.4.3
3
+ Version: 0.4.4
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>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "marklas"
3
- version = "0.4.3"
3
+ version = "0.4.4"
4
4
  description = "Bidirectional converter between GitHub Flavored Markdown and Atlassian Document Format"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -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
- # Preserve leading/trailing whitespace that _tokenize strips
116
- leading = part[: len(part) - len(part.lstrip())]
117
- trailing = part[len(part.rstrip()) :]
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 item_token.get("children", []):
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