aboutsummaryrefslogtreecommitdiff
path: root/deskutils/bookworm/files/patch-data_scripts_mobi__lib_mobi__html.py
blob: e02d8e2fcfcef7f1c9f5e63e1a184906288f3d07 (plain) (blame)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
--- data/scripts/mobi_lib/mobi_html.py.orig	2021-08-16 04:19:38 UTC
+++ data/scripts/mobi_lib/mobi_html.py
@@ -23,7 +23,7 @@ class HTMLProcessor:
     def findAnchors(self, rawtext, indx_data, positionMap):
         # process the raw text
         # find anchors...
-        print "Find link anchors"
+        print("Find link anchors")
         link_pattern = re.compile(r'''<[^<>]+filepos=['"]{0,1}(\d+)[^<>]*>''', re.IGNORECASE)
         # TEST NCX: merge in filepos from indx
         pos_links = [int(m.group(1)) for m in link_pattern.finditer(rawtext)]
@@ -38,7 +38,7 @@ class HTMLProcessor:
                 positionMap[position] = '<a id="filepos%d" />' % position
 
         # apply dictionary metadata and anchors
-        print "Insert data into html"
+        print("Insert data into html")
         pos = 0
         lastPos = len(rawtext)
         dataList = []
@@ -63,7 +63,7 @@ class HTMLProcessor:
         metadata = self.metadata
 
         # put in the hrefs
-        print "Insert hrefs into html"
+        print("Insert hrefs into html")
         # Two different regex search and replace routines.
         # Best results are with the second so far IMO (DiapDealer).
 
@@ -73,11 +73,11 @@ class HTMLProcessor:
         srctext = link_pattern.sub(r'''<a href="#filepos\1"\2>''', srctext)
 
         # remove empty anchors
-        print "Remove empty anchors from html"
+        print("Remove empty anchors from html")
         srctext = re.sub(r"<a/>",r"", srctext)
 
         # convert image references
-        print "Insert image references into html"
+        print("Insert image references into html")
         # split string into image tag pieces and other pieces
         image_pattern = re.compile(r'''(<img.*?>)''', re.IGNORECASE)
         image_index_pattern = re.compile(r'''recindex=['"]{0,1}([0-9]+)['"]{0,1}''', re.IGNORECASE)
@@ -91,7 +91,7 @@ class HTMLProcessor:
                 imageNumber = int(m.group(1))
                 imageName = imgnames[imageNumber-1]
                 if imageName is None:
-                    print "Error: Referenced image %s was not recognized as a valid image" % imageNumber
+                    print("Error: Referenced image %s was not recognized as a valid image" % imageNumber)
                 else:
                     replacement = 'src="images/' + imageName + '"'
                     tag = re.sub(image_index_pattern, replacement, tag, 1)
@@ -128,7 +128,7 @@ class XHTMLK8Processor:
         posfid_index_pattern = re.compile(r'''['"]kindle:pos:fid:([0-9|A-V]+):off:([0-9|A-V]+).*?["']''')
 
         parts = []
-        print "Building proper xhtml for each file"
+        print("Building proper xhtml for each file")
         for i in xrange(self.k8proc.getNumberOfParts()):
             part = self.k8proc.getPart(i)
             [partnum, dir, filename, beg, end, aidtext] = self.k8proc.getPartInfo(i)
@@ -227,7 +227,7 @@ class XHTMLK8Processor:
                             self.used[imageName] = 'used'
                             tag = re.sub(img_index_pattern, replacement, tag, 1)
                         else:
-                            print "Error: Referenced image %s was not recognized as a valid image in %s" % (imageNumber, tag)
+                            print("Error: Referenced image %s was not recognized as a valid image in %s" % (imageNumber, tag))
                     srcpieces[j] = tag
             flowpart = "".join(srcpieces)
 
@@ -246,13 +246,13 @@ class XHTMLK8Processor:
                         self.used[imageName] = 'used'
                         tag = re.sub(url_img_index_pattern, replacement, tag, 1)
                     else:
-                        print "Error: Referenced image %s was not recognized as a valid image in %s" % (imageNumber, tag)
+                        print("Error: Referenced image %s was not recognized as a valid image in %s" % (imageNumber, tag))
                 # process links to fonts
                 for m in re.finditer(font_index_pattern, tag):
                     fontNumber = fromBase32(m.group(1))
                     fontName = self.imgnames[fontNumber-1]
                     if fontName is None:
-                        print "Error: Referenced font %s was not recognized as a valid font in %s" % (fontNumber, tag)
+                        print("Error: Referenced font %s was not recognized as a valid font in %s" % (fontNumber, tag))
                     else:
                         replacement = '"../Fonts/' + fontName + '"'
                         tag = re.sub(font_index_pattern, replacement, tag, 1)
@@ -345,7 +345,7 @@ class XHTMLK8Processor:
                             self.used[imageName] = 'used'
                             tag = re.sub(img_index_pattern, replacement, tag, 1)
                         else:
-                            print "Error: Referenced image %s was not recognized as a valid image in %s" % (imageNumber, tag)
+                            print("Error: Referenced image %s was not recognized as a valid image in %s" % (imageNumber, tag))
                     srcpieces[j] = tag
             part = "".join(srcpieces)
             # store away modified version