41
41
42
42
jsondatas = common .get_jsondata (True )
43
43
44
- classes = []
44
+ classes = [] # list of class names
45
45
libraries = []
46
46
for jsondata in jsondatas :
47
47
if "class" in jsondata :
68
68
htmlFile = open ('functions.html' , 'w' )
69
69
def html (s ): htmlFile .write (s + "\n " );
70
70
71
- def htmlify (d ):
71
+ def htmlify (d , current ):
72
72
d = markdown .markdown (d , extensions = ['urlize' ])
73
73
# replace <code> with newlines with pre
74
74
idx = d .find ("<code>" )
75
75
end = d .find ("</code>" , idx )
76
76
while idx >= 0 and end > idx :
77
- codeBlock = d [idx :end + 7 ]
77
+ codeBlock = d [idx + 6 :end ]
78
+ # search for known links in code
79
+ if codeBlock [- 2 :]== "()" and codeBlock [:- 2 ] in links :
80
+ codeBlock = "<a href=\" #" + links [codeBlock [:- 2 ]]+ "\" >" + codeBlock + "</a>" ;
81
+ elif codeBlock in links :
82
+ codeBlock = "<a href=\" #" + links [codeBlock ]+ "\" >" + codeBlock + "</a>" ;
83
+ # ensure multi-line code is handled correctly
84
+ codeBlock = "<code>" + codeBlock + "</code>" ;
78
85
if codeBlock .find ("\n " )>= 0 :
79
- d = d [0 :idx ]+ "<pre>" + codeBlock + "</pre>" + d [end + 7 :];
80
- idx = d .find ("<code>" , end + 7 + 5 + 6 )
86
+ codeBlock = "<pre>" + codeBlock + "</pre>"
87
+ d = d [0 :idx ]+ codeBlock + d [end + 7 :];
88
+ # search again
89
+ idx = d .find ("<code>" , end )
81
90
end = d .find ("</code>" , idx )
82
91
return d ;
83
92
84
93
def html_description (d ,current ):
85
94
if isinstance (d , list ): d = "\n " .join (d )
86
- d = htmlify (d )
87
- for link in links :
88
- if link != current :
89
- d = d .replace (" " + link + " " , " <a href=\" #" + links [link ]+ "\" >" + link + "</a> " )
90
- d = d .replace (" " + link + "." , " <a href=\" #" + links [link ]+ "\" >" + link + "</a>." )
91
- d = d .replace (" " + link + "(" , " <a href=\" #" + links [link ]+ "\" >" + link + "</a>(" )
95
+ d = htmlify (d ,current )
92
96
html ("<div class=\" description\" >\n " + d + "\n </div>\n " )
93
97
94
98
def get_prefixed_name (jsondata ):
@@ -241,6 +245,11 @@ def insert_mdn_link(jsondata):
241
245
242
246
detail = []
243
247
links = {}
248
+ def add_link (jsondata ):
249
+ if not "no_create_links" in jsondata :
250
+ link = get_prefixed_name (jsondata );
251
+ if link != "global" :
252
+ links [link ] = get_link (jsondata )
244
253
jsondatas = sorted (jsondatas , key = lambda s : common .get_name_or_space (s ).lower ())
245
254
246
255
html (' <div id="contents">' )
@@ -249,17 +258,13 @@ def insert_mdn_link(jsondata):
249
258
html (" <li><a class=\" blush\" name=\" t__global\" href=\" #_global\" onclick=\" place('_global');\" >Globals</A></li>" )
250
259
for jsondata in jsondatas :
251
260
if "name" in jsondata and not "class" in jsondata :
252
- link = get_link (jsondata )
253
- if not "no_create_links" in jsondata :
254
- links [get_prefixed_name (jsondata )] = link
261
+ add_link (jsondata )
255
262
detail .append (jsondata )
256
263
for className in sorted (classes , key = lambda s : s .lower ()):
257
264
html (" <li><a class=\" blush\" name=\" t_" + className + "\" href=\" #" + className + "\" onclick=\" place('" + className + "');\" >" + className + "</a></li>" )
258
265
for jsondata in jsondatas :
259
266
if "name" in jsondata and "class" in jsondata and jsondata ["class" ]== className :
260
- link = get_link (jsondata )
261
- if not "no_create_links" in jsondata :
262
- links [get_prefixed_name (jsondata )] = link
267
+ add_link (jsondata )
263
268
detail .append (jsondata )
264
269
html (" </ul>" )
265
270
html (' </div><!-- Contents -->' )
@@ -313,7 +318,7 @@ def insert_mdn_link(jsondata):
313
318
html (" </ul>" )
314
319
link = get_link (jsondata )
315
320
html (" <h3 class=\" detail\" ><a class=\" blush\" name=\" " + link + "\" href=\" #t_" + link + "\" onclick=\" place('t_" + link + "','" + linkName + "');\" >" + get_fullname (jsondata )+ "</a>" )
316
- html ("<!-- " + json .dumps (jsondata , sort_keys = True , indent = 2 )+ "-->" );
321
+ # html("<!-- "+json.dumps(jsondata, sort_keys=True, indent=2)+"-->");
317
322
if "githublink" in jsondata :
318
323
html ('<a class="githublink" title="Link to source code on GitHub" href="' + jsondata ["githublink" ]+ '">⇒</a>' );
319
324
html ("</h3>" )
@@ -346,13 +351,13 @@ def insert_mdn_link(jsondata):
346
351
if isinstance (desc , list ): desc = '<br/>' .join (desc )
347
352
extra = ""
348
353
if param [1 ]== "JsVarArray" : extra = ", ..." ;
349
- html (" <div class=\" param\" >" + htmlify ("`" + param [0 ]+ extra + "` - " + desc )+ "</div>" )
354
+ html (" <div class=\" param\" >" + htmlify ("`" + param [0 ]+ extra + "` - " + desc , "" )+ "</div>" )
350
355
if "return" in jsondata :
351
356
html (" <h4>Returns</h4>" )
352
357
desc = ""
353
358
if len (jsondata ["return" ])> 1 : desc = jsondata ["return" ][1 ]
354
359
if desc == "" : desc = "See description above"
355
- html (" <div class=\" return\" >" + htmlify (desc )+ "</div>" )
360
+ html (" <div class=\" return\" >" + htmlify (desc , "" )+ "</div>" )
356
361
357
362
url = "http://www.espruino.com/Reference#" + get_link (jsondata )
358
363
if url in code_uses :
0 commit comments