mirror of
https://github.com/withastro/astro.git
synced 2024-12-30 22:03:56 -05:00
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>
This commit is contained in:
parent
3b94324228
commit
eb303e1ad5
9 changed files with 84 additions and 0 deletions
5
.changeset/forty-scissors-jog.md
Normal file
5
.changeset/forty-scissors-jog.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/markdoc': patch
|
||||
---
|
||||
|
||||
Adds support for markdown-it's typographer option
|
|
@ -1,4 +1,5 @@
|
|||
export interface MarkdocIntegrationOptions {
|
||||
allowHTML?: boolean;
|
||||
ignoreIndentation?: boolean;
|
||||
typographer?: boolean;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
7
packages/integrations/markdoc/test/fixtures/render-typographer/astro.config.mjs
vendored
Normal file
7
packages/integrations/markdoc/test/fixtures/render-typographer/astro.config.mjs
vendored
Normal file
|
@ -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 })],
|
||||
});
|
9
packages/integrations/markdoc/test/fixtures/render-typographer/package.json
vendored
Normal file
9
packages/integrations/markdoc/test/fixtures/render-typographer/package.json
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"name": "@test/markdoc-render-typographer",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@astrojs/markdoc": "workspace:*",
|
||||
"astro": "workspace:*"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
title: Typographer
|
||||
---
|
||||
|
||||
## Typographer's post
|
||||
|
||||
This is a post to test the "typographer" option.
|
19
packages/integrations/markdoc/test/fixtures/render-typographer/src/pages/index.astro
vendored
Normal file
19
packages/integrations/markdoc/test/fixtures/render-typographer/src/pages/index.astro
vendored
Normal file
|
@ -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>
|
|
@ -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.');
|
||||
}
|
||||
|
|
|
@ -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':
|
||||
|
|
Loading…
Reference in a new issue