diff --git a/.gitignore b/.gitignore index f96ff51..836dee1 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,10 @@ instance/ *.pylint.d/ *.pydist/ *.pytest_cache/ +*.cache/ +*.coverage.* +*.bak +*.tmp +*.swp +*.swo +*.swn \ No newline at end of file diff --git a/app.py b/app.py index 1e724b4..cee5f45 100644 --- a/app.py +++ b/app.py @@ -516,7 +516,8 @@ def process_template(text): # --- Section Heading Handler --- def process_section_heading(text): """ - Processes section headings like ==Title== and wraps the heading text in tags. + Processes section headings like ==Title== and wraps the entire heading in tags, + with the tags on their own lines per MediaWiki translation guidelines. """ # Match ==Title==, ===Subsection===, etc. match = re.match(r'^(=+)([^=]+)(=+)$', text.strip()) @@ -524,8 +525,8 @@ def process_section_heading(text): return text level = match.group(1) heading_text = match.group(2).strip() - # Reconstruct with same number of = on both sides - return f'{level}{heading_text}{level}' + # Wrap the entire heading (including == markers) in tags on their own lines + return f'\n{level}{heading_text}{level}\n' def process_raw_url(text): """ diff --git a/tests.py b/tests.py index 207f384..3c263fa 100644 --- a/tests.py +++ b/tests.py @@ -6,7 +6,19 @@ class TestTranslatableWikitext(unittest.TestCase): def test_section_headers(self): self.assertEqual( convert_to_translatable_wikitext("==HELLO=="), - "==HELLO==" # Removed the \n\n that was expected + "\n==HELLO==\n" + ) + + def test_section_heading_strips_spaces(self): + self.assertEqual( + convert_to_translatable_wikitext("== Example =="), + "\n==Example==\n" + ) + + 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"), + "\n==Example==\n\n\nlorem ipsum\n\n\n===Second example===\n\n\nlorem ipsum" ) def test_file_tag_translations(self):