Skip to content

Configure block types with a blocks setting, and report the supported blocks - #50

Merged
ericof merged 5 commits into
mainfrom
issue-49
Oct 29, 2026
Merged

ericof merged 5 commits into
mainfrom
issue-49

Conversation

@ericof

@ericof ericof commented Oct 29, 2026

Copy link
Copy Markdown
Member

Every block converter now declares the Volto block type it produces, and one blocks setting turns each type on or off and sets its options. This replaces the code-block-specific plumbing from #48, so the next opt-in block needs no new parameters or flags.

volto_blocks(source, blocks={"codeBlock": {"style": "light"}, "slateTable": False})
  • html2blocks convert --enable codeBlock --option codeBlock.style=light --disable slateTable …
  • A blocks field on POST /html, /markdown and /volto. An invalid setting returns 400.
  • html2blocks blocks (text/JSON/Markdown), GET /blocks, and a new block-types section in info. The docs page Supported blocks is generated with make docs-blocks, and a test fails when it goes stale.
  • code_block= and the --code-* flags from Convert <pre> and Markdown code fences to code blocks #48 are removed. They were never released.

Registrations

Block type From Package Default
slate everything else @plone/volto always
image <img> @plone/volto on
slateTable <table> @plone/volto on
video <video>, YouTube and Vimeo <iframe> @plone/volto on
maps (new) Google Maps <iframe> @plone/volto on
iframe any other <iframe> @kitconcept/volto-iframe-block on
soundcloudBlock SoundCloud <iframe> @kitconcept/volto-social-blocks on
codeBlock <pre> @plonegovbr/volto-code-block off

iframe and soundcloudBlock come from add-ons but stay on, so the default output doesn't change. While there are no fallbacks for disabled image, video and iframe blocks, disabling them drops the element.

Bugs fixed along the way

  • A YouTube <video> produced two video blocks, and kept its watch?v= URL instead of youtu.be/<id>.
  • The HTTP service dropped every block key that VoltoBlock doesn't declare: the table of a table, the src of an iframe, the alt/title of an image.
  • With codeBlock on, a <pre> inside a table came out before the table instead of after it.

Default output was compared against a snapshot of 298 cases taken from the fixtures, and only the YouTube <video> cases changed.

Closes #49

video_block yielded the YouTube block and then fell through to the plain
video block, so every <video> with a YouTube src produced two identical
video blocks. The tests only looked at the first block, so they never saw
the second one.

Refs #49
The endpoints are annotated with the VoltoBlock TypedDict, and pydantic
dropped every key it does not declare: the table of a slateTable, the src,
width and height of an iframe, the alt and title of an image. Allow extra
keys through __pydantic_config__, set as a plain dict so that pydantic stays
an optional dependency of the package.

Refs #49
Block converters and iframe providers now declare the Volto block type they
produce, the frontend package that provides it, whether it is enabled by
default, its options (a dataclass) and an optional fallback. Every existing
registration got its metadata: image, slateTable, video, codeBlock, slate,
iframe and soundcloudBlock.

One blocks setting, keyed by block type, enables, disables and configures
them: blocks= in html_to_blocks(), markdown_to_blocks() and volto_blocks(),
--enable, --disable and --option in the convert command, and a blocks field
on POST /html, /markdown and /volto. Unknown block types and options, and
values of the wrong type, are errors. The setting replaces the code_block
argument and the --code-* options added for codeBlock, which were never
released.

A disabled block type sends its tags to its fallback, or hides them as the
codeBlock converter did. An iframe whose provider block is disabled goes to
the default provider, and is dropped when that one is disabled too.

The new html2blocks blocks command (text, JSON or Markdown), GET /blocks and
the info command report the block types. The Markdown output is the
Supported blocks reference page, regenerated with make docs-blocks, and a
test fails when the page is out of date.

The table converter now takes the tags to extract from cells from the
registry, so a <pre> inside a table comes after the table, like images and
videos, while codeBlock is enabled.

Closes #49
Add two iframe providers, both producing Volto core blocks:

- Google Maps (www.google.com/maps/embed and maps.google.com/maps) becomes
  a maps block, with the iframe src as its url and the iframe title, if any.
- Vimeo (player.vimeo.com/video/<id> and vimeo.com/<id>) becomes a video
  block. The video block reads the Vimeo id from what follows ".com/", so
  the url is always https://vimeo.com/<id>, never the player URL.

Disabling maps or video sends these iframes to the default iframe provider.

Refs #49
A YouTube <iframe> becomes a video block with https://youtu.be/<id>, but a
<video> with a YouTube src kept its original URL (watch?v=, embed/...).
Use the same URL for both.

Refs #49
@ericof
ericof merged commit ea43534 into main Oct 29, 2026
14 checks passed
@ericof
ericof deleted the issue-49 branch October 29, 2026 00:47
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.

Configurable block converters: per-block enable/options, package provenance and a supported blocks report

1 participant