aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Peter Schilling <peter@schpet.com> 2024-07-17 05:14:35 -0700
committerGravatar GitHub <noreply@github.com> 2024-07-17 14:14:35 +0200
commiteb303e1ad5dade7787c0d9bbb520c21292cf3950 (patch)
tree731a9f9876f555b920c5f9f0ca88d26e92f73fd3
parent3b94324228b5b587cadf766a8e112dec3f33642b (diff)
downloadastro-eb303e1ad5dade7787c0d9bbb520c21292cf3950.tar.gz
astro-eb303e1ad5dade7787c0d9bbb520c21292cf3950.tar.zst
astro-eb303e1ad5dade7787c0d9bbb520c21292cf3950.zip
feat(markdoc): Support markdown-it's typographer option (#11450)
* Support markdoc-it's typographer option in markdoc * Update .changeset/forty-scissors-jog.md [skip ci] * Update .changeset/forty-scissors-jog.md [skip ci] * Fix typo in changeset --------- Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com> Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
-rw-r--r--.changeset/forty-scissors-jog.md5
-rw-r--r--packages/integrations/markdoc/src/options.ts1
-rw-r--r--packages/integrations/markdoc/src/tokenizer.ts5
-rw-r--r--packages/integrations/markdoc/test/fixtures/render-typographer/astro.config.mjs7
-rw-r--r--packages/integrations/markdoc/test/fixtures/render-typographer/package.json9
-rw-r--r--packages/integrations/markdoc/test/fixtures/render-typographer/src/content/blog/typographer.mdoc7
-rw-r--r--packages/integrations/markdoc/test/fixtures/render-typographer/src/pages/index.astro19
-rw-r--r--packages/integrations/markdoc/test/render.test.js22
-rw-r--r--pnpm-lock.yaml9
9 files changed, 84 insertions, 0 deletions
diff --git a/.changeset/forty-scissors-jog.md b/.changeset/forty-scissors-jog.md
new file mode 100644
index 000000000..3637b0802
--- /dev/null
+++ b/.changeset/forty-scissors-jog.md
@@ -0,0 +1,5 @@
+---
+'@astrojs/markdoc': patch
+---
+
+Adds support for markdown-it's typographer option
diff --git a/packages/integrations/markdoc/src/options.ts b/packages/integrations/markdoc/src/options.ts
index 450285bcf..abaeb5a96 100644
--- a/packages/integrations/markdoc/src/options.ts
+++ b/packages/integrations/markdoc/src/options.ts
@@ -1,4 +1,5 @@
export interface MarkdocIntegrationOptions {
allowHTML?: boolean;
ignoreIndentation?: boolean;
+ typographer?: boolean;
}
diff --git a/packages/integrations/markdoc/src/tokenizer.ts b/packages/integrations/markdoc/src/tokenizer.ts
index 79d0d7358..001e6da06 100644
--- a/packages/integrations/markdoc/src/tokenizer.ts
+++ b/packages/integrations/markdoc/src/tokenizer.ts
@@ -24,6 +24,11 @@ export function getMarkdocTokenizer(options: MarkdocIntegrationOptions | undefin
// allow indentation so nested Markdoc tags can be formatted for better readability
tokenizerOptions.allowIndentation = true;
}
+ if (options?.typographer) {
+ // enable typographer to convert straight quotes to curly quotes, etc.
+ tokenizerOptions.typographer = options.typographer;
+ }
+
_cachedMarkdocTokenizers[key] = new Markdoc.Tokenizer(tokenizerOptions);
}
diff --git a/packages/integrations/markdoc/test/fixtures/render-typographer/astro.config.mjs b/packages/integrations/markdoc/test/fixtures/render-typographer/astro.config.mjs
new file mode 100644
index 000000000..408e036c7
--- /dev/null
+++ b/packages/integrations/markdoc/test/fixtures/render-typographer/astro.config.mjs
@@ -0,0 +1,7 @@
+import markdoc from '@astrojs/markdoc';
+import { defineConfig } from 'astro/config';
+
+// https://astro.build/config
+export default defineConfig({
+ integrations: [markdoc({ typographer: true })],
+});
diff --git a/packages/integrations/markdoc/test/fixtures/render-typographer/package.json b/packages/integrations/markdoc/test/fixtures/render-typographer/package.json
new file mode 100644
index 000000000..02fd6788f
--- /dev/null
+++ b/packages/integrations/markdoc/test/fixtures/render-typographer/package.json
@@ -0,0 +1,9 @@
+{
+ "name": "@test/markdoc-render-typographer",
+ "version": "0.0.0",
+ "private": true,
+ "dependencies": {
+ "@astrojs/markdoc": "workspace:*",
+ "astro": "workspace:*"
+ }
+}
diff --git a/packages/integrations/markdoc/test/fixtures/render-typographer/src/content/blog/typographer.mdoc b/packages/integrations/markdoc/test/fixtures/render-typographer/src/content/blog/typographer.mdoc
new file mode 100644
index 000000000..2180e7a47
--- /dev/null
+++ b/packages/integrations/markdoc/test/fixtures/render-typographer/src/content/blog/typographer.mdoc
@@ -0,0 +1,7 @@
+---
+title: Typographer
+---
+
+## Typographer's post
+
+This is a post to test the "typographer" option.
diff --git a/packages/integrations/markdoc/test/fixtures/render-typographer/src/pages/index.astro b/packages/integrations/markdoc/test/fixtures/render-typographer/src/pages/index.astro
new file mode 100644
index 000000000..88fc531fa
--- /dev/null
+++ b/packages/integrations/markdoc/test/fixtures/render-typographer/src/pages/index.astro
@@ -0,0 +1,19 @@
+---
+import { getEntryBySlug } from "astro:content";
+
+const post = await getEntryBySlug('blog', 'typographer');
+const { Content } = await post.render();
+---
+
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Content</title>
+</head>
+<body>
+ <Content />
+</body>
+</html>
diff --git a/packages/integrations/markdoc/test/render.test.js b/packages/integrations/markdoc/test/render.test.js
index d439adcd2..4c6d1b415 100644
--- a/packages/integrations/markdoc/test/render.test.js
+++ b/packages/integrations/markdoc/test/render.test.js
@@ -117,6 +117,15 @@ describe('Markdoc - render', () => {
renderWithRootFolderContainingSpace(html);
});
+
+ it('renders content - with typographer option', async () => {
+ const fixture = await getFixture('render-typographer');
+ await fixture.build()
+
+ const html = await fixture.readFile('/index.html');
+
+ renderTypographerChecks(html);
+ });
});
});
@@ -173,3 +182,16 @@ function renderWithRootFolderContainingSpace(html) {
const p = document.querySelector('p');
assert.equal(p.textContent, 'This is a simple Markdoc post with root folder containing a space.');
}
+
+/**
+ * @param {string} html
+ */
+function renderTypographerChecks(html) {
+ const { document } = parseHTML(html);
+
+ const h2 = document.querySelector('h2');
+ assert.equal(h2.textContent, 'Typographer’s post');
+
+ const p = document.querySelector('p');
+ assert.equal(p.textContent, 'This is a post to test the “typographer” option.');
+}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 2031e768b..061a60598 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -4597,6 +4597,15 @@ importers:
specifier: workspace:*
version: link:../../../../../astro
+ packages/integrations/markdoc/test/fixtures/render-typographer:
+ dependencies:
+ '@astrojs/markdoc':
+ specifier: workspace:*
+ version: link:../../..
+ astro:
+ specifier: workspace:*
+ version: link:../../../../../astro
+
packages/integrations/markdoc/test/fixtures/render-with-components:
dependencies:
'@astrojs/markdoc':