Skip to content

Plugin best practices

Romain Menke edited this page Jul 9, 2022 · 5 revisions

A set of guidelines and tips to create plugins that work well for as much users as possible.

Selector and Value parsers

It is tempting to use string find/replace or regex operations to modify CSS in a plugin. These are easy ways that work well for simple cases.

However they fail when bits have escape sequences (\) or maybe they are part of a string.

/* looking for selector `:fancy-selector` */

:fancy-selector {}

\:fancy-selector {} /* escaping changes ":" */

[data-example=":fancy-selector"] {} /* strings in attribute selectors */
/* looking for value `fancy-value` */

.example {
  order: fancy-value; /* keyword value */
}

.example {
  content: "fancy-value"; /* string value */
}
Clone this wiki locally