Add-on with code, Mermaid diagram and GitHub Gist blocks for Plone projects with Volto.
- Code Block (
codeBlock): source code with syntax highlighting, line numbers and a caption. - Mermaid Diagram (
mermaidBlock): diagrams rendered from their text definition. - Gist Block (
gistBlock): embedded GitHub Gists.
All blocks are also available inside the grid and accordion blocks, and they are documented for the @blocks-schema endpoint of Volto 19.6 and later.
@plonegovbr/volto-code-block can be seen in action at the following sites:
You can also check its Storybook.
The languages offered in the block settings are in config.settings.codeBlock.languages. Each item is an object containing:
label: Friendly name for the language, for examplePython.language: Reference to theprismjslanguage component.
To change them, start from the existing languages in the configuration of your project or add-on. The Mermaid block needs the mermaid language for its syntax highlighting, and languages with no grammar are shown as plain text. For example, this adds Markdown highlighting, which is not loaded by default:
import type { ConfigType } from '@plone/registry';
import { languages } from '@plonegovbr/volto-code-block';
import type { CodeBlockSettings } from '@plonegovbr/volto-code-block/helpers/languages';
import 'prismjs/components/prism-markdown';
const applyConfig = (config: ConfigType) => {
const settings = config.settings.codeBlock as CodeBlockSettings;
config.settings.codeBlock = {
languages: {
...settings.languages,
markdown: { label: 'Markdown', language: languages.markdown },
},
};
return config;
};
export default applyConfig;config.blocks.blocksConfig.codeBlock sets the language and the style used when a block has none:
defaultLanguage:pythondefaultStyle:dark
This add-on is developed and tested with Volto 19.6. The @blocks-schema endpoint, which serves the documentation of its blocks, requires Volto 19.6.0 or later.
Add @plonegovbr/volto-code-block to the dependencies and addons keys of your package.json:
"addons": [
"@plonegovbr/volto-code-block"
],
"dependencies": {
"@plonegovbr/volto-code-block": "*"
}Install the dependencies and start Volto. From the frontend folder of your project, run:
make install
make startOr, from the root of your project, run:
make frontend-install
make frontend-startVisit http://localhost:3000/ in a browser, log in, edit a page, and add a Code Block, Mermaid Diagram or Gist Block from the text group of the block chooser.
The development of this add-on is done in isolation using pnpm workspaces, mrs-developer and a checkout of Volto core.
For this reason, it only works with pnpm.
- An operating system that runs all the requirements mentioned.
- nvm
- Node.js and pnpm 24
- Make
- Git
- Docker (optional)
-
Clone this repository, then change your working directory.
git clone git@github.com:plonegovbr/volto-code-block.git cd volto-code-block -
Install this code base.
make install
Run make help to list the available commands.
help Show this help
clean Clean environment
install Installs the add-on in a development environment
start Starts Volto, allowing reloading of the add-on during development
build Build a production bundle for distribution of the project with the add-on
build-deps Build dependencies
i18n Sync i18n
ci-i18n Check if i18n is not synced
format Format codebase
lint Lint, or catch and remove problems, in code base
typecheck Type check the add-on with tsc
release Release the add-on on npmjs.org
release-dry-run Dry-run the release of the add-on on npmjs.org
test Run unit tests
ci-test Run unit tests in CI
backend-docker-start Starts a Docker-based backend for development
storybook-start Start Storybook server on port 6006
storybook-build Build Storybook
acceptance-frontend-dev-start Start acceptance frontend in development mode
acceptance-frontend-prod-start Start acceptance frontend in production mode
acceptance-backend-start Start backend acceptance server
ci-acceptance-backend-start Start backend acceptance server in headless mode for CI
install-acceptance Install the Playwright browsers used by the acceptance tests
acceptance-test Start the acceptance tests in interactive (UI) mode
ci-acceptance-test Run the acceptance tests in headless mode for CI
Install package requirements.
make installStart the backend.
make backend-docker-startIn a separate terminal session, start the frontend.
make startRun ESlint, Prettier, Stylelint and the type check in analyze mode.
make lintRun ESlint, Prettier, and Stylelint in fix mode.
make formatRun tsc on the add-on.
make typecheckExtract the i18n messages to locales.
make i18nRun unit tests.
make testThe acceptance tests in acceptance/tests use Playwright.
The first time, install the browser.
make install-acceptanceRun each of the next steps in separate terminal sessions.
In the first session, start the frontend in development mode.
make acceptance-frontend-dev-startIn the second session, start the backend acceptance server.
make acceptance-backend-startIn the third session, start the Playwright interactive test runner.
make acceptance-testTo run the tests headless instead, use make ci-acceptance-test.
Each block has a docs.block.md next to its schema, which Volto serves through the @blocks-schema endpoint.
When you change the fields of a block, update this file too: src/components/Blocks/docs.test.ts fails when the documentation and the schema disagree.
The project is licensed under the MIT license.
Generated using Cookieplone, and aligned with cookieplone-templates (feb3bcf). A special thanks to all contributors and supporters!

