create redacted pdf version
This commit is contained in:
parent
f7ae8705d0
commit
f5e639f59c
2 changed files with 65 additions and 5 deletions
16
Makefile
16
Makefile
|
@ -21,7 +21,7 @@ pdfFilesInt := $(call suffixSubst,$(mdFiles),md,pdf,$(suffixInt))
|
|||
texFilesInt := $(call suffixSubst,$(mdFiles),md,tex,$(suffixInt))
|
||||
|
||||
.PHONY: all pdf pdfPub pdfInt tex texPub texInt
|
||||
all: pdfPub
|
||||
all: pdf
|
||||
|
||||
pdf: pdfPub pdfInt
|
||||
pdfPub: $(pdfFilesPub)
|
||||
|
@ -47,8 +47,14 @@ compile = pandoc \
|
|||
--variable lang:de-DE \
|
||||
--output $(2)
|
||||
|
||||
%.pdf: %.md lenaisten-defs.sty
|
||||
$(call compile,$<,$@)
|
||||
%$(suffixPub).pdf: %.md lenaisten-defs.sty
|
||||
python3 ./redact.py $< | $(call compile,-,$@)
|
||||
|
||||
%.tex: %.md lenaisten-defs.sty
|
||||
$(call compile,$<,$@)
|
||||
%$(suffixPub).tex: %.md lenaisten-defs.sty
|
||||
python3 ./redact.py $< | $(call compile,-,$@)
|
||||
|
||||
%$(suffixInt).pdf: %.md lenaisten-defs.sty
|
||||
python3 ./redact.py -i $< | $(call compile,-,$@)
|
||||
|
||||
%$(suffixInt).tex: %.md lenaisten-defs.sty
|
||||
python3 ./redact.py -i $< | $(call compile,-,$@)
|
||||
|
|
54
redact.py
Normal file
54
redact.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# parse CLI arguments
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("file", help="File to open")
|
||||
parser.add_argument("-i", "--internal", help="Output internal version", action="store_true")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
# read file
|
||||
from pathlib import Path
|
||||
txt = Path(args.file).read_text()
|
||||
|
||||
# redaction syntax
|
||||
import re
|
||||
inlinepat = re.compile(r"\(\(\((([^>]*?):::)?(.*?)\)\)\)", re.MULTILINE|re.DOTALL)
|
||||
tokenpat = re.compile(r"\[redact(:::(.*?))?\](.*?)\[\/redact\]", re.MULTILINE|re.DOTALL)
|
||||
|
||||
# match handling
|
||||
def subredact(match):
|
||||
_, reason, content = match.groups()
|
||||
|
||||
if reason:
|
||||
reason = reason.strip()
|
||||
else:
|
||||
reason = ""
|
||||
|
||||
if args.internal:
|
||||
retval = content.lstrip(" ").rstrip()
|
||||
# retval = re.sub(r"(\s*[+\-\*]\s+)?(.*)", r"\1*\2*", retval, re.MULTILINE)
|
||||
|
||||
retval = f"*{retval}*"
|
||||
retval = re.sub(r"\n(\s*[+\-\*]\s+)?", r"*\n\1*", retval, re.MULTILINE)
|
||||
|
||||
else:
|
||||
retval = reason + " [intern]"
|
||||
|
||||
# DEBUG output
|
||||
# print("GROUPS", match.groups())
|
||||
# print("REASON", reason.strip())
|
||||
# print("CONTENT", content.strip())
|
||||
# print("RET", retval)
|
||||
# print("~~~~~~")
|
||||
|
||||
return retval
|
||||
|
||||
# matching
|
||||
txt = tokenpat.sub(subredact, txt)
|
||||
txt = inlinepat.sub(subredact, txt)
|
||||
|
||||
# pipe to stdout
|
||||
print(txt)
|
Loading…
Reference in a new issue