mirror of
https://gitlab.com/octtspacc/OcttKB
synced 2025-01-24 03:31:05 +01:00
36 lines
991 B
Python
36 lines
991 B
Python
#!/usr/bin/env python3
|
|
from base64 import b64encode
|
|
from bs4 import BeautifulSoup
|
|
from re import sub
|
|
from sys import argv
|
|
|
|
File = argv[-1]
|
|
B64Prefix = 'data:text/html;base64,'
|
|
|
|
def b64encodeStr(Data):
|
|
return b64encode(Data.encode()).decode()
|
|
|
|
def MkHtml(Content:str):
|
|
return f'''\
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<body>{Content}</body>
|
|
</html>
|
|
'''
|
|
|
|
def Fix1(m):
|
|
return f'<details><a name="{m.group(1)}"></a><summary>{m.group(2)}</summary>'
|
|
|
|
def SafeIframe(m):
|
|
SrcData = m.group(2)
|
|
SrcData = b64encodeStr(MkHtml(f'<a href="{SrcData}">Click to load: {SrcData}</a>'))
|
|
return f'<iframe {m.group(1)} src="{B64Prefix}{SrcData}"></iframe>'
|
|
|
|
Html = str(BeautifulSoup(open(File, 'r'), 'html5lib'))
|
|
|
|
Html = sub('<details><a name="(.+)"><summary>(.+)<\/summary>\s*<\/a>', Fix1, Html)
|
|
Html = sub('<iframe( +)src="(.+)"><\/iframe>', SafeIframe, Html)
|
|
Html = sub('<iframe (.+) src="(.+)"><\/iframe>', SafeIframe, Html)
|
|
|
|
open(File, 'w').write(Html)
|