semantic representation of columns based on schemaยค
schema may define the columnar properties of a table.
that can be canonically presented using the colgroup
and col
elements
that allow for bulk operations on column styles.
make a schema with subschema
(schema := tomli.loads("".join(
```toml
[[allOf]]
"$ref" = "#/$defs/A"
[[allOf]]
"$ref" = "#/$defs/B"
["$defs".A.properties.foo]
["$defs".A.properties.bar]
["$defs".B.properties.baz]
```
.splitlines(1)[1:-1])))
make a schema with subschema
(schema := tomli.loads("".join(
[[allOf]]
"$ref" = "#/$defs/A"
[[allOf]]
"$ref" = "#/$defs/B"
["$defs".A.properties.foo]
["$defs".A.properties.bar]
["$defs".B.properties.baz]
.splitlines(1)[1:-1])))
the form we create uses `colgroup` and `col` elements as demonstrated next
```html
{{table.prettify()}}
```
and it is generated directly from schema using the following code generate example `colgroup` and `col` elements
import bs4, jsonpointer
soup = bs4.BeautifulSoup(features="html5lib")
soup.append(table := soup.new_tag("table"))
table.append(colgroup := soup.new_tag("colgroup"))
table.append(props := soup.new_tag("colgroup"))
for s in schema["allOf"]:
id = jsonpointer.JsonPointer.from_parts((ref:=s.get("$ref")).split("/")[1:])
colgroup.append(col := soup.new_tag("col"))
p = id.get(schema).get("properties")
col.attrs.update(id=str(id), span=len(p))
for k in p:
props.append(x := soup.new_tag("col"))
x.attrs.update(id=jsonpointer.JsonPointer.from_parts(ref.split("/")[1:] + ["properties", k]))
the form we create uses colgroup
and col
elements as demonstrated next
<table>
<colgroup>
<col id="/$defs/A" span="2"/>
<col id="/$defs/B" span="1"/>
</colgroup>
<colgroup>
<col id="/$defs/A/properties/foo"/>
<col id="/$defs/A/properties/bar"/>
<col id="/$defs/B/properties/baz"/>
</colgroup>
</table>
and it is generated directly from schema using the following code generate example colgroup
and col
elements
import bs4, jsonpointer
soup = bs4.BeautifulSoup(features="html5lib")
soup.append(table := soup.new_tag("table"))
table.append(colgroup := soup.new_tag("colgroup"))
table.append(props := soup.new_tag("colgroup"))
for s in schema["allOf"]:
id = jsonpointer.JsonPointer.from_parts((ref:=s.get("$ref")).split("/")[1:])
colgroup.append(col := soup.new_tag("col"))
p = id.get(schema).get("properties")
col.attrs.update(id=str(id), span=len(p))
for k in p:
props.append(x := soup.new_tag("col"))
x.attrs.update(id=jsonpointer.JsonPointer.from_parts(ref.split("/")[1:] + ["properties", k]))