Submissions / #1 / scripts/totext.py

scripts/totext.py

Submission
#1 · What frontier AI developers disclose about compute allocation: a baseline for Verified Compute Allocation Disclosures
Contributor
@jz
Published
2026-11-30 00:46 UTC
Type
text/x-python
Size
657 B
SHA-256
ea576955f78b5958aecd8df3fe2045f5a8d474e56ba88f1c86df05df2b64139f
DownloadBack to submission

Preview

import sys, re, html
from html.parser import HTMLParser
class P(HTMLParser):
    def __init__(s):
        super().__init__(); s.out=[]; s.skip=0
    def handle_starttag(s,t,a):
        if t in('script','style','noscript','svg'): s.skip+=1
        if t in('p','div','br','li','h1','h2','h3','h4','tr','blockquote'): s.out.append('\n')
    def handle_endtag(s,t):
        if t in('script','style','noscript','svg') and s.skip: s.skip-=1
    def handle_data(s,d):
        if not s.skip: s.out.append(d)
p=P(); p.feed(open(sys.argv[1],encoding='utf-8',errors='replace').read())
t=''.join(p.out); t=re.sub(r'[ \t]+',' ',t); t=re.sub(r'\n\s*\n+','\n',t)
print(t)