marklas 0.7.1__tar.gz → 0.7.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: marklas
3
- Version: 0.7.1
3
+ Version: 0.7.2
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
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "marklas"
3
- version = "0.7.1"
3
+ version = "0.7.2"
4
4
  description = "Bidirectional converter between GitHub Flavored Markdown and Atlassian Document Format"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -835,92 +835,91 @@ def _find_inline_close(
835
835
 
836
836
 
837
837
  def _normalize_inlines(tokens: list[dict[str, Any]]) -> list[dict[str, Any]]:
838
- """Normalize inline token stream.
838
+ """Recursively pair inline_html tokens at every nesting level.
839
839
 
840
840
  - inline_html pairs → {"_kind": "inline_html", "tag", "adf_type", "attrs", "inner"}
841
- - void inline_html → same with "inner": []
842
841
  - adf-less HTML → removed
842
+ - tokens with children (strong, emphasis, link, etc.) → children normalized
843
843
  - other tokens → pass through
844
+
845
+ After this pass, no raw inline_html open/close tokens remain anywhere in the
846
+ tree; `_flatten_inlines` can assume the tree is fully normalized.
844
847
  """
845
848
  result: list[dict[str, Any]] = []
846
849
  i = 0
847
850
  while i < len(tokens):
848
851
  token = tokens[i]
849
852
 
850
- if token.get("type") != "inline_html":
851
- result.append(token)
852
- i += 1
853
- continue
854
-
855
- raw = token.get("raw", "")
856
- tag, attrs, closing = _parse_tag(raw)
853
+ if token.get("type") == "inline_html":
854
+ raw = token.get("raw", "")
855
+ tag, attrs, closing = _parse_tag(raw)
857
856
 
858
- if closing or not _has_adf(attrs):
859
- i += 1
860
- continue
857
+ if closing or not _has_adf(attrs):
858
+ i += 1
859
+ continue
861
860
 
862
- adf_type = attrs.get("adf", "")
861
+ adf_type = attrs.get("adf", "")
862
+ close_idx = _find_inline_close(tokens, i + 1, tag)
863
+ if close_idx is not None:
864
+ result.append(
865
+ {
866
+ "_kind": "inline_html",
867
+ "tag": tag,
868
+ "adf_type": adf_type,
869
+ "attrs": attrs,
870
+ "inner": _normalize_inlines(tokens[i + 1 : close_idx]),
871
+ }
872
+ )
873
+ i = close_idx + 1
874
+ continue
863
875
 
864
- close_idx = _find_inline_close(tokens, i + 1, tag)
865
- if close_idx is not None:
866
- result.append(
867
- {
868
- "_kind": "inline_html",
869
- "tag": tag,
870
- "adf_type": adf_type,
871
- "attrs": attrs,
872
- "inner": tokens[i + 1 : close_idx],
873
- }
874
- )
875
- i = close_idx + 1
876
+ i += 1
876
877
  continue
877
878
 
879
+ if "children" in token:
880
+ result.append({**token, "children": _normalize_inlines(token["children"])})
881
+ else:
882
+ result.append(token)
878
883
  i += 1
879
884
 
880
885
  return result
881
886
 
882
887
 
883
888
  def _parse_inlines(tokens: list[dict[str, Any]]) -> list[ast.Inline]:
889
+ return _flatten_inlines(_normalize_inlines(tokens), [])
890
+
891
+
892
+ def _flatten_inlines(
893
+ tokens: list[dict[str, Any]], parent_marks: list[ast.Mark]
894
+ ) -> list[ast.Inline]:
895
+ """Walk normalized tokens, accumulating marks. Assumes input is normalized."""
884
896
  result: list[ast.Inline] = []
885
- for token in _normalize_inlines(tokens):
897
+ for token in tokens:
886
898
  if token.get("_kind") == "inline_html":
887
- result.append(
888
- _parse_inline_html(
889
- token["tag"], token["adf_type"], token["attrs"], token["inner"]
890
- )
891
- )
899
+ result.extend(_parse_inline_html(token, parent_marks))
892
900
  else:
893
- result.extend(_flatten_marks(token, []))
901
+ result.extend(_flatten_token(token, parent_marks))
894
902
  return result
895
903
 
896
904
 
897
905
  # ── Mark flattening ───────────────────────────────────────────────────────────
898
906
 
899
907
 
900
- def _flatten_children(
901
- children: list[dict[str, Any]], marks: list[ast.Mark]
902
- ) -> list[ast.Inline]:
903
- result: list[ast.Inline] = []
904
- for child in children:
905
- result.extend(_flatten_marks(child, marks))
906
- return result
907
-
908
-
909
- def _flatten_marks(
908
+ def _flatten_token(
910
909
  token: dict[str, Any], parent_marks: list[ast.Mark]
911
910
  ) -> list[ast.Inline]:
912
911
  t = token.get("type", "")
913
912
  match t:
914
913
  case "strong":
915
- return _flatten_children(
914
+ return _flatten_inlines(
916
915
  token.get("children", []), [*parent_marks, ast.StrongMark()]
917
916
  )
918
917
  case "emphasis":
919
- return _flatten_children(
918
+ return _flatten_inlines(
920
919
  token.get("children", []), [*parent_marks, ast.EmMark()]
921
920
  )
922
921
  case "strikethrough":
923
- return _flatten_children(
922
+ return _flatten_inlines(
924
923
  token.get("children", []), [*parent_marks, ast.StrikeMark()]
925
924
  )
926
925
  case "codespan":
@@ -934,20 +933,22 @@ def _flatten_marks(
934
933
  *parent_marks,
935
934
  ast.LinkMark(href=href, title=title),
936
935
  ]
937
- return _flatten_children(token.get("children", []), link_marks)
936
+ return _flatten_inlines(token.get("children", []), link_marks)
938
937
  case "text":
939
938
  text = token.get("raw", "")
940
939
  if parent_marks:
941
- return [ast.Text(text=text, marks=parent_marks)]
940
+ return [ast.Text(text=text, marks=list(parent_marks))]
942
941
  return [ast.Text(text=text)]
943
942
  case "softbreak":
943
+ if parent_marks:
944
+ return [ast.Text(text=" ", marks=list(parent_marks))]
944
945
  return [ast.Text(text=" ")]
945
946
  case "linebreak":
946
947
  return [ast.HardBreak()]
947
948
  case _:
948
949
  children = token.get("children", [])
949
950
  if children:
950
- return _flatten_children(children, parent_marks)
951
+ return _flatten_inlines(children, parent_marks)
951
952
  return []
952
953
 
953
954
 
@@ -959,40 +960,46 @@ def _inline_content_text(tokens: list[dict[str, Any]]) -> str:
959
960
 
960
961
 
961
962
  def _parse_inline_html(
962
- tag: str, adf_type: str, attrs: dict[str, str], content_tokens: list[dict[str, Any]]
963
- ) -> ast.Inline:
964
- content = _inline_content_text(content_tokens)
963
+ token: dict[str, Any], parent_marks: list[ast.Mark]
964
+ ) -> list[ast.Inline]:
965
+ tag = token["tag"]
966
+ adf_type = token["adf_type"]
967
+ attrs = token["attrs"]
968
+ inner = token["inner"]
969
+ content = _inline_content_text(inner)
965
970
  match adf_type:
966
971
  case "mention":
967
- return _parse_mention(attrs, content)
972
+ return [_parse_mention(attrs, content)]
968
973
  case "emoji":
969
- return _parse_emoji(attrs, content)
974
+ return [_parse_emoji(attrs, content)]
970
975
  case "date":
971
- return _parse_date(attrs)
976
+ return [_parse_date(attrs)]
972
977
  case "status":
973
- return _parse_status(attrs, content)
978
+ return [_parse_status(attrs, content)]
974
979
  case "inlineCard":
975
- return _parse_inline_card(attrs)
980
+ return [_parse_inline_card(attrs)]
976
981
  case "placeholder":
977
- return _parse_placeholder(content)
982
+ return [_parse_placeholder(content)]
978
983
  case "mediaInline":
979
- return _parse_media_inline(attrs)
984
+ return [_parse_media_inline(attrs)]
980
985
  case "inlineExtension":
981
- return _parse_inline_data(attrs)
986
+ return [_parse_inline_data(attrs)]
982
987
  case "underline" | "textColor" | "bgColor" | "subSup" | "annotation":
983
- return _parse_html_mark(tag, adf_type, attrs, content_tokens, content)
988
+ return _parse_html_mark(tag, adf_type, attrs, inner, parent_marks)
984
989
  case _:
985
- return ast.Text(text=content)
990
+ text = ast.Text(text=content)
991
+ if parent_marks:
992
+ text.marks = list(parent_marks)
993
+ return [text]
986
994
 
987
995
 
988
996
  def _parse_html_mark(
989
997
  tag: str,
990
998
  adf_type: str,
991
999
  attrs: dict[str, str],
992
- content_tokens: list[dict[str, Any]],
993
- content: str,
994
- ) -> ast.Inline:
995
- """Parse HTML mark element → Text with mark attached."""
1000
+ inner: list[dict[str, Any]],
1001
+ parent_marks: list[ast.Mark],
1002
+ ) -> list[ast.Inline]:
996
1003
  mark: ast.Mark
997
1004
  match adf_type:
998
1005
  case "underline":
@@ -1010,13 +1017,17 @@ def _parse_html_mark(
1010
1017
  annotation_type=p.get("annotationType", "inlineComment"),
1011
1018
  )
1012
1019
  case _:
1013
- return ast.Text(text=content)
1020
+ content = _inline_content_text(inner)
1021
+ text = ast.Text(text=content)
1022
+ if parent_marks:
1023
+ text.marks = list(parent_marks)
1024
+ return [text]
1014
1025
 
1015
- inlines = _parse_inlines(content_tokens)
1026
+ inlines = _flatten_inlines(inner, parent_marks)
1016
1027
  for node in inlines:
1017
1028
  if isinstance(node, ast.Text):
1018
1029
  node.marks = [*node.marks, mark]
1019
- return inlines[0] if inlines else ast.Text(text=content)
1030
+ return inlines
1020
1031
 
1021
1032
 
1022
1033
  def _parse_mention(attrs: dict[str, str], content: str) -> ast.Mention:
File without changes
File without changes
File without changes
File without changes