#!/usr/bin/env python3 import urllib.request import re import minify_html zig_version = 'master' def fix_ul(s): l = s.split('
{#syntax#}(.+?){#endsyntax#}', blk, re.M | re.S)[1].replace('\n ', '').replace('"', '\\"') snippet = name if f'{name}()' in signature: params = None snippet += '()' else: params = [] i = signature.index('(') + 1 level = 1 j = i while i < len(signature): if signature[i] == '(': level += 1 elif signature[i] == ')': level -= 1 if signature[i] == ',' and level == 1: params.append(signature[j:i]) j = i + 2 if level == 0: break i += 1 params.append(signature[j:i]) snippet += '(${' i = 1 for param in params: snippet += f'{i}:{param}}}, ${{' i += 1 snippet = snippet[:-4] + ')' docs = re.sub(r'{#see_also\|[^#]+#}', '', blk) docs = re.sub( r' {#code_begin\|(obj|syntax|(test(\|(call|truncate))?))#}\n', '
{#syntax#}', docs) docs = re.sub( r' {#code_begin\|test_(err|safety)\|[^#]+#}\n', '', '{#endsyntax#}') docs = minify_html.minify(docs) prefix = '{#syntax#}', docs) docs = docs.replace(' {#code_release_fast#}\n', '') docs = docs.replace(' {#code_end#}', '{#endsyntax#}') docs = docs.replace('\n{#endsyntax#}
' docs = docs[docs.index(prefix)+len(prefix):] docs = docs.replace('
', '\n\n') docs = re.sub(r'{#(end)?syntax#}', '`', docs) # @cDefine docs = re.sub(r'
]+>([^<]+)
', '`\\1`', docs)
docs = re.sub(r'?code>', '`', docs)
docs = docs.replace('`', '\n\n```zig\n') docs = docs.replace('`', '\n```') # @setFloatMode docs = docs.replace('```<', '```\n<') # @TypeOf docs = re.sub(r'?em>', '*', docs) docs = re.sub(r']+)>([^<]+)', '[\\2](\\1)', docs) docs = re.sub(r'{#link\|([^|#]+)\|([^|#]+)#}', lambda m: f'[{m[1]}](https://ziglang.org/documentation/{zig_version}/#{m[2].replace(" ","-")})', docs) docs = re.sub( r'{#link\|([^|#]+)#}', lambda m: f'[{m[1]}](https://ziglang.org/documentation/{zig_version}/#{m[1].replace(" ","-").replace("@","")})', docs) docs = re.sub(r'