@@ -38,19 +38,67 @@ def pprint(x):
3838 box-sizing: border-box;
3939}
4040
41- body {
42- width: 700pt;
41+ @page {
42+ size: A4;
43+ margin: 2cm;
4344}
4445
46+ div.window {
47+ display: flex;
48+ flex-flow: row nowrap;
49+ justify-content: flex-start;
50+ align-items: flex-start;
51+ min-width: 1000pt;
52+ height: 99vh;
53+ }
54+ div.sidebar {
55+ flex: 1 1 300pt;
56+ display: flex;
57+ flex-flow: row nowrap;
58+ border-right: 1pt solid var(--fog-rim);
59+ padding-left: 8px;
60+ padding-right: 12px;
61+ height: 99vh;
62+ overflow: auto;
63+ -webkit-overflow-scrolling: touch;
64+ }
65+ div.toc {
66+ flex: 1 1 50pt;
67+ }
68+ div.pages {
69+ flex: 0 0 700pt;
70+ }
71+ div.pages.bypage {
72+ height: 99vh;
73+ overflow: auto;
74+ -webkit-overflow-scrolling: touch;
75+ }
76+ div.page {
77+ margin-right: 1cm;
78+ padding-left: 0.5cm;
79+ max-width: 600pt;
80+ min-width: 600pt;
81+ width: 600pt;
82+ }
83+ div.phead {
84+ color: #777777;
85+ font-size: small;
86+ text-align: right;
87+ width: 1cm;
88+ margin-right: -1cm;
89+ float: right;
90+ }
91+
92+
4593.r {
4694 font-family: normal, sans-serif;
47- font-size: xx -large;
95+ font-size: x -large;
4896 direction: rtl;
4997 unicode-bidi: isolate-override;
5098}
5199.rc, .lc {
52100 font-family: normal, sans-serif;
53- font-size: xx -large;
101+ font-size: x -large;
54102 background-color: white;
55103 border: 2pt solid #ffcccc;
56104}
@@ -74,7 +122,7 @@ def pprint(x):
74122}
75123.l {
76124 font-family: normal, sans-serif;
77- font-size: xx -large;
125+ font-size: x -large;
78126 direction: ltr;
79127 unicode-bidi: isolate-override;
80128}
@@ -93,7 +141,7 @@ def pprint(x):
93141 unicode-bidi: isolate-override;
94142}
95143.lrg {
96- font-size: xx -large;
144+ font-size: x -large;
97145 font-weight: bold;
98146}
99147span.sp {
@@ -171,9 +219,50 @@ def pprint(x):
171219 min-width: 20%;
172220 width: 20%;
173221}
222+ :root {
223+ --fog-rim: hsla( 0, 0%, 60%, 0.5 );
224+ }
174225</style>
175226"""
176227
228+ POST_HTML = """
229+ </body>
230+ </html>
231+ """
232+
233+
234+ def preHtml (pageNum ):
235+ return f"""\
236+ <html>
237+ <head>
238+ <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
239+ <meta charset="utf-8"/>
240+ <title>Lakhnawi { pageNum } </title>
241+ { CSS }
242+ </head>
243+ <body>
244+ """
245+
246+
247+ def getToc (pageNums ):
248+ limit = 60
249+
250+ html = []
251+ html .append ("""<div class="toc">""" )
252+ j = 0
253+
254+ for (i , pageNum ) in enumerate (pageNums ):
255+ if j == limit :
256+ j = 0
257+ html .append ("""</div>\n <div class="toc">""" )
258+ html .append (f"""<a href="#p{ pageNum :>03} ">p { pageNum } </a><br>""" )
259+ j += 1
260+
261+ html .append ("""</div>""" )
262+
263+ return "\n " .join (html )
264+
265+
177266PUA_RANGES = (("e000" , "f8ff" ),)
178267
179268LATIN_PRESENTATIONAL_RANGES = (("00c0" , "024f" ), ("1e00" , "1eff" ), ("fb00" , "fb06" ))
@@ -616,24 +705,6 @@ def parseNums(numSpec):
616705 )
617706
618707
619- def preHtml (pageNum ):
620- return f"""\
621- <html>
622- <head>
623- <meta charset="utf-8"/>
624- <title>Lakhnawi p. { pageNum } </title>
625- { CSS }
626- </head>
627- <body>
628- """
629-
630-
631- POST_HTML = """
632- </body>
633- </html>
634- """
635-
636-
637708U_LINE_RE = re .compile (r"""^U\+([0-9a-f]{4})([0-9a-f ]*)$""" , re .I )
638709HEX_RE = re .compile (r"""^[0-9a-f]{4}$""" , re .I )
639710PUA_RE = re .compile (r"""⌊([^⌋]*)⌋""" )
@@ -954,33 +1025,88 @@ def plainPages(self, pageNumSpec):
9541025 for (i , line ) in enumerate (lines ):
9551026 print (self .plainLine (line ))
9561027
957- def htmlPages (self , pageNumSpec , showSpaces = False , export = False ):
1028+ def htmlPages (
1029+ self , pageNumSpec , showSpaces = False , export = False , singleFile = False , toc = False
1030+ ):
9581031 self .showSpaces = showSpaces
959- destDir = f"{ UR_DIR } /{ NAME } /html"
1032+ destDir = f"{ UR_DIR } /{ NAME } " if singleFile else f"{ UR_DIR } /{ NAME } /html"
1033+ pageNums = self .parsePageNums (pageNumSpec )
9601034
961- if not os .path .exists (destDir ):
962- os .makedirs (destDir , exist_ok = True )
1035+ if export :
1036+ if not os .path .exists (destDir ):
1037+ os .makedirs (destDir , exist_ok = True )
1038+ if singleFile :
1039+ pageNumRep = "allpages" if pageNumSpec is None else str (pageNumSpec )
1040+ tocRep = "-with-toc" if toc else ""
1041+ filePath = f"{ destDir } /{ pageNumRep } { tocRep } .html"
1042+ fh = open (filePath , "w" )
1043+ fh .write (preHtml (f"{ pageNumRep } { tocRep } " ))
1044+ if toc :
1045+ toc = getToc (pageNums )
1046+ fh .write (
1047+ f"""
1048+ <div class="window">
1049+ <div class="sidebar">
1050+ { toc }
1051+ </div>
1052+ <div class="pages bypage">
1053+ """
1054+ )
1055+ else :
1056+ fh .write (
1057+ """
1058+ <div class="pages">
1059+ """
1060+ )
9631061
964- for pageNum in self . parsePageNums ( pageNumSpec ) :
1062+ for pageNum in pageNums :
9651063 lines = self .text .get (pageNum , [])
9661064 nLines = len (lines )
9671065
9681066 html = []
1067+ html .append (
1068+ f"""
1069+ <div class="page">
1070+ <div class="phead"><a name="p{ pageNum :>03} ">{ pageNum } </a></div>
1071+ """
1072+ )
9691073
9701074 prevMulti = False
9711075
9721076 for (i , line ) in enumerate (lines ):
9731077 html .append (self .htmlLine (line , prevMulti , i == nLines - 1 ))
9741078 prevMulti = len (line ) > 1
9751079
1080+ html .append ("""</div>""" )
1081+
9761082 if export :
977- html = preHtml (pageNum ) + "" .join (html ) + POST_HTML
978- filePath = f"{ destDir } /p{ pageNum :>03} .html"
979- with open (filePath , "w" ) as fh :
980- fh .write (html )
1083+ htmlRep = "" .join (html )
1084+
1085+ if singleFile :
1086+ fh .write (htmlRep )
1087+ else :
1088+ html = preHtml (pageNum ) + htmlRep + POST_HTML
1089+ filePath = f"{ destDir } /p{ pageNum :>03} .html"
1090+ with open (filePath , "w" ) as fh :
1091+ fh .write (html )
9811092 else :
9821093 display (HTML ("\n " .join (html )))
9831094
1095+ if export and singleFile :
1096+ fh .write (
1097+ """
1098+ </div>
1099+ """
1100+ )
1101+ if toc :
1102+ fh .write (
1103+ """
1104+ </div>
1105+ """
1106+ )
1107+ fh .write (POST_HTML )
1108+ fh .close ()
1109+
9841110 def showLines (
9851111 self ,
9861112 pageNumSpec ,
0 commit comments