dc09.ru-old/html_conv.py

27 lines
603 B
Python
Raw Normal View History

2022-10-12 16:07:01 +03:00
#!/usr/bin/env python3
import re
import sys
SCRIPTS = r'((<script src="js/\w+\.js"></script>[\s\r\n]+)+)'
MINJS = '<script src="{}"></script>'
LESSJS = '<script src="https://cdn.jsdelivr.net/npm/less"></script>'
STYLES = '<link rel="stylesheet/less" type="text/css" href="styles.less" />'
CSS = '<link rel="stylesheet" href="{}" />'
def main():
stdin = sys.stdin.read()
conv = re.sub(SCRIPTS, MINJS.format(sys.argv[1]), stdin)
conv = conv.replace(LESSJS, '')
conv = conv.replace(STYLES, CSS.format(sys.argv[2]))
sys.stdout.write(conv)
if __name__ == '__main__':
main()