Skip to content

Commit 3355a5b

Browse files
committed
Now add links when a built-in function is referenced inside backticks
1 parent 6b1b9f5 commit 3355a5b

File tree

3 files changed

+32
-27
lines changed

3 files changed

+32
-27
lines changed

scripts/build_docs.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
jsondatas = common.get_jsondata(True)
4343

44-
classes = []
44+
classes = [] # list of class names
4545
libraries = []
4646
for jsondata in jsondatas:
4747
if "class" in jsondata:
@@ -68,27 +68,31 @@
6868
htmlFile = open('functions.html', 'w')
6969
def html(s): htmlFile.write(s+"\n");
7070

71-
def htmlify(d):
71+
def htmlify(d,current):
7272
d = markdown.markdown(d, extensions=['urlize'])
7373
# replace <code> with newlines with pre
7474
idx = d.find("<code>")
7575
end = d.find("</code>", idx)
7676
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>";
7885
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)
8190
end = d.find("</code>", idx)
8291
return d;
8392

8493
def html_description(d,current):
8594
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)
9296
html("<div class=\"description\">\n" + d + "\n</div>\n")
9397

9498
def get_prefixed_name(jsondata):
@@ -241,6 +245,11 @@ def insert_mdn_link(jsondata):
241245

242246
detail = []
243247
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)
244253
jsondatas = sorted(jsondatas, key=lambda s: common.get_name_or_space(s).lower())
245254

246255
html(' <div id="contents">')
@@ -249,17 +258,13 @@ def insert_mdn_link(jsondata):
249258
html(" <li><a class=\"blush\" name=\"t__global\" href=\"#_global\" onclick=\"place('_global');\">Globals</A></li>")
250259
for jsondata in jsondatas:
251260
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)
255262
detail.append(jsondata)
256263
for className in sorted(classes, key=lambda s: s.lower()):
257264
html(" <li><a class=\"blush\" name=\"t_"+className+"\" href=\"#"+className+"\" onclick=\"place('"+className+"');\">"+className+"</a></li>")
258265
for jsondata in jsondatas:
259266
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)
263268
detail.append(jsondata)
264269
html(" </ul>")
265270
html(' </div><!-- Contents -->')
@@ -313,7 +318,7 @@ def insert_mdn_link(jsondata):
313318
html(" </ul>")
314319
link = get_link(jsondata)
315320
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)+"-->");
317322
if "githublink" in jsondata:
318323
html('<a class="githublink" title="Link to source code on GitHub" href="'+jsondata["githublink"]+'">&rArr;</a>');
319324
html("</h3>")
@@ -346,13 +351,13 @@ def insert_mdn_link(jsondata):
346351
if isinstance(desc, list): desc = '<br/>'.join(desc)
347352
extra = ""
348353
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>")
350355
if "return" in jsondata:
351356
html(" <h4>Returns</h4>")
352357
desc = ""
353358
if len(jsondata["return"])>1: desc=jsondata["return"][1]
354359
if desc=="": desc="See description above"
355-
html(" <div class=\"return\">"+htmlify(desc)+"</div>")
360+
html(" <div class=\"return\">"+htmlify(desc,"")+"</div>")
356361

357362
url = "http://www.espruino.com/Reference#"+get_link(jsondata)
358363
if url in code_uses:

src/jswrap_interactive.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ void jswrap_interface_edit(JsVar *funcName) {
328328
["echoOn","bool",""]
329329
]
330330
}
331-
Should TinyJS echo what you type back to you? true = yes (Default), false = no. When echo is off, the result of executing a command is not returned. Instead, you must use 'print' to send output.
331+
Should Espruino echo what you type back to you? true = yes (Default), false = no. When echo is off, the result of executing a command is not returned. Instead, you must use 'print' to send output.
332332
*/
333333
void jswrap_interface_echo(bool echoOn) {
334334
if (echoOn)
@@ -511,7 +511,7 @@ JsVar *jswrap_interface_setTimeout(JsVar *func, JsVarFloat timeout, JsVar *args)
511511
["id","JsVar","The id returned by a previous call to setInterval"]
512512
]
513513
}
514-
Clear the Interval that was created with setInterval, for example:
514+
Clear the Interval that was created with `setInterval`, for example:
515515
516516
```var id = setInterval(function () { print('foo'); }, 1000);```
517517
@@ -527,7 +527,7 @@ If no argument is supplied, all timers and intervals are stopped
527527
["id","JsVar","The id returned by a previous call to setTimeout"]
528528
]
529529
}
530-
Clear the Timeout that was created with setTimeout, for example:
530+
Clear the Timeout that was created with `setTimeout`, for example:
531531
532532
```var id = setTimeout(function () { print('foo'); }, 1000);```
533533
@@ -584,7 +584,7 @@ void jswrap_interface_clearTimeout(JsVar *idVar) {
584584
["time","float","The new time period in ms"]
585585
]
586586
}
587-
Change the Interval on a callback created with setInterval, for example:
587+
Change the Interval on a callback created with `setInterval`, for example:
588588
589589
```var id = setInterval(function () { print('foo'); }, 1000); // every second```
590590

src/jswrap_serial.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,14 @@ The sixth Serial (USART) port
162162
"name" : "LoopbackA",
163163
"instanceof" : "Serial"
164164
}
165-
A loopback serial device. Data sent to LoopbackA comes out of LoopbackB and vice versa
165+
A loopback serial device. Data sent to `LoopbackA` comes out of `LoopbackB` and vice versa
166166
*/
167167
/*JSON{
168168
"type" : "object",
169169
"name" : "LoopbackB",
170170
"instanceof" : "Serial"
171171
}
172-
A loopback serial device. Data sent to LoopbackA comes out of LoopbackB and vice versa
172+
A loopback serial device. Data sent to `LoopbackA` comes out of `LoopbackB` and vice versa
173173
*/
174174
/*JSON{
175175
"type" : "object",
@@ -245,7 +245,7 @@ pin's value will be 0 when Espruino is ready for data and 1 when it isn't.
245245
By default, framing or parity errors don't create `framing` or `parity` events
246246
on the `Serial` object because storing these errors uses up additional
247247
storage in the queue. If you're intending to receive a lot of malformed
248-
data then the queue mioght overflow `E.getErrorFlags()` would return `FIFO_FULL`.
248+
data then the queue might overflow `E.getErrorFlags()` would return `FIFO_FULL`.
249249
However if you need to respond to `framing` or `parity` errors then
250250
you'll need to use `errors:true` when initialising serial.
251251
*/

0 commit comments

Comments
 (0)