1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
"""
This enables -L, --language and -W for docbook output.
Additionally the magic word IMAGENAME will contain the imagename instead of "IMAGE:imagename"
Example:
mw-render -w docbook -L de -W debug=True;imagesrcresolver=/home/images/IMAGENAME
The content of writer() belongs to the mwlib.
"""
from mwlib.docbookwriter import *
def writer(env, output, status_callback, **args): # changed
""" This is the function for external use. It is called by apps.render """
if status_callback:
buildbook_status = status_callback.getSubRange(0, 50)
else:
buildbook_status = None
book = writerbase.build_book(env, status_callback=buildbook_status)
scb = lambda status, progress : status_callback is not None and status_callback(status=status, progress=progress)
scb(status='preprocessing', progress=50)
for c in book.children:
preprocess(c)
scb(status='rendering', progress=60)
args["language"] = args["lang"] # changed
del args["lang"] # changed
mwlib.docbookwriter.DocBookWriter(env, status_callback=scb, documenttype="book", **args).writeBook(book, output=output) # changed
def setupWriter():
mwlib.docbookwriter.writer = writer
mwlib.docbookwriter.writer.options = \
["documenttype","lang","imagesrcresolver","debug"]
import mwlib.docbookwriter
class MyDocBookWriter(mwlib.docbookwriter.DocBookWriter):
def dbwriteImageLink(self, obj):
if obj.target:
name = obj.target
obj.target = name[name.find(":") + 1:]
return super(MyDocBookWriter,self).dbwriteImageLink(obj)
def setupDocBookWriter():
mwlib.docbookwriter.DocBookWriter = MyDocBookWriter
def apply():
setupWriter()
setupDocBookWriter()
|