x Input: Sie können direkt auf die Variablen value (der Wert des tags) und source (das XML-
Dokument) zugreifen.
x Output: Der Wert der Variablen out wird in die Zieldatei kopiert
-
+- mDoc-spezifische Tags (Docbook-Erweiterung)
+ x <line>: Einzelne Zeilen innerhalb eines Paragraphen
+ x <item>: Definition von Testbausteinen, wenn im Paragraphen auch Hervorhebungs-Tags (wie
+ <emphasis>) vorkommen.
+
--- /dev/null
+'''
+Created on 26.03.2021
+
+@author: antix19
+'''
+from mutil.XmlExtractor import XmlExtractor
+from mutil import XmlExtractor as XMLE
+from pickle import NONE, FALSE, TRUE
+
+def eval_class(classs, item):
+ item_hira = item.split(".")
+ ilen = len(item_hira)
+ class_hira = classs.split(".")
+ if len(class_hira) < len(item_hira):
+ return False,ilen
+ for i in range(len(item_hira)):
+ if item_hira[i] != class_hira[i]:
+ return False,ilen
+ return True,ilen
+
+def is_for_print(classs, attrs):
+ include = False
+ exclude = False
+ ilen = 0
+ elen = 0
+ if "include" in attrs:
+ include,ilen = eval_class(classs, attrs["include"])
+ if "exclude" in attrs:
+ exclude,elen = eval_class(classs, attrs["exclude"])
+ if ilen > 0 and elen == 0:
+ return include
+ elif elen > 0 and ilen == 0:
+ return not exclude
+ elif ilen > 0 and elen > 0:
+ if ilen > elen:
+ if include:
+ return True
+ else:
+ return not exclude
+ elif elen > ilen:
+ if exclude:
+ return False
+ else:
+ return include
+ return True
+
+
+def extract(file, classs, target):
+ source = XmlExtractor()
+ source.openInput(file)
+
+ # open output file
+ out_file = open(target, "w")
+
+ source.requireChild("document")
+ (ctl,elem, value, attrs) = source.extractElement(XMLE.EC_BEG)
+ while ctl != XMLE.EC_END:
+ if elem != "text":
+ raise EnvironmentError("<text> node expected")
+ if is_for_print(classs, attrs):
+ out_file.write(value+"\n")
+ (ctl,elem, value, attrs) = source.extractElement(ctl)
+ return 0
+
+
\ No newline at end of file
--- /dev/null
+#!/usr/bin/python3
+'''
+Created on 26.03.2021
+
+@author: antix19
+'''
+import sys
+from mdoc import extractor
+import re
+
+usage = 'mdoc-extract <source> <class>'
+
+def command_dispatch(args):
+
+ # check runtime parameters
+ if len(args) < 2:
+ raise RuntimeError("mdoc-extract needs 2 arguments.")
+
+ file = args[0]
+ classs = args[1]
+ target = re.sub(r'\..*', '.tex', file)
+
+ return extractor.extract(file, classs, target)
+
+
+# evaulate runtime parameters
+if __name__ == '__main__':
+ try:
+ ret = command_dispatch(sys.argv[1:])
+ if ret != 0:
+ print ("Operation returned: "+str(ret))
+ exit (ret)
+ except Exception as e:
+ print (e)
+ print (usage)
+ raise
\ No newline at end of file