Skip to content

Instantly share code, notes, and snippets.

@epicfaace
Created May 20, 2020 15:45
Show Gist options
  • Save epicfaace/23e8dab04bd290659f2db1feccd57891 to your computer and use it in GitHub Desktop.
Save epicfaace/23e8dab04bd290659f2db1feccd57891 to your computer and use it in GitHub Desktop.
apache beam docs script
import fileinput
PATH = "website/www/site/content/en/documentation/programming-guide.md"
seen = []
STATE_DEFAULT = 0
STATE_IN_HIGHLIGHT = 1
STATE_FINISHED_HIGHLIGHT = 2
STATE_AFTER_HIGHLIGHT_NEWLINE = 3
state = STATE_DEFAULT
with fileinput.input(inplace=True, files=(PATH)) as f:
for line in f:
if state == STATE_IN_HIGHLIGHT and "{{< /highlight >}}" in line:
state = STATE_FINISHED_HIGHLIGHT
elif state == STATE_FINISHED_HIGHLIGHT and line.strip() == "":
state = STATE_AFTER_HIGHLIGHT_NEWLINE
elif "{{< highlight" in line:
if "{{< highlight java >}}" in line:
seen.append("java")
elif "{{< highlight py >}}" in line or "{{< highlight python >}}" in line:
seen.append("py")
if "{{< highlight go >}}" in line:
seen.append("go")
state = STATE_IN_HIGHLIGHT
elif state == STATE_AFTER_HIGHLIGHT_NEWLINE and line.strip() != "":
if "py" not in seen:
print("{{< highlight py />}}\n")
if "go" not in seen:
print("{{< highlight go />}}\n")
seen = []
state = STATE_DEFAULT
print(line, end="")
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment