Skip to content

Commit

Permalink
fix docs when example code has odd characters in the title
Browse files Browse the repository at this point in the history
  • Loading branch information
gfwilliams committed Mar 16, 2017
1 parent bd39d2c commit c363065
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion scripts/build_docs.py
Expand Up @@ -25,6 +25,7 @@
import common
import urllib2
import markdown
import htmlentitydefs

# Scans files for comments of the form /*JSON......*/ and then writes out an HTML file describing
# all the functions
Expand Down Expand Up @@ -141,6 +142,14 @@ def get_link(jsondata):
s=s+jsondata["name"]
return s

def html_escape(text):
escaped_chars = ""
for c in text:
if (ord(c) < 32) or (ord(c) > 126):
c = '&{};'.format(htmlentitydefs.codepoint2name[ord(c)])
escaped_chars = escaped_chars + c
return escaped_chars

# If MDN doesn't 404 then include a link to it
def insert_mdn_link(jsondata):
if "class" in jsondata and "name" in jsondata:
Expand Down Expand Up @@ -344,7 +353,7 @@ def insert_mdn_link(jsondata):
html(" <p class=\"examples\">This function is used in the following places in Espruino's documentation</p>")
html(" <ul class=\"examples\">")
for link in uses:
html(' <li><a href="'+link["url"]+'">'+link["title"]+'</a></li>')
html(' <li><a href="'+link["url"]+'">'+html_escape(link["title"])+'</a></li>')
html(" </ul>")

html(" </body>")
Expand Down

0 comments on commit c363065

Please sign in to comment.