mirror of
https://github.com/enzet/map-machine.git
synced 2025-06-14 00:31:52 +02:00
Fix wiki page rewriting.
This commit is contained in:
parent
67c9b095d0
commit
05b9d39e21
1 changed files with 23 additions and 4 deletions
|
@ -150,11 +150,32 @@ def generate_new_text(
|
||||||
|
|
||||||
lines: list[str] = old_text.split("\n")
|
lines: list[str] = old_text.split("\n")
|
||||||
|
|
||||||
|
# If rendering section already exists.
|
||||||
|
|
||||||
start: Optional[int] = None
|
start: Optional[int] = None
|
||||||
end: int = -1
|
end: int = -1
|
||||||
|
|
||||||
|
for index, line in enumerate(lines):
|
||||||
|
if HEADER_PATTERN.match(line):
|
||||||
|
if start is not None:
|
||||||
|
end = index
|
||||||
|
break
|
||||||
|
if RENDERING_HEADER_PATTERN.match(line):
|
||||||
|
start = index
|
||||||
|
|
||||||
|
if start is not None:
|
||||||
|
return (
|
||||||
|
"\n".join(lines[:end])
|
||||||
|
+ "\n=== [[Röntgen]] icons in [[Map Machine]] ===\n"
|
||||||
|
+ f"\n{wiki_text}\n"
|
||||||
|
+ "\n".join(lines[end:])
|
||||||
|
), icons
|
||||||
|
|
||||||
# If Röntgen rendering section already exists.
|
# If Röntgen rendering section already exists.
|
||||||
|
|
||||||
|
start: Optional[int] = None
|
||||||
|
end: int = -1
|
||||||
|
|
||||||
for index, line in enumerate(lines):
|
for index, line in enumerate(lines):
|
||||||
if HEADER_PATTERN.match(line):
|
if HEADER_PATTERN.match(line):
|
||||||
if start is not None:
|
if start is not None:
|
||||||
|
@ -166,15 +187,13 @@ def generate_new_text(
|
||||||
if start is not None:
|
if start is not None:
|
||||||
return (
|
return (
|
||||||
"\n".join(lines[: start + 2])
|
"\n".join(lines[: start + 2])
|
||||||
+ "\n"
|
+ f"\n{wiki_text}\n"
|
||||||
+ wiki_text
|
|
||||||
+ "\n"
|
|
||||||
+ "\n".join(lines[end:])
|
+ "\n".join(lines[end:])
|
||||||
), icons
|
), icons
|
||||||
|
|
||||||
# Otherwise.
|
# Otherwise.
|
||||||
|
|
||||||
headers = [None, None]
|
headers: list[Optional[int]] = [None, None]
|
||||||
|
|
||||||
for index, line in enumerate(lines):
|
for index, line in enumerate(lines):
|
||||||
for i, pattern in enumerate(HEADER_PATTERNS):
|
for i, pattern in enumerate(HEADER_PATTERNS):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue