diff --git a/README.md b/README.md
index aab6531..9c09ee6 100644
--- a/README.md
+++ b/README.md
@@ -110,6 +110,28 @@ You can hide the HTML code block from the source view, yet still have it part of
+### CSS block
+
+You can add CSS to be applied to the HTML application. The CSS block is not shown on the output page.
+
+
+ ```html
+
Hello
+ ```
+ ```css
+ #greeting {
+ color: #f0f;
+ padding: 1rem;
+ font-weight: bold;
+ }
+ ```
+ ```js
+ cy.get('div#greeting')
+ .should('have.text', 'Hello')
+ .and('have.css', 'color', 'rgb(255, 0, 255)')
+ ```
+
+
### Suites
To create suites of tests, use `/` to separate the suite name from the test name. Tests with the same suite name are grouped together automatically.
diff --git a/cypress/integration/css-code-block.md b/cypress/integration/css-code-block.md
new file mode 100644
index 0000000..1bc1e6b
--- /dev/null
+++ b/cypress/integration/css-code-block.md
@@ -0,0 +1,21 @@
+
+
+```html
+Hello
+```
+
+```css
+#greeting {
+ color: #f0f;
+ padding: 1rem;
+ font-weight: bold;
+}
+```
+
+```js
+cy.get('div#greeting')
+ .should('have.text', 'Hello')
+ .and('have.css', 'color', 'rgb(255, 0, 255)')
+```
+
+
diff --git a/cypress/integration/extract-fiddles.js b/cypress/integration/extract-fiddles.js
index d4ff867..10bbed8 100644
--- a/cypress/integration/extract-fiddles.js
+++ b/cypress/integration/extract-fiddles.js
@@ -129,6 +129,7 @@ describe('extractFiddles', () => {
test: "console.log('1')",
html: null,
commonHtml: null,
+ css: null,
only: false,
skip: false,
export: false,
@@ -161,6 +162,7 @@ describe('extractFiddles', () => {
},
],
commonHtml: null,
+ css: null,
only: false,
skip: false,
export: false,
@@ -182,6 +184,7 @@ describe('extractFiddles', () => {
},
],
commonHtml: null,
+ css: null,
only: false,
skip: false,
export: false,
diff --git a/src/markdown-utils.js b/src/markdown-utils.js
index 7a12976..030256c 100644
--- a/src/markdown-utils.js
+++ b/src/markdown-utils.js
@@ -260,12 +260,21 @@ function extractFiddles(md) {
const isJavaScript = (n) =>
n.type === 'CodeBlock' &&
(n.lang === 'js' || n.lang === 'javascript')
+ const isCssCodeBlock = (n) =>
+ n.type === 'CodeBlock' && n.lang === 'css'
fiddles.forEach((fiddle) => {
const ast = parse(fiddle.fiddle)
// console.log('markdown fiddle AST')
// console.log(ast)
+ const cssMaybe = ast.children
+ .filter(isCssCodeBlock)
+ .filter(shouldIncludeBlock)
+ .map((codeBlock) => codeBlock.value)
+ .join('\n')
+ // console.log(cssMaybe)
+
const htmlMaybe = ast.children
.filter(isHtmlCodeBlock)
.filter(shouldIncludeBlock)
@@ -313,6 +322,7 @@ function extractFiddles(md) {
? htmlMaybe
: null,
commonHtml,
+ css: cssMaybe || null,
only: fiddle.only,
skip: fiddle.skip,
export: fiddle.export,