Skip to content

Commit

Permalink
[doc] Fix HTML processing in IndexLinker for help-index.
Browse files Browse the repository at this point in the history
- preserve DOCTYPE declaration
- handle <startendtags/> properly

Also run unit tests in devtools/

This fixes a bunch of errors caught by 'tidy'!  Tidy is still useful.
  • Loading branch information
Andy Chu committed Dec 2, 2019
1 parent c776b0b commit d4dae40
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
24 changes: 17 additions & 7 deletions devtools/make_help.py
Expand Up @@ -465,6 +465,15 @@ def _LinkLine(line):
return html_line


def _AttrsToString(attrs):
if not attrs:
return ''

# Important: there's a leading space here.
# TODO: Change href="$help:command" to href="help.html#command"
return ''.join(' %s="%s"' % (k, v) for (k, v) in attrs)


class IndexLinker(HTMLParser.HTMLParser):

def __init__(self, pre_class, out):
Expand All @@ -482,6 +491,13 @@ def log(self, msg, *args):
ind = self.indent * ' '
log(ind + msg, *args)

def handle_decl(self, data):
"""Pass through <!DOCTYPE ...>"""
self.out.write('<!%s>' % data)

def handle_startendtag(self, tag, attrs):
self.out.write('<%s%s/>' % (tag, _AttrsToString(attrs)))

def handle_starttag(self, tag, attrs):
if tag == 'pre':
values = [v for k, v in attrs if k == 'class']
Expand All @@ -490,13 +506,7 @@ def handle_starttag(self, tag, attrs):
if class_name:
self.linking = True

# TODO: Change href="$help:command" to href="help.html#command"
if attrs:
attr_str = ' ' # leading space
attr_str += ' '.join('%s="%s"' % (k, v) for (k, v) in attrs)
else:
attr_str = ''
self.out.write('<%s%s>' % (tag, attr_str))
self.out.write('<%s%s>' % (tag, _AttrsToString(attrs)))

self.log('start tag %s %s', tag, attrs)
self.indent += 1
Expand Down
3 changes: 1 addition & 2 deletions test/unit.sh
Expand Up @@ -44,8 +44,7 @@ banner() {
}

tests-to-run() {
# TODO: Add opy.
for t in {build,test,native,asdl,core,oil_lang,osh,frontend,pylib,test,tools}/*_test.py; do
for t in {devtools,build,test,native,asdl,core,oil_lang,osh,frontend,pylib,test,tools}/*_test.py; do
# For Travis after build/dev.sh minimal: if we didn't build fastlex.so,
# then skip a unit test that will fail.
if test $t = 'native/fastlex_test.py' && ! test -e 'fastlex.so'; then
Expand Down

0 comments on commit d4dae40

Please sign in to comment.