Extract inline styles with Cheerio

Jeasx lets you post-process the finished HTML with a response handler. This example uses Cheerio to turn all inline styles into CSS classes in the head of the page.

  1. RenderJSX produces HTML full of inline style attributes.
  2. CollectCheerio finds each declaration; identical ones share a single class.
  3. RewriteClasses go into one style tag in the head and Prettier formats the result.

Compare the original and the rewritten markup of this very page below.

Original sourcebefore
Rewritten markupafter