Skip to content

Commit

Permalink
bug/issue 1375 preserve HTML entities when prerendering markdown (#1376)
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 authored Jan 23, 2025
1 parent 0133290 commit 7fd7dc3
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Use Case
* Run Greenwood with custom markdown content and prerendering enabled with WCC.
*
* User Result
* Should generate a bare bones Greenwood build and in particular make sure HTML entities are preserved.
*
* User Command
* greenwood build
*
* User Config
* {
* prerender: true
* }
*
* User Workspace
* src/
* components/
* ctc-block.js
* pages/
* index.md
*/
import fs from 'fs/promises';
import path from 'path';
import chai from 'chai';
import { runSmokeTest } from '../../../../../test/smoke-test.js';
import { getOutputTeardownFiles } from '../../../../../test/utils.js';
import { Runner } from 'gallinago';
import { fileURLToPath, URL } from 'url';

const expect = chai.expect;

// https://github.com/ProjectEvergreen/greenwood/issues/1375
describe('Build Greenwood With: ', function() {
const LABEL = 'Markdown with prerendering and HTML entities';
const cliPath = path.join(process.cwd(), 'packages/cli/src/index.js');
const outputPath = fileURLToPath(new URL('.', import.meta.url));
let runner;

before(function() {
this.context = {
publicDir: path.join(outputPath, 'public')
};
runner = new Runner();
});

describe(LABEL, function() {
before(function() {
runner.setup(outputPath);
runner.runCommand(cliPath, 'build');
});

runSmokeTest(['public', 'index'], LABEL);

describe('Markdown Rendering', function() {
let html;

before(async function() {
html = await fs.readFile(path.resolve(this.context.publicDir, 'index.html'), 'utf-8');
});

it('should correctly render out code fences with HTML entities preserved', function() {
expect(html).to.contain('<x-card>');
});
});

});

after(function() {
runner.teardown(getOutputTeardownFiles(outputPath));
});

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
prerender: true
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default class CopyToClipboardBlock extends HTMLElement {

}

customElements.define('x-ctc', CopyToClipboardBlock);
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
imports:
- /components/x-ctc.js
---

## Server Rendering

You will need to use version <= 20.6.0.

<x-ctc>

```js
import "../components/card/card.js"; // <x-card></x-card>

export default class UsersPage extends HTMLElement {
async connectedCallback() {
const users = await fetch("https://www.example.com/api/users").then((resp) => resp.json());
const html = users
.map((user) => {
const { name, imageUrl } = user;
return `
<x-card>
<h2 slot="title">${name}</h2>
<img slot="image" src="${imageUrl}" alt="${name}"/>
</x-card>
`;
})
.join("");

this.innerHTML = html;
}
}
```

</x-ctc>
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* Use Case
* Run Greenwood with custom markdown preset in greenwood config.
* Run Greenwood with markdown content.
*
* User Result
* Should generate a bare bones Greenwood build. (same as build.default.spec.js) with custom markdown and rehype links
* Should generate a bare bones Greenwood build with markdown correctly transformed.
*
* User Command
* greenwood build
Expand All @@ -12,7 +12,9 @@
* None
*
* User Workspace
* Greenwood default
* src/
* pages/
* index.md
*/
import { JSDOM } from 'jsdom';
import path from 'path';
Expand Down

0 comments on commit 7fd7dc3

Please sign in to comment.