Tutoriels/Installation et utilisation.../preprocess.py

25 lines
642 B
Python
Executable File

#! /usr/bin/env python3
import sys
import re
import os
base_url = "https://gitea.planet-casio.com/Lephenixnoir/Tutoriels/raw/branch" \
"/master/mumble/"
if len(sys.argv) > 1:
print("warning: this script takes no arguments -- ignoring",
file=sys.stderr)
with open("utilisation-mumble.txt", "r") as fp:
t = fp.read()
t = re.sub(r'^#[^\n]*[\n]+', "", t, count=1)
def one(m):
if not os.path.exists(m[1]):
print("warning: file", m[1], "does not exist", file=sys.stderr)
return "[img]" + base_url + m[1] + "[/img]"
t = re.sub(r'\[img\]([^[:]+)\[/img\]', one, t)
print(t)