Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@ instance/
*.pylint.d/
*.pydist/
*.pytest_cache/
*.cache/
*.coverage.*
*.bak
*.tmp
*.swp
*.swo
*.swn
7 changes: 4 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,16 +516,17 @@ def process_template(text):
# --- Section Heading Handler ---
def process_section_heading(text):
"""
Processes section headings like ==Title== and wraps the heading text in <translate> tags.
Processes section headings like ==Title== and wraps the entire heading in <translate> tags,
with the tags on their own lines per MediaWiki translation guidelines.
"""
# Match ==Title==, ===Subsection===, etc.
match = re.match(r'^(=+)([^=]+)(=+)$', text.strip())
if not match:
return text
level = match.group(1)
heading_text = match.group(2).strip()
# Reconstruct with same number of = on both sides
return f'{level}<translate>{heading_text}</translate>{level}'
# Wrap the entire heading (including == markers) in <translate> tags on their own lines
return f'<translate>\n{level}{heading_text}{level}\n</translate>'

def process_raw_url(text):
"""
Expand Down
14 changes: 13 additions & 1 deletion tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,19 @@ class TestTranslatableWikitext(unittest.TestCase):
def test_section_headers(self):
self.assertEqual(
convert_to_translatable_wikitext("==HELLO=="),
"<translate>==HELLO==</translate>" # Removed the \n\n that was expected
"<translate>\n==HELLO==\n</translate>"
)

def test_section_heading_strips_spaces(self):
self.assertEqual(
convert_to_translatable_wikitext("== Example =="),
"<translate>\n==Example==\n</translate>"
)

def test_section_headings_multiple_levels_with_body(self):
self.assertEqual(
convert_to_translatable_wikitext("== Example ==\n\nlorem ipsum\n\n=== Second example ===\n\nlorem ipsum"),
"<translate>\n==Example==\n</translate>\n\n<translate>lorem ipsum</translate>\n\n<translate>\n===Second example===\n</translate>\n\n<translate>lorem ipsum</translate>"
)

def test_file_tag_translations(self):
Expand Down