Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Introducing BBCode Data-Processor #158

Merged
merged 404 commits into from
Dec 6, 2023
Merged

Conversation

pkliesch
Copy link
Contributor

@pkliesch pkliesch commented Aug 23, 2023

New Features 🎉

BBCode Data Processor

The new module @coremedia/ckeditor5-bbcode provides a plugin for editing data available as BBCode.

As each BBCode is vendor specific (with some standards most agree upon), this plugin will also come with its own BBCode specification. The specification is mostly based on commonly agreed standards (for example, see Wikipedia (en)).

Find the full specification, including specifications for paragraph support and escaping in the module description.

RgbColor and CSSStyleDeclarations

Module @coremedia/ckeditor5-dom-support ships with two new utilities. They are dedicated (for now) to handling (text) colors. While introduced for BBCode parsing, they may be of more general use.

Main Usage Example

The following example for getColor from CSSStyleDeclarations forwards to RgbColor internally, when there is some rgb() or rgba() code to parse.

Style To Parse Result of getColor Comment
fuchsia fuchsia Color names (also artificial ones like transparent or currentcolor are returned as is.
rgb(1, 2, 3) RgbColor parsed result
rgba(1, 2, 3, 0.5) RgbColor parsed result

Note that there is no need for parsing other color format styles, as CSSStyleDeclaration transforms all color codes (thus, no color names) to either rgb() or rgba() internally.

RgbColor is then able to provide different representations of the parsed color either as rgb(), rgba(), as hex value or as hex-with-alpha (hexa) value.

The following table demonstrates different representations for a parsed rgba(128, 128, 128, 0.5) value:

Property Value Comment
rgb rgb(128, 128, 128) Alpha is stripped.
rgba rgba(128, 128, 128, 0.5)
toRgb() rgba(128, 128, 128, 0.5) Transparently switches between rgba and rgb depending on if alpha channel is set or not.
hex #808080 Alpha is stripped.
hexa #8080807f
toHex() #8080807f Transparently switches between hexa and hex depending on if alpha channel is set or not.

BBCode Usage

For BBCode, we use it for supporting [color=#808080] in data-processing.

BBob (third-party library we use for toView processing from BBCode to HTML) automatically transforms this to <span style="color: #808080;">

In toData processing, driven by a proprietary mapping as defined in some rule-sets, we can process any color state generated by the FontColor plugin that ships with CKEditor 5. They all will be transformed to the hex or hexa representation suitable for the [color] tag (despite color names, which are transformed as is).

Suggested CoreMedia Rich Text 1.0 Usage

CoreMedia Rich Text 1.0 lacks a style property. Typical mappings from HTML (CKEditor 5 data view) to CoreMedia Rich Text 1.0 (data layer) will try transforming styles to some dedicated token in class-attribute.

Given the new API, you could apply such transformations based on getColor in CSSStyleDeclarations utility collection. Suggested mapping:

Data View Data
<span style="color: fuchsia;"> <span class="style--color-fuchsia">
<span style="color: rgb(128, 128, 128);"> <span class="style--color-x808080">

The additional x may help in parsing, when it comes to resolve this mapping later in delivery (CAE, Headless Server).

Bug Fixes 🩹

Blocklist Feature

This pull-request also includes a set of fixes for the blocklist plugin:

Adjusting the following behaviors:

  • Allow letters which are not only between a-z/A-Z to support all languages.
  • Cut off words/text which is too long in balloon.
  • Improve initial balloon state when a word/text is selected.

Internal Changes 🔐

Some changes are not relevant for the external deliverable, but may be important to know for developers within this workspace.

ESLint

  • Enabling consistent-return.

    Required, for example, explicit return undefined; instead of just a void return value as in return;. Added, as it adds more consistency to the API we develop.

BBCode Example App

BBCode has been introduced as an additional flavor of the Example App. The CoreMedia Rich Text Example App, which is still our main example application, has been refactored, so that we can now load different flavors of example apps.

This comes with a new SwitchButton, that automatically stores the current state in the URL, so that upon reload, corresponding states are kept as is. For example, if you turned on read-only before, the editor will also be read-only after reload.

Babel Configuration Simplification

As most plugins we referenced explicitly are already part of the corresponding presets, removed the obsolete explicit references.

As a needed side effect, we returned to the standard configurations of the corresponding plugins, which is especially about skipping the loose option for plugin-transform-*.

TypeDoc: Prefer index.ts over index-doc.ts

Since we mature our public API within index.ts (adapting the CKEditor 5 code-style), the index-doc.ts becomes more and more obsolete. What is more: Using index.ts also for documentation will inform us automatically also on possibly missing (yet) private API to expose, that is reachable via public API.

Only more or less directly affected modules have been adapted accordingly.

@mmichaelis mmichaelis force-pushed the feature/bbcode-dataprocessor branch from ffb5c77 to 3abd876 Compare September 12, 2023 13:02
@mmichaelis mmichaelis force-pushed the feature/bbcode-dataprocessor branch from 3786b04 to b776872 Compare October 2, 2023 06:11
app/src/HashParams.ts Fixed Show fixed Hide fixed
@mmichaelis mmichaelis marked this pull request as draft October 4, 2023 12:55
Similar to DOM-Support, we require to deal with `null` again and again
as it is part of the BBob API. Thus, decided to skip these linter checks.
This is an intermediate commit to show the working paragraph support
at least for nested block-elements. Still missing is support on root-
level and of course a lot of clean-up.
To be able to process paragraphs on root-level we need to create
an artificial root-node to be processed within configured
default-tags.

There may be other options, like adding a paragraph-support plugin,
that runs after the HTML5 preset. But the current solution also
fixes an issue with the default `quote` processing of BBob HTML5
Preset: By default, it just wraps any content into a single paragraph
not respecting, that in a valid HTML5 structure, a paragraph must not
contain other block-level elements.

As alternative, we can now use the new "intelligent paragraph
processing" also on this level already, instead of having to devour
the results of the HTML5 preset (which even may change with more
recent BBob versions).
Bundling all hard-wired BBob-dependent artifacts into an extra folder.
Some documentation and removing debugging output.
One of the original tests for BBob HTML5 Preset (we copied them, to
ensure, we are consistent with the original mapping), added spaces
in front of a list. These extra spaces triggered creation of a
paragraph node containing only these _indent spaces_.

Decided to introduce a `skipEmpty` option, that is enabled by default.
This will prevent the creation of paragraphs, that are empty - also
trimming any blanks prior to this check.
First sketch for some security related checks on high integration
layer (thus, testing `bbcode2html` as facade to BBob).
Small sanitizer, that removes any `on` attributes.
Respect `requireParagraph` even if to skip empty.
A broad escaping may do harm to the BBCode. Instead, if handling
HTML characters is required it should be done in corresponding
environment (thus, different for element content compared to attribute
content).
For new rendering we skip final newlines in paragraph (BBCode to data
view). Adapting expectations accordingly.
Next trying to set an actions secret.
Set required GitHub Token.
Next try to get it going. For `gh` we need our repository. Thus,
checkout first.
Failed for now to pass authorization token from a called workflow.
Must be URL, not host.
Removing list of types. Not relevant.
And as probe, reduce again to the default search limit 20.
Trying with defensive comparison, if the used bash version does not
support arithmetic contexts.
There is a strict specification for pre-release versions.

Previous template `<mj>.<mn>.<p>-pr<pr>-<run>.0` violated this pattern
and may irritate parsing and ordering semantic versions.

The new template aligns with the standards, so that, for example, a
previous pre-release version:

    16.0.1-pr158-717.0

is now generated as:

    16.0.1-pr.158.717.0

See-also: <https://semver.org/>
Prefer check via local script over

    npx --yes only-allow pnpm

For a no-op install this boosts runtime from 7.2s to 1.5s (as one
example).
To reduce GitHub actions load (and as part of some debugging), providing
a Node.js script to deal with versions.
Instead of dealing with version increments at several GitHub actions,
we now prefer using a dedicated script. This also spares installing
`semver` and it provides the option to validate the process in
local runs.
Missed adding the theme folder.
As it seems, our implementation cannot handle CRLF inputs (Windows)
as well as CR (some older systems, like classic MacOS).

This test demonstrate it and should be fixed.
BBob only supports parsing of BBCode having Unix (LF) line-separators.
Thus, added pre-processing for this behavior.

An additional integration test will tell us, if BBob changes the
behavior here, which may trigger removing this normalization.
As decided, we will not support tables for BBCode up to now (due to
several challenges regarding the CKEditor 5 table-handling). Because
of that, also removing the Table Plugins from example application.
@mmichaelis mmichaelis merged commit af7c55b into main Dec 6, 2023
3 checks passed
@mmichaelis mmichaelis deleted the feature/bbcode-dataprocessor branch December 6, 2023 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature:bbcode BBCode Data-Processor release:minor Suggests a minor release (x.X.x) type:feature New Feature or Request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants