MCPcopy Create free account
hub / github.com/Freedium-cfd/web / parse_markups

Function parse_markups

medium-parser/medium_parser/markups.py:14–59  ·  view source on GitHub ↗
(
    markups: list[dict[str, str | jinja2.Template]]
)

Source from the content-addressed store, hash-verified

12
13
14def parse_markups(
15 markups: list[dict[str, str | jinja2.Template]]
16) -> list[dict[str, str | jinja2.Template]]:
17 markups_out = []
18
19 for markup in markups:
20 if markup["type"] == "A":
21 if markup["anchorType"] == "LINK":
22 target: str = ""
23 if not markup.get("href", "").startswith("#"):
24 target = "_blank"
25
26 template = jinja_env_debug.from_string(
27 '<a style="text-decoration: underline;" rel="{{rel}}" title="{{title}}" href="{{href}}" target="{{target}}">{{text}}</a>'
28 )
29 template_rendered = template.render(
30 raw_render(
31 rel=markup.get("rel", ""),
32 target=target,
33 title=markup.get("title", ""),
34 href=markup["href"],
35 )
36 )
37 elif markup["anchorType"] == "USER":
38 template = jinja_env_debug.from_string(
39 '<a style="text-decoration: underline;" href="https://medium.com/u/{{userId}}">{{text}}</a>'
40 )
41 template_rendered = template.render(userId=markup["userId"])
42 else:
43 continue
44 elif markup["type"] == "STRONG":
45 template_rendered = "<strong>{{text}}</strong>"
46 elif markup["type"] == "EM":
47 template_rendered = "<em>{{text}}</em>"
48 elif markup["type"] == "CODE":
49 template_rendered = (
50 "<code class='p-1.5 bg-gray-300 dark:bg-gray-600'>{{text}}</code>"
51 )
52 else:
53 continue
54
55 template = jinja_env_debug.from_string(template_rendered)
56 markup["template"] = template
57 markups_out.append(markup)
58
59 return markups_out

Callers 1

parse_paragraph_textMethod · 0.85

Calls 4

raw_renderFunction · 0.85
appendMethod · 0.80
getMethod · 0.45
renderMethod · 0.45

Tested by

no test coverage detected