Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,28 @@ You can hide the HTML code block from the source view, yet still have it part of

<!-- fiddle-end -->

### CSS block

You can add CSS to be applied to the HTML application. The CSS block is not shown on the output page.

<!-- fiddle CSS Code block -->
```html
<div id="greeting">Hello</div>
```
```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)')
```
<!-- fiddle-end -->

### 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.
Expand Down
21 changes: 21 additions & 0 deletions cypress/integration/css-code-block.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!-- fiddle CSS Code block -->

```html
<div id="greeting">Hello</div>
```

```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)')
```

<!-- fiddle-end -->
3 changes: 3 additions & 0 deletions cypress/integration/extract-fiddles.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ describe('extractFiddles', () => {
test: "console.log('1')",
html: null,
commonHtml: null,
css: null,
only: false,
skip: false,
export: false,
Expand Down Expand Up @@ -161,6 +162,7 @@ describe('extractFiddles', () => {
},
],
commonHtml: null,
css: null,
only: false,
skip: false,
export: false,
Expand All @@ -182,6 +184,7 @@ describe('extractFiddles', () => {
},
],
commonHtml: null,
css: null,
only: false,
skip: false,
export: false,
Expand Down
10 changes: 10 additions & 0 deletions src/markdown-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -313,6 +322,7 @@ function extractFiddles(md) {
? htmlMaybe
: null,
commonHtml,
css: cssMaybe || null,
only: fiddle.only,
skip: fiddle.skip,
export: fiddle.export,
Expand Down