2022-06-03 13:38:45 +00:00
|
|
|
import { renderMarkdown } from '../dist/index.js';
|
|
|
|
import chai from 'chai';
|
|
|
|
|
2022-07-22 22:45:16 +00:00
|
|
|
describe('strictness in Astro-flavored markdown', () => {
|
|
|
|
const renderAstroMd = (text, opts) => renderMarkdown(text, { isAstroFlavoredMd: true, ...opts });
|
|
|
|
|
2022-06-03 13:38:45 +00:00
|
|
|
it('should allow self-closing HTML tags (void elements)', async () => {
|
2022-07-22 22:45:16 +00:00
|
|
|
const { code } = await renderAstroMd(
|
2022-06-03 13:38:45 +00:00
|
|
|
`Use self-closing void elements<br>like word<wbr>break and images: <img src="hi.jpg">`,
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
|
2022-06-03 13:39:43 +00:00
|
|
|
chai
|
|
|
|
.expect(code)
|
|
|
|
.to.equal(
|
|
|
|
`<p>Use self-closing void elements<br />like word<wbr />break and images: ` +
|
|
|
|
`<img src="hi.jpg" /></p>`
|
|
|
|
);
|
2022-06-03 13:38:45 +00:00
|
|
|
});
|
2022-06-08 17:41:36 +00:00
|
|
|
|
|
|
|
it('should allow attribute names starting with ":" after element names', async () => {
|
2022-07-22 22:45:16 +00:00
|
|
|
const { code } = await renderAstroMd(`<div :class="open ? '' : 'hidden'">Test</div>`, {});
|
2022-06-08 17:41:36 +00:00
|
|
|
|
2022-06-08 17:43:10 +00:00
|
|
|
chai.expect(code.trim()).to.equal(`<div :class="open ? '' : 'hidden'">Test</div>`);
|
2022-06-08 17:41:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should allow attribute names starting with ":" after local element names', async () => {
|
2022-07-22 22:45:16 +00:00
|
|
|
const { code } = await renderAstroMd(`<div.abc :class="open ? '' : 'hidden'">x</div.abc>`, {});
|
2022-06-08 17:41:36 +00:00
|
|
|
|
2022-06-08 17:43:10 +00:00
|
|
|
chai.expect(code.trim()).to.equal(`<div.abc :class="open ? '' : 'hidden'">x</div.abc>`);
|
2022-06-08 17:41:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should allow attribute names starting with ":" after attribute names', async () => {
|
2022-07-22 22:45:16 +00:00
|
|
|
const { code } = await renderAstroMd(`<input type="text" disabled :placeholder="hi">`, {});
|
2022-06-08 17:41:36 +00:00
|
|
|
|
2022-06-08 17:43:10 +00:00
|
|
|
chai.expect(code.trim()).to.equal(`<input type="text" disabled :placeholder="hi" />`);
|
2022-06-08 17:41:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should allow attribute names starting with ":" after local attribute names', async () => {
|
2022-07-22 22:45:16 +00:00
|
|
|
const { code } = await renderAstroMd(
|
2022-06-08 17:41:36 +00:00
|
|
|
`<input type="text" x-test:disabled :placeholder="hi">`,
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
|
2022-06-08 17:43:10 +00:00
|
|
|
chai.expect(code.trim()).to.equal(`<input type="text" x-test:disabled :placeholder="hi" />`);
|
2022-06-08 17:41:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should allow attribute names starting with ":" after attribute values', async () => {
|
2022-07-22 22:45:16 +00:00
|
|
|
const { code } = await renderAstroMd(`<input type="text" :placeholder="placeholder">`, {});
|
2022-06-08 17:41:36 +00:00
|
|
|
|
2022-06-08 17:43:10 +00:00
|
|
|
chai.expect(code.trim()).to.equal(`<input type="text" :placeholder="placeholder" />`);
|
2022-06-08 17:41:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should allow attribute names starting with "@" after element names', async () => {
|
2022-07-22 22:45:16 +00:00
|
|
|
const { code } = await renderAstroMd(`<button @click="handleClick">Test</button>`, {});
|
2022-06-08 17:41:36 +00:00
|
|
|
|
2022-06-08 17:43:10 +00:00
|
|
|
chai.expect(code.trim()).to.equal(`<button @click="handleClick">Test</button>`);
|
2022-06-08 17:41:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should allow attribute names starting with "@" after local element names', async () => {
|
2022-07-22 22:45:16 +00:00
|
|
|
const { code } = await renderAstroMd(
|
2022-06-08 17:41:36 +00:00
|
|
|
`<button.local @click="handleClick">Test</button.local>`,
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
|
2022-06-08 17:43:10 +00:00
|
|
|
chai.expect(code.trim()).to.equal(`<button.local @click="handleClick">Test</button.local>`);
|
2022-06-08 17:41:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should allow attribute names starting with "@" after attribute names', async () => {
|
2022-07-22 22:45:16 +00:00
|
|
|
const { code } = await renderAstroMd(
|
2022-06-08 17:41:36 +00:00
|
|
|
`<button disabled @click="handleClick">Test</button>`,
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
|
2022-06-08 17:43:10 +00:00
|
|
|
chai.expect(code.trim()).to.equal(`<button disabled @click="handleClick">Test</button>`);
|
2022-06-08 17:41:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should allow attribute names starting with "@" after local attribute names', async () => {
|
2022-07-22 22:45:16 +00:00
|
|
|
const { code } = await renderAstroMd(
|
2022-06-08 17:41:36 +00:00
|
|
|
`<button x-test:disabled @click="handleClick">Test</button>`,
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
|
2022-06-08 17:43:10 +00:00
|
|
|
chai.expect(code.trim()).to.equal(`<button x-test:disabled @click="handleClick">Test</button>`);
|
2022-06-08 17:41:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should allow attribute names starting with "@" after attribute values', async () => {
|
2022-07-22 22:45:16 +00:00
|
|
|
const { code } = await renderAstroMd(
|
2022-06-08 17:41:36 +00:00
|
|
|
`<button type="submit" @click="handleClick">Test</button>`,
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
|
2022-06-08 17:43:10 +00:00
|
|
|
chai.expect(code.trim()).to.equal(`<button type="submit" @click="handleClick">Test</button>`);
|
2022-06-08 17:41:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should allow attribute names containing dots', async () => {
|
2022-07-22 22:45:16 +00:00
|
|
|
const { code } = await renderAstroMd(`<input x-on:input.debounce.500ms="fetchResults">`, {});
|
2022-06-08 17:41:36 +00:00
|
|
|
|
2022-06-08 17:43:10 +00:00
|
|
|
chai.expect(code.trim()).to.equal(`<input x-on:input.debounce.500ms="fetchResults" />`);
|
2022-06-08 17:41:36 +00:00
|
|
|
});
|
2022-06-03 13:38:45 +00:00
|
|
|
});
|