Skip to content

Commit

Permalink
Linkify the type lines in argumentdef blocks. Fixes #1252
Browse files Browse the repository at this point in the history
  • Loading branch information
tabatkins committed May 20, 2022
1 parent 4d52fbb commit ac0d420
Show file tree
Hide file tree
Showing 3 changed files with 885 additions and 8 deletions.
23 changes: 15 additions & 8 deletions bikeshed/unsortedJunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from urllib import parse
from PIL import Image

from . import biblio, config, dfnpanels, h, func, t, messages as m
from . import biblio, config, dfnpanels, h, func, t, messages as m, idl


class MarkdownCodeSpans(func.Functor):
Expand Down Expand Up @@ -1391,19 +1391,26 @@ def formatArgumentdefTables(doc: "t.SpecType"):
m.die(f"Can't find method '{forMethod}'.", el=table)
continue
for tr in h.findAll("tbody > tr", table):
tds = h.findAll("td", tr)
argName = h.textContent(tds[0]).strip()
try:
argCell, typeCell, nullCell, optCell, descCell = h.findAll("td", tr)
except:
m.die(
f"In the argumentdef table for '{method.full_name}', the '{argName}' line is misformatted, with {len(h.findAll('td', tr))} cells instead of 5.",
el=table,
)
continue
argName = h.textContent(argCell).strip()
arg = method.find_argument(argName)
if arg:
h.appendChild(tds[1], str(arg.type))
h.appendChild(typeCell, idl.nodesFromType(arg.type)),
if str(arg.type).strip().endswith("?"):
h.appendChild(tds[2], h.E.span({"class": "yes"}, "✔"))
h.appendChild(nullCell, h.E.span({"class": "yes"}, "✔"))
else:
h.appendChild(tds[2], h.E.span({"class": "no"}, "✘"))
h.appendChild(nullCell, h.E.span({"class": "no"}, "✘"))
if arg.optional:
h.appendChild(tds[3], h.E.span({"class": "yes"}, "✔"))
h.appendChild(optCell, h.E.span({"class": "yes"}, "✔"))
else:
h.appendChild(tds[3], h.E.span({"class": "no"}, "✘"))
h.appendChild(optCell, h.E.span({"class": "no"}, "✘"))
else:
m.die(
f"Can't find the '{argName}' argument of method '{method.full_name}' in the argumentdef block.",
Expand Down
28 changes: 28 additions & 0 deletions tests/idl007.bs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<pre class=metadata>
Title: Foo
Group: test
Shortname: foo
Level: 1
Status: LS
ED: http://example.com/foo
Abstract: Testing argumentdef blocks.
Editor: Example Editor
Date: 1970-01-01
</pre>

<xmp class=idl>
enum BarEnum { "", "bar" };
interface Foo {
undefined foo(
Promise<(DOMString or unsigned long or BarEnum)?> a,
any b,
([Clamp] unsigned long? or sequence<record<DOMString, [Exposed=(Window, Worker)] short>>) c
);
};
</xmp>
<pre class="argumentdef" for="Foo/foo()">
a: A complex promise
b: A nullable any
c: Unions and HKTs and extended attributes, oh my!
</pre>

Loading

0 comments on commit ac0d420

Please sign in to comment.