Skip to content

Commit

Permalink
Add region sections to format-links precommit (#14818)
Browse files Browse the repository at this point in the history
* Add region sections to format-links precommit

The precommit was moving links inside the `site-region` sections to the
end of the document, causing them to break. This alters that behavior
to mimic links that are in tabs or `programming-lang` sections.

* Updating

* remove whitespace

* backing out formatting changes
  • Loading branch information
hestonhoffman authored Aug 11, 2022
1 parent 14839d5 commit 291653b
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions local/bin/py/build/actions/format_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ def prepare_file(file):
main_section.append(line)
if (re.search(r"{{< tabs >}}", line.strip()) or re.search(r"{{< programming-lang-wrapper", line.strip())):
state = 'tabs'
if re.search(r"{{< site-region", line.strip()):
state = 'region'
elif state == 'region':
if re.search(r"{{< /site-region >}}", line.strip()):
main_section.append(line)
sub_sections.append(temp_section)
temp_section = []
state = 'main'
else:
temp_section.append(line)
elif state == 'tabs':
main_section.append(line)
if (re.search(r"{{% tab ", line.strip()) or re.search(r"{{< programming-lang ", line.strip())):
Expand All @@ -46,8 +56,7 @@ def prepare_file(file):
sub_sections.append(temp_section)
temp_section = []
else:
temp_section.append(line)

temp_section.append(line)
if state != 'main':
raise ValueError

Expand Down Expand Up @@ -326,12 +335,17 @@ def inline_section(file_prepared):

end_section_pattern = r"\s*{{% /tab %}}.*"
end_lang_section_pattern = r"\s*{{< /programming-lang >}}.*"
end_region_section_pattern = r"\s*{{< /site-region >}}.*"

i = 1

try:
for line in file_prepared[0]:
if (re.match(end_section_pattern, line) or re.match(end_lang_section_pattern, line)):
if (
re.match(end_section_pattern, line) or
re.match(end_lang_section_pattern, line) or
re.match(end_region_section_pattern, line)
):
final_text += file_prepared[i]
i += 1
final_text.append(line)
Expand Down

0 comments on commit 291653b

Please sign in to comment.