summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/astro/components/Markdown.astro12
-rw-r--r--packages/astro/test/astro-markdown-shiki.test.js6
-rw-r--r--packages/astro/test/astro-markdown.test.js17
-rw-r--r--packages/astro/test/fixtures/astro-markdown/src/pages/nested-list.astro32
4 files changed, 61 insertions, 6 deletions
diff --git a/packages/astro/components/Markdown.astro b/packages/astro/components/Markdown.astro
index feff437a6..fc666218d 100644
--- a/packages/astro/components/Markdown.astro
+++ b/packages/astro/components/Markdown.astro
@@ -3,11 +3,17 @@ export interface Props {
content?: string;
}
-const dedent = (str: string) =>
- str
+const dedent = (str: string) => {
+ const _str = str.split('\n').filter(s => s.trimStart().length > 0);
+ if (_str.length === 0) {
+ return str.trimStart();
+ }
+ const trimmedSpace = _str[0].replace(_str[0].trimStart(), '');
+ return str
.split('\n')
- .map((ln) => ln.trimStart())
+ .map((ln) => ln.startsWith(trimmedSpace) ? ln.replace(trimmedSpace, '') : ln)
.join('\n');
+}
// Internal props that should not be part of the external interface.
interface InternalProps extends Props {
diff --git a/packages/astro/test/astro-markdown-shiki.test.js b/packages/astro/test/astro-markdown-shiki.test.js
index 0f909c11f..f98b5413b 100644
--- a/packages/astro/test/astro-markdown-shiki.test.js
+++ b/packages/astro/test/astro-markdown-shiki.test.js
@@ -118,9 +118,9 @@ describe('Astro Markdown Shiki', () => {
const $ = cheerio.load(html);
const segments = $('.line').get(6).children;
- expect(segments).to.have.lengthOf(2);
- expect(segments[0].attribs.style).to.be.equal('color: #79C0FF');
- expect(segments[1].attribs.style).to.be.equal('color: #C9D1D9');
+ expect(segments).to.have.lengthOf(3);
+ expect(segments[0].attribs.style).to.be.equal('color: #C9D1D9');
+ expect(segments[1].attribs.style).to.be.equal('color: #79C0FF');
});
});
diff --git a/packages/astro/test/astro-markdown.test.js b/packages/astro/test/astro-markdown.test.js
index 8f1878914..2bccf8d87 100644
--- a/packages/astro/test/astro-markdown.test.js
+++ b/packages/astro/test/astro-markdown.test.js
@@ -146,4 +146,21 @@ describe('Astro Markdown', () => {
// render html without error
expect(html).to.be.ok;
});
+
+ it('can render nested list correctly', async () => {
+ const html = await fixture.readFile('/nested-list/index.html');
+ const $ = cheerio.load(html);
+ /**
+ * - list
+ * - list
+ */
+ expect($('#target > ul > li').children()).to.have.lengthOf(1);
+ expect($('#target > ul > li > ul > li').text()).to.equal('nested list');
+ /**
+ * 1. Hello
+ * 1. nested hello
+ */
+ expect($('#target > ol > li').children()).to.have.lengthOf(1);
+ expect($('#target > ol > li > ol > li').text()).to.equal('nested hello');
+ });
});
diff --git a/packages/astro/test/fixtures/astro-markdown/src/pages/nested-list.astro b/packages/astro/test/fixtures/astro-markdown/src/pages/nested-list.astro
new file mode 100644
index 000000000..32a0f2916
--- /dev/null
+++ b/packages/astro/test/fixtures/astro-markdown/src/pages/nested-list.astro
@@ -0,0 +1,32 @@
+---
+// Component imports and setup JavaScript go here!
+import { Markdown } from 'astro/components';
+const content = `
+- list 1
+ - list 2
+- list
+ - - list
+1. Hello
+ 1. Hello`
+---
+
+<html lang="en">
+ <head>
+ <meta charset="utf-8" />
+ <meta name="viewport" content="width=device-width" />
+ <title>Welcome to Astro</title>
+ </head>
+
+ <body>
+ <h1>Welcome to <a href="https://astro.build/">Astro</a></h1>
+ <div id="target">
+ <Markdown>
+ - list
+ - nested list
+
+ 1. Hello
+ 1. nested hello
+ </Markdown>
+ </div>
+ </body>
+</html>