Skip to content

Commit 6591990

Browse files
committed
postprocessing alignment
1 parent ac7f9dd commit 6591990

2 files changed

Lines changed: 40 additions & 31 deletions

File tree

include/gl/graph.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ struct to_impl;
103103
/// ```
104104
///
105105
/// ### References
106-
/// For a general overview and integration instructions, see the [Project Overview](/#overview)
107-
/// or the [Installation Guide](/#installing-the-library).
108-
/// A simple reference [MAIN PAGE](/)
106+
/// For a general overview and integration instructions, see the [Project Overview](README.md#overview)
107+
/// or the [Installation Guide](README.md#installing-the-library).
108+
/// A simple reference [MAIN PAGE](README.md)
109109
///
110110
/// > [!WARNING]
111111
/// > This class relies on its internal implementation tag to correctly define its layout. Modifying

scripts/postprocess_doxyhtml.py

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from typing import Optional
66
from bs4 import BeautifulSoup
77

8+
ImgRules = list[dict]
9+
810

911
def encode_md_link(path_str: str) -> str:
1012
"""
@@ -72,49 +74,56 @@ def process_gfm(content: str) -> str:
7274
return content
7375

7476

75-
# def remove_mainpage_title(content: str, filename: str) -> str:
76-
# if filename != "index.html":
77-
# return content
77+
def process_heading_code_blocks(content: str) -> str:
78+
content = content.replace("&lt;tt&gt;", "<code>")
79+
content = content.replace("&lt;/tt&gt;", "</code>")
80+
return content
81+
7882

79-
# soup = BeautifulSoup(content, 'html.parser')
80-
# header_div = soup.find("div", class_="header")
81-
# if header_div:
82-
# header_div.decompose()
83-
# return str(soup)
83+
def remove_mainpage_title(content: str, filename: str) -> str:
84+
if filename != "index.html":
85+
return content
8486

87+
return re.sub(r'<div class="header">\s*<div class="headertitle">.*?</div>\s*</div>', '', content, flags=re.DOTALL)
8588

86-
# ImgRules = list[dict]
8789

88-
# def process_images(content: str, html_path: Path, rules: ImgRules) -> str:
89-
# soup = BeautifulSoup(content, 'html.parser')
90+
def process_images(content: str, html_path: Path, rules: list[dict]) -> str:
91+
def replacer(match):
92+
img_tag = match.group(0)
93+
src = match.group(1)
94+
filename = Path(src).name
95+
96+
# Skip external or missing files
97+
if src.startswith(('http', 'data:')) or not (html_path.parent / filename).exists():
98+
return img_tag
9099

91-
# for img in soup.find_all('img'):
92-
# src = img.get('src')
93-
# if not src:
94-
# continue
100+
# Fix the src path
101+
img_tag = img_tag.replace(f'src="{src}"', f'src="{filename}"')
95102

96-
# if src.startswith(('http://', 'https://', 'data:')):
97-
# continue
103+
# Apply style rules
104+
for rule in rules:
105+
if rule.get("filename") == filename or f'alt="{rule.get("alt")}"' in img_tag:
106+
style = rule.get("style", "").strip('; ')
98107

99-
# filename = Path(src).name
100-
# if (html_path.parent / filename).exists():
101-
# img['src'] = filename # Align the file path
108+
if 'style="' in img_tag: # Append to existing style
109+
img_tag = re.sub(r'style="([^"]*)"', lambda m: f'style="{m.group(1).strip("; ")}; {style}"', img_tag)
110+
else: # Inject new style
111+
img_tag = img_tag.replace('/>', f' style="{style}" />').replace('">', f' style="{style}">')
102112

103-
# alt = img.get('alt', '')
104-
# for rule in rules: # Apply image style rules
105-
# if ("filaneme" in rule and filename == rule["filename"]) or ("alt" in rule and alt == rule["alt"]):
106-
# img['style'] = f"{img.get('style', '')}; {rule.get('style', '')}".strip('; ')
113+
return img_tag
107114

108-
# return str(soup)
115+
# Match <img> tags and capture their src attribute
116+
return re.sub(r'<img[^>]*src="([^"]+)"[^>]*>', replacer, content, flags=re.IGNORECASE)
109117

110118

111119
def process_file(f: Path, img_rules: Optional[ImgRules] = None):
112120
content = f.read_text(encoding='utf-8')
113121
content = process_md_refs(content)
114122
content = process_gfm(content)
115-
# content = remove_mainpage_title(content, f.name)
116-
# if img_rules:
117-
# content = process_images(content, f, img_rules)
123+
content = process_heading_code_blocks(content)
124+
content = remove_mainpage_title(content, f.name)
125+
if img_rules:
126+
content = process_images(content, f, img_rules)
118127

119128
f.write_text(content, encoding='utf-8')
120129

0 commit comments

Comments
 (0)