-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy pathhooks.py
More file actions
27 lines (21 loc) · 839 Bytes
/
hooks.py
File metadata and controls
27 lines (21 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import re
def on_page_markdown(markdown, **kwargs):
pattern = re.compile(
r"```metrics\n(.*?)\n```",
re.DOTALL
)
metrics_root_url = "https://prometheus.io/docs/concepts/metric_types/"
def replace_with_admonition(match):
content = match.group(1)
# Parse the HELP and TYPE lines
metric_pattern = r'# HELP (\w+) (.*)\n# TYPE \1 (\w+)'
metrics = re.findall(metric_pattern, content)
admonitions = []
for name, help_text, metric_type in metrics:
block = (
f'???+ info "**`{name}`**: [`{metric_type}`]({metrics_root_url}#{metric_type})"\n'
f' {help_text.strip()}\n'
)
admonitions.append(block)
return "\n".join(admonitions)
return pattern.sub(replace_with_admonition, markdown)