Visitar URL original
GitHub - plonegovbr/volto-code-block: Volto add-on providing a code block with syntax highlighting. Β· GitHub
Skip to content

About

Volto add-on providing a code block with syntax highlighting.

Topics

Resources

Stars

2 stars

Watchers

13 watching

Forks

Latest commit

Β 

History

69 Commits

Folders and files

Repository files navigation

Code Block for Volto (@plonegovbr/volto-code-block)

Add-on with code, Mermaid diagram and GitHub Gist blocks for Plone projects with Volto.

npm CI

Features

  • 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.

Screenshots

Code Block with Dark style

Screenshot

Code Block with Light style

Screenshot

Examples

@plonegovbr/volto-code-block can be seen in action at the following sites:

You can also check its Storybook.

Configuration

Languages

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 example Python.
  • language: Reference to the prismjs language 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;

Defaults

config.blocks.blocksConfig.codeBlock sets the language and the style used when a block has none:

  • defaultLanguage: python
  • defaultStyle: dark

Installation

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 start

Or, from the root of your project, run:

make frontend-install
make frontend-start

Test installation

Visit 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.

Development

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.

Prerequisites βœ…

Installation πŸ”§

  1. Clone this repository, then change your working directory.

    git clone git@github.com:plonegovbr/volto-code-block.git
    cd volto-code-block
  2. Install this code base.

    make install

Make convenience commands

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

Development environment set up

Install package requirements.

make install

Start developing

Start the backend.

make backend-docker-start

In a separate terminal session, start the frontend.

make start

Lint code

Run ESlint, Prettier, Stylelint and the type check in analyze mode.

make lint

Format code

Run ESlint, Prettier, and Stylelint in fix mode.

make format

Type check

Run tsc on the add-on.

make typecheck

i18n

Extract the i18n messages to locales.

make i18n

Unit tests

Run unit tests.

make test

Run acceptance tests

The acceptance tests in acceptance/tests use Playwright. The first time, install the browser.

make install-acceptance

Run each of the next steps in separate terminal sessions.

In the first session, start the frontend in development mode.

make acceptance-frontend-dev-start

In the second session, start the backend acceptance server.

make acceptance-backend-start

In the third session, start the Playwright interactive test runner.

make acceptance-test

To run the tests headless instead, use make ci-acceptance-test.

Documenting blocks

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.

License

The project is licensed under the MIT license.

Credits and acknowledgements πŸ™

Generated using Cookieplone, and aligned with cookieplone-templates (feb3bcf). A special thanks to all contributors and supporters!

About

Volto add-on providing a code block with syntax highlighting.

Topics

Resources

Stars

2 stars

Watchers

13 watching

Forks

Releases

Used by

Contributors

Languages