Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add table header to the notebook cells table #79

Merged
merged 19 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/pr-open.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
on:
pull_request:
types:
- opened

jobs:
comment:
runs-on: ubuntu-latest
name: Notify html target
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Comment PR
uses: thollander/actions-comment-pull-request@v2
with:
message: |
A preview fo the exported examples will be rendered at
https://iota-school.github.io/notebooks-for-all/branch/${{ github.event.pull_request.head.ref }}/exports/html
2 changes: 2 additions & 0 deletions nbconvert_html5/form_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
this design assumes __notebooks are a feed of forms__.
"""

from datetime import datetime
from nbconvert.exporters.html import HTMLExporter
from contextlib import suppress
from functools import lru_cache
Expand Down Expand Up @@ -113,6 +114,7 @@ def __init__(self, *args, **kwargs):
count_code_cells=count_code_cells,
ordered=ordered,
schema=SCHEMA,
datetime=datetime
)

def from_notebook_node(self, nb, resources=None, **kw):
Expand Down
4 changes: 2 additions & 2 deletions nbconvert_html5/templates/a11y/activity-log.html.j2
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<details class="log">
<summary>activity log</summary>
<summary><span {% if LOGID %}id="nb-activity-log-label" {% endif %}>activity log</span></summary>
</details>
<table aria-labelledby="nb-activity-log-label" aria-live="polite">
<table aria-live="polite" aria-labelledby="nb-activity-log-label">
<tr>
<th>time</th>
<td>message</td>
Expand Down
92 changes: 47 additions & 45 deletions nbconvert_html5/templates/a11y/help.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,50 @@ what about internationalization? how does scheme effect internalization? #}
<dl aria-labelledby="nb-notebook-label nb-defs-label">
<dt id="nb-root-metadata-label">metadata</dt>
<dd id="nb-root-metadata-desc">{{schema.properties.metadata.description}}</dd>
<dl>
<dt id="nb-kernelspec-label">kernelspec</dt>
<dd>{{schema.properties.metadata.properties.kernelspec.description}}</dd>
<dd>
{# kernel is going to be problmenatic language for novice users. run? runtime? #}
{# kernelspec and language info should appear as separate sections with widgets in the
metadata dialog. #}
<dl aria-labelledby="nb-kernelspec-label">
<dt>kernel name</dt>
<dd>{{schema.properties.metadata.properties.kernelspec.properties.name.description}}
</dd>
<dt>display name</dt>
<dd>{{schema.properties.metadata.properties.kernelspec.properties.display_name.description}}
</dd>
</dl>
</dd>
<dt id="nb-language_info-label">language info</dt>
<dd>{{schema.properties.metadata.properties.language_info.description}}</dd>
<dd>
<dl aria-labelledby="nb-language_info-label">
<dt>programming language</dt>
<dd>{{schema.properties.metadata.properties.language_info.properties.name.description}}
</dd>
<dt><a>codemirror mode</a></dt>
<dd>{{schema.properties.metadata.properties.language_info.properties.codemirror_mode.description}}
</dd>
<dt>file extension</dt>
<dd>{{schema.properties.metadata.properties.language_info.properties.file_extension.description}}
</dd>
<dt>mimetype</dt>
<dd>{{schema.properties.metadata.properties.language_info.properties.mimetype.description}}
</dd>
<dt>pygments lexer</dt>
<dd>{{schema.properties.metadata.properties.language_info.properties.pygments_lexer.description}}
</dd>
</dl>
</dd>
<dt>title</dt>
<dd>{{schema.properties.metadata.properties.title.description}}</dd>
<dt>authors</dt>
<dd>{{schema.properties.metadata.properties.authors.description}}</dd>
</dl>
<dd>
<dl>
<dt id="nb-kernelspec-label">kernelspec</dt>
<dd>{{schema.properties.metadata.properties.kernelspec.description}}</dd>
<dd>
{# kernel is going to be problmenatic language for novice users. run? runtime? #}
{# kernelspec and language info should appear as separate sections with widgets in the
metadata dialog. #}
<dl aria-labelledby="nb-kernelspec-label">
<dt>kernel name</dt>
<dd>{{schema.properties.metadata.properties.kernelspec.properties.name.description}}
</dd>
<dt>display name</dt>
<dd>{{schema.properties.metadata.properties.kernelspec.properties.display_name.description}}
</dd>
</dl>
</dd>
<dt id="nb-language_info-label">language info</dt>
<dd>{{schema.properties.metadata.properties.language_info.description}}</dd>
<dd>
<dl aria-labelledby="nb-language_info-label">
<dt>programming language</dt>
<dd>{{schema.properties.metadata.properties.language_info.properties.name.description}}
</dd>
<dt><a>codemirror mode</a></dt>
<dd>{{schema.properties.metadata.properties.language_info.properties.codemirror_mode.description}}
</dd>
<dt>file extension</dt>
<dd>{{schema.properties.metadata.properties.language_info.properties.file_extension.description}}
</dd>
<dt>mimetype</dt>
<dd>{{schema.properties.metadata.properties.language_info.properties.mimetype.description}}
</dd>
<dt>pygments lexer</dt>
<dd>{{schema.properties.metadata.properties.language_info.properties.pygments_lexer.description}}
</dd>
</dl>
</dd>
<dt>title</dt>
<dd>{{schema.properties.metadata.properties.title.description}}</dd>
<dt>authors</dt>
<dd>{{schema.properties.metadata.properties.authors.description}}</dd>
</dl>
</dd>
<dt id="nb-cells-label">cells</dt>
<dd id="nb-cells-desc">{{schema.properties.cells.description}}</dd>
</dl>
Expand All @@ -90,15 +92,15 @@ what about internationalization? how does scheme effect internalization? #}
<dd id="nb-jupyter-desc">
{{schema.definitions.raw_cell.properties.metadata.properties.jupyter.description}}</dd>
<dd>
<dl id="nb-jupyter-desc">
<dl>
<dt>source hidden</dt>
<dd>{{schema.definitions.code_cell.properties.metadata.properties.jupyter.source_hidden.description}}
</dd>
<dt>outputs hidden</dt>
<dd>{{schema.definitions.code_cell.properties.metadata.properties.jupyter.outputs_hidden.description}}
</dd>
<dt id="nb-exection-label">execution</dt>
<dd id="nb-exection-desc">
<dt id="nb-execution-label">execution</dt>
<dd id="nb-execution-desc">
{{schema.definitions.code_cell.properties.metadata.properties.execution.description}}
</dd>
<dd>
Expand Down
8 changes: 4 additions & 4 deletions nbconvert_html5/templates/a11y/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ const BODY = document.querySelector("body"), SELECTORS = {
"cell": "none",
}, "table": {
"table": "table",
"body": null,
"row": null,
"header": null,
"cell": null,
"body": "rowgroup",
"row": "row",
"header": "rowheader",
"cell": "cell",
}, "landmark": {
"table": "presentation",
"body": "group",
Expand Down
3 changes: 3 additions & 0 deletions nbconvert_html5/templates/a11y/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,14 @@ textarea[name=source] {


table#cells+table,
table#cells>tbody>tr:first-child,
#cells .cell>.nb-loc,
#cells .cell.markdown>.nb-source,
#cells .nb-cell_type,
#cells .nb-metadata,
#cells .nb-execution_count,
#cells .nb-start,
#cells .nb-end,
#cells details>summary[inert]~textarea[name=source],
#cells details>summary:not([inert])~textarea[name=source]~* {
display: none;
Expand Down
32 changes: 27 additions & 5 deletions nbconvert_html5/templates/a11y/table.html.j2
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{%- extends 'semantic-forms/base.html.j2' -%}

{% set COLUMNS = ["index", "execution_count", "cell_type", "toolbar", "started_at", "completed_at", "source", "loc",
"metadata", "outputs"] %}
{% block body_header %}
{{super()}}
{# the most consistent implementation would connect the input visibility to a form #}
<table id="cells" role="presentation">
<tbody role="list">
<tr>
{% for col in COLUMNS %}
<th scope="col">{{col}}</th>
{% endfor %}
</tr>
{# the table caption is removed because testing on VoiceOver iOS encountered
https://developer.apple.com/forums/thread/679841

Expand All @@ -19,6 +25,7 @@
</tbody>
</table>
<table class="nb-cells-footer" hidden>

<tbody>
{# needs a header row #}
<tr class="total">
Expand Down Expand Up @@ -62,18 +69,33 @@

{% macro loc(cell) %}{{cell.source.splitlines().__len__()}}{% endmacro%}

{% macro time(t) %}
{% if t %}{% if t.endswith("Z") %}{% set t = t[:-1] + "+00:00" %}{% endif %}<time datetime="{{datetime.fromisoformat(t).isoformat(timespec="milliseconds")}}">{{t}}</time>{% endif %}
{% endmacro %}

{% macro cell_row(cell, loop) %}
<tr role="listitem" class="cell {{cell.cell_type}}"
aria-labelledby="nb-cell-label {{loop.index}} cell-{{loop.index}}-cell_type"
data-loc="{{cell.source.splitlines().__len__()}}" {% if cell.cell_type=="code" %} {% endif %} data-index="{{loop.index}}">
data-loc="{{cell.source.splitlines().__len__()}}" {% if cell.cell_type=="code" %} {% endif %}
data-index="{{loop.index}}">
<td role="none" class="nb-anchor">{{cell_anchor(loop.index, cell.cell_type)}}</td>
<td role="none" class="nb-execution_count">{{cell_execution_count(loop.index, cell.execution_count)}}</td>
<td role="none" class="nb-cell_type">{{cell_cell_type(loop.index, cell.cell_type)}}</td>
<td role="none" class="nb-toolbar">{{cell_form(loop.index)}}</td>
<td role="none" class="nb-start" id="cell-{{loop.index}}-start">
{% set t0 = cell.metadata.get("execution", {}).get("iopub.execute_input", "") %}
{{time(t0)}}
</td>
<td role="none" class="nb-end" id="cell-{{loop.index}}-end">
{% set t1 = cell.metadata.get("execution", {}).get("shell.execute_reply", "") %}
{{time(t1)}}
</td>
<td role="none" class="nb-source">{{cell_source(loop.index, cell.source, cell.execution_count)}}</td>
<td role="none" class="nb-outputs">{{cell_output(loop.index, cell, cell.source, cell.outputs, cell.cell_type,
cell.execution_count)}}</td>
<td role="none" class="nb-metadata">{{cell_metadata(loop.index, cell.metadata)}}</td>
<td role="none" class="nb-toolbar">{{cell_form(loop.index)}}</td>
{# it was noted in a video that lines of code were helpful in assistive descriptions.
lines of code are part of the gestalt of code forms. #}
<td role="none" class="nb-loc" id="cell-{{loop.index}}-loc">{{loc(cell)}}</td>
<td role="none" class="nb-outputs">{{cell_output(loop.index, cell, cell.source, cell.outputs, cell.cell_type,
cell.execution_count)}}</td>
</tr>
{% endmacro %}
2 changes: 1 addition & 1 deletion nbconvert_html5/templates/semantic-forms/base.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ the notebook experiennce from browse to edit/focus mode.
<dialog id="nb-metadata">
<form method="dialog">
<button formmethod="dialog">Close</button>
{{nb.metadata}}
{{nb.metadata| json_dumps | escape_html_keep_quotes }}
</form>
</dialog>
{% if resources.include_help %}{% include "a11y/help.html.j2" %}{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions nbconvert_html5/templates/semantic-forms/displays.j2.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

{% block stream_stdout -%}
<pre class="stdout">
<code>{{- output.text -}}</code>
<code>{{- output.text | escape_html -}}</code>
</pre>
{%- endblock stream_stdout %}

{% block stream_stderr -%}
<pre class="stdout">
<code>{{- output.text -}}</code>
<code>{{- output.text | escape_html -}}</code>
</pre>
{%- endblock stream_stderr %}

Expand Down
Loading