Skip to content

Fix/22 footnotes not replaced in structblocks - #95

Draft
kevinhowbrook wants to merge 7 commits into
mainfrom
fix/22-footnotes-not-replaced-in-structblocks
Draft

kevinhowbrook wants to merge 7 commits into
mainfrom
fix/22-footnotes-not-replaced-in-structblocks

Conversation

@kevinhowbrook

Copy link
Copy Markdown
Contributor

This is a very raw WIP for #22

Fix footnotes not being replaced inside StructBlocks

When a RichTextBlockWithFootnotes was a StructBlock child, rendering it with {% include_block value.caption %} output raw markup and left the footnote out of the footnotes list. (The |richtext filter still can't replace footnotes, the README is updated to adisve people to use {% include_block %} in StructBlock templates instead.

Two StructBlocks with a RichTextBlockWithFootnotes caption, each using one
of the common template patterns for rendering a child rich text value:
{{ value.caption|richtext }} and {% include_block value.caption %}.
These are used by the tests for footnotes inside StructBlocks.
When a RichTextBlockWithFootnotes is a StructBlock child and the struct's
template renders it with {% include_block value.caption %}, the footnote
tags are output as raw <footnote> markup and the footnotes aren't added to
the page's footnotes list. These tests fail until that's fixed:

- the caption's footnote tag is replaced with a numbered link
- the footnote is added to page.footnotes_list
- a full page request renders and lists the footnote

Two regression guards pass already and must keep passing: the
{% include_block value.bound_blocks.caption %} workaround, and
{{ value.caption|richtext }} rendering without raising.
{% include_block %} only renders a value through its block if the value
has a render_as_block() method. RichTextBlockWithFootnotes returned plain
RichText values, so a StructBlock template using
{% include_block value.caption %} skipped the block's render() and the
footnote tags were never replaced.

Values loaded from the database are now RichTextWithFootnotes, a RichText
subclass that keeps a reference to its block and implements
render_as_block(). Because it's still a RichText, the |richtext filter and
anything reading value.source (saving, search, the API) are unchanged.
RichTextBlock creates RichText values in two more places besides
to_python(): value_from_form(), used for page previews built from
submitted form data, and normalize(), used when values are set from
Python. Values created on those paths are still plain RichText, so
{% include_block value.caption %} doesn't replace their footnotes yet.
Without these, footnotes in a StructBlock were replaced on published pages
but not in page previews (which build values from form data) or for values
set from Python.
Explain that StructBlock templates should render RichTextBlockWithFootnotes
children with {% include_block %}, and that the |richtext filter (and a
StructBlock without a template) can't replace footnotes because they don't
have access to the page.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant