-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug/issue 1375 preserve HTML entities when prerendering markdown (#1376)
- Loading branch information
1 parent
0133290
commit 7fd7dc3
Showing
5 changed files
with
121 additions
and
3 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
...es/cli/test/cases/build.config.prerender-markdown/build.config.prerender-markdown.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); | ||
|
||
}); |
3 changes: 3 additions & 0 deletions
3
packages/cli/test/cases/build.config.prerender-markdown/greenwood.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default { | ||
prerender: true | ||
}; |
5 changes: 5 additions & 0 deletions
5
packages/cli/test/cases/build.config.prerender-markdown/src/components/x-ctc.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
35 changes: 35 additions & 0 deletions
35
packages/cli/test/cases/build.config.prerender-markdown/src/pages/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters