diff --git a/.changeset/forty-scissors-jog.md b/.changeset/forty-scissors-jog.md new file mode 100644 index 0000000000..3637b08025 --- /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 450285bcf7..abaeb5a964 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 79d0d7358b..001e6da062 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 0000000000..408e036c7a --- /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 0000000000..02fd6788f3 --- /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 0000000000..2180e7a47b --- /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 0000000000..88fc531fa2 --- /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(); +--- + + + +
+ + + +