Skip to content

Commit

Permalink
template tag for updating cells (#12)
Browse files Browse the repository at this point in the history
* being creating a template tag of cells to facilitate uploading content
* add a table element to template so beautiful soup doesnt sanitize it.
* add flags for visibility upload components
* update configuration to not default to template tags
  • Loading branch information
tonyfast committed Dec 12, 2023
1 parent f7be77f commit a45571f
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 33 deletions.
4 changes: 4 additions & 0 deletions nbconvert_a11y/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class A11yExporter(PostProcess, HTMLExporter):
include_cell_index = Bool(
True, help="show the ordinal cell index, typically this is ignored from notebooks."
).tag(config=True)
include_visibility = Bool(False, help="include visibility toggle").tag(config=True)
include_upload = Bool(False, help="include template for uploading new content").tag(config=True)
exclude_anchor_links = Bool(True).tag(config=True)
code_theme = Enum(list(THEMES), "gh-high", help="an accessible pygments dark/light theme").tag(
config=True
Expand Down Expand Up @@ -130,6 +132,8 @@ def from_notebook_node(self, nb, resources=None, **kw):
resources["include_settings"] = self.include_settings
resources["include_help"] = self.include_help
resources["include_toc"] = self.include_toc
resources["include_visibility"] = self.include_upload
resources["include_upload"] = self.include_upload
resources["wcag_priority"] = self.wcag_priority
resources["accesskey_navigation"] = self.accesskey_navigation
resources["code_theme"] = THEMES[self.code_theme]
Expand Down
7 changes: 5 additions & 2 deletions nbconvert_a11y/templates/a11y/base.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,17 @@ the notebook experiennce from browse to edit/focus mode.
<summary onclick="openDialogs()">settings, help, & diagnostics</summary>
</details>
{% if resources.include_settings %}{% include "a11y/components/settings.html.j2" %}{% endif %}
{% include "a11y/components/visibility.html.j2"%}
{% if resources.include_visibility %}{% include "a11y/components/visibility.html.j2"%}{% endif %}
{% if resources.include_help %}{% include "a11y/components/help.html.j2" %}{% endif %}
{% if resources.include_axe %}{% include "a11y/components/audit.html.j2" %}{% endif %}
{# make the individual settings discoverable before all the settings
when using shift+tab #}
{% if resources.include_settings %}
<button onclick="openDialog()" aria-controls="nb-settings" accesskey=",">settings</button>
{% endif %}
<button aria-controls="nb-visibility-dialog" onclick="openDialog()" accesskey="-">show/hide</button>
{% if resources.include_visibility %}<button aria-controls="nb-visibility-dialog" onclick="openDialog()"
accesskey="-">show/hide</button>
{% endif %}
{% if resources.include_axe %}<button aria-controls="nb-audit" aria-describedby="nb-audit-desc"
onclick="openDialog()">audit</button>{% endif %}
{% if resources.include_help %}<button onclick="openDialog()" aria-controls="nb-help"
Expand All @@ -80,6 +82,7 @@ the notebook experiennce from browse to edit/focus mode.
{{activity_log()}}
<a href="#TOP" accesskey="0">skip to top</a>
</footer>
{% if resources.include_upload %}{% block template_element %}{% endblock %}{% endif %}
</body>
{% endblock body_footer %}

Expand Down
6 changes: 3 additions & 3 deletions nbconvert_a11y/templates/a11y/components/cell.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
{% from "a11y/components/displays.html.j2" import cell_display_priority with context %}

{% macro cell_anchor(i, cell_type, hidden=False)%}
<a href="#{{i}}" id="{{i}}" aria-labelledby="nb-cell-label {{i}}" {% if resources.accesskey_navigation and (i < 10)
%}accesskey="{{i}}" {% endif %} aria-describedby="nb-{{cell_type}}-label nb-cell-label cell-{{i}}-loc nb-loc-label"
{{hide(hidden)}}>{{i}}</a>
<a href="#{{i}}" id="{{i}}" aria-labelledby="nb-cell-label {{i}}" {% if resources.accesskey_navigation and isinstance(i,
int) and (i < 10) %}accesskey="{{i}}" {% endif %}
aria-describedby="nb-{{cell_type}}-label nb-cell-label cell-{{i}}-loc nb-loc-label" {{hide(hidden)}}>{{i}}</a>
{% endmacro %}

{% macro cell_form(i, cell_type, hidden=True) %}
Expand Down
71 changes: 43 additions & 28 deletions nbconvert_a11y/templates/a11y/table.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,37 @@
cell_form, cell_source, cell_metadata, cell_output with context%}
{% set COLUMNS = ["index", "execution_count", "cell_type", "toolbar", "started_at", "completed_at", "source", "loc",
"metadata", "outputs"] %}

{% 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}}">
<td role="none" class="nb-anchor">{{cell_anchor(loop.index, cell.cell_type)}}</td>
<td role="none" class="nb-execution_count" hidden>{{cell_execution_count(loop.index, cell.execution_count)}}
</td>
<td role="none" class="nb-cell_type" hidden>{{cell_cell_type(loop.index, cell.cell_type)}}</td>
<td role="none" class="nb-toolbar" hidden>{{cell_form(loop.index)}}</td>
<td role="none" class="nb-start" id="cell-{{loop.index}}-start" hidden>
{% set t0 = cell.get("metadata", {}).get("execution", {}).get("iopub.execute_input", "") %}
{{time(t0)}}
</td>
<td role="none" class="nb-end" id="cell-{{loop.index}}-end" hidden>
{% set t1 = cell.get("metadata", {}).get("execution", {}).get("shell.execute_reply", "") %}
{{time(t1)}}
</td>
<td role="none" class="nb-source" {{hide(cell.cell_type=="markdown" )}}>{{cell_source(loop.index,
cell.source, cell.cell_type, cell.execution_count)}}</td>
<td role="none" class="nb-metadata" hidden>{{cell_metadata(loop.index, cell.get("metadata", {}))}}</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" hidden>{{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 %}

{% block body_loop %}
{# the most consistent implementation would connect the input visibility to a form #}
<table id="cells" role="presentation">
Expand All @@ -15,37 +46,13 @@ cell_form, cell_source, cell_metadata, cell_output with context%}
</tr>
{%- for cell in nb.cells -%}
{% block any_cell scoped %}
<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}}">
<td role="none" class="nb-anchor">{{cell_anchor(loop.index, cell.cell_type)}}</td>
<td role="none" class="nb-execution_count" hidden>{{cell_execution_count(loop.index, cell.execution_count)}}
</td>
<td role="none" class="nb-cell_type" hidden>{{cell_cell_type(loop.index, cell.cell_type)}}</td>
<td role="none" class="nb-toolbar" hidden>{{cell_form(loop.index)}}</td>
<td role="none" class="nb-start" id="cell-{{loop.index}}-start" hidden>
{% set t0 = cell.metadata.get("execution", {}).get("iopub.execute_input", "") %}
{{time(t0)}}
</td>
<td role="none" class="nb-end" id="cell-{{loop.index}}-end" hidden>
{% set t1 = cell.metadata.get("execution", {}).get("shell.execute_reply", "") %}
{{time(t1)}}
</td>
<td role="none" class="nb-source" {{hide(cell.cell_type=="markdown" )}}>{{cell_source(loop.index,
cell.source, cell.cell_type, cell.execution_count)}}</td>
<td role="none" class="nb-metadata" hidden>{{cell_metadata(loop.index, cell.metadata)}}</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" hidden>{{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>
{{cell_row(cell, loop)}}
{% endblock any_cell %}
{%- endfor -%}
</tbody>
</table>


<table class="nb-cells-footer" hidden>
<tbody>
{# needs a header row #}
Expand Down Expand Up @@ -85,4 +92,12 @@ cell_form, cell_source, cell_metadata, cell_output with context%}
</tr>
</tbody>
</table>
{% endblock body_loop %}
{% endblock body_loop %}

{% block template_element %}
<template>
<table>
{{cell_row(dict(source=""), dict(index=""))}}
</table>
</template>
{% endblock %}
2 changes: 2 additions & 0 deletions tests/configurations/a11y.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
c.A11yExporter.include_sa11y = True
c.A11yExporter.include_settings = True
c.A11yExporter.include_help = True
c.A11yExporter.include_visibility = True
c.A11yExporter.include_upload = True
c.A11yExporter.wcag_priority = "AAA"

0 comments on commit a45571f

Please sign in to comment.