BBcode color tags in a theme

I’ll let Sam elaborate, but believe it’s a plugin because:

  • the server needs to cook the raw post in the back-end, and this can only be done if the assets are loaded in the backend for V8 to process it (which requires a plugin)
  • the plugins can include specs to test the new rules

However, there’s another workaround, e.g.:

post, e.g.:

[wrap=colorme color=red]Hello there[/wrap]
[wrap=colorme color=blue]Hi there![/wrap]

CSS:


div.d-wrap[data-wrap="colorme"], span.d-wrap[data-wrap="colorme"] {

  &[data-color="red"] {
    color: red;
  }

  &[data-color="blue"] {
    color: blue;
  }

  &[data-color="yellow"] {
    color: yellow;
  }

  &[data-color="green"] {
    color: green;
  }
}

You only need to add the CSS, the behaviour above is native.

The result appears to be a little less flexible and bulletproof than BBCode, but it’s quite useable for many use cases. (in order to have multiple different colours in the same line, the first character must not be coloured I believe?).

Based on:

2 Likes