@astrojs/markdoc 0.0.0-data-collections-20230418125011 → 0.0.0-debug-missing-endpoint-20240209155111

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/LICENSE +0 -2
  2. package/README.md +21 -309
  3. package/components/Renderer.astro +8 -1
  4. package/components/TreeNode.ts +101 -22
  5. package/dist/config.d.ts +57 -2
  6. package/dist/config.js +21 -1
  7. package/dist/content-entry-type.d.ts +8 -0
  8. package/dist/content-entry-type.js +209 -0
  9. package/dist/extensions/prism.d.ts +2 -0
  10. package/dist/extensions/prism.js +21 -0
  11. package/dist/extensions/shiki.d.ts +3 -0
  12. package/dist/extensions/shiki.js +21 -0
  13. package/dist/heading-ids.d.ts +10 -0
  14. package/dist/heading-ids.js +55 -0
  15. package/dist/html/css/parse-inline-css-to-react.d.ts +1 -0
  16. package/dist/html/css/parse-inline-css-to-react.js +21 -0
  17. package/dist/html/css/parse-inline-styles.d.ts +8 -0
  18. package/dist/html/css/parse-inline-styles.js +153 -0
  19. package/dist/html/css/style-to-object.d.ts +12 -0
  20. package/dist/html/css/style-to-object.js +53 -0
  21. package/dist/html/index.d.ts +2 -0
  22. package/dist/html/index.js +6 -0
  23. package/dist/html/tagdefs/html.tag.d.ts +2 -0
  24. package/dist/html/tagdefs/html.tag.js +21 -0
  25. package/dist/html/transform/html-token-transform.d.ts +3 -0
  26. package/dist/html/transform/html-token-transform.js +154 -0
  27. package/dist/index.d.ts +2 -1
  28. package/dist/index.js +26 -101
  29. package/dist/load-config.d.ts +6 -12
  30. package/dist/load-config.js +11 -2
  31. package/dist/options.d.ts +4 -0
  32. package/dist/options.js +0 -0
  33. package/dist/{experimental-assets-config.d.ts → runtime-assets-config.d.ts} +1 -1
  34. package/dist/{experimental-assets-config.js → runtime-assets-config.js} +2 -2
  35. package/dist/runtime.d.ts +29 -0
  36. package/dist/runtime.js +152 -0
  37. package/dist/tokenizer.d.ts +3 -0
  38. package/dist/tokenizer.js +27 -0
  39. package/dist/utils.d.ts +13 -7
  40. package/dist/utils.js +19 -32
  41. package/package.json +54 -22
  42. package/template/content-module-types.d.ts +1 -0
  43. package/.turbo/turbo-build.log +0 -5
  44. package/CHANGELOG.md +0 -129
  45. package/dist/default-config.d.ts +0 -5
  46. package/dist/default-config.js +0 -13
  47. package/src/config.ts +0 -5
  48. package/src/default-config.ts +0 -18
  49. package/src/experimental-assets-config.ts +0 -29
  50. package/src/index.ts +0 -164
  51. package/src/load-config.ts +0 -102
  52. package/src/utils.ts +0 -98
  53. package/test/content-collections.test.js +0 -110
  54. package/test/entry-prop.test.js +0 -58
  55. package/test/fixtures/content-collections/astro.config.mjs +0 -7
  56. package/test/fixtures/content-collections/node_modules/.bin/astro +0 -17
  57. package/test/fixtures/content-collections/package.json +0 -9
  58. package/test/fixtures/content-collections/src/content/blog/post-1.mdoc +0 -7
  59. package/test/fixtures/content-collections/src/content/blog/post-2.mdoc +0 -7
  60. package/test/fixtures/content-collections/src/content/blog/post-3.mdoc +0 -7
  61. package/test/fixtures/content-collections/src/content/config.ts +0 -12
  62. package/test/fixtures/content-collections/src/pages/collection.json.js +0 -10
  63. package/test/fixtures/content-collections/src/pages/entry.json.js +0 -10
  64. package/test/fixtures/content-collections/utils.js +0 -8
  65. package/test/fixtures/entry-prop/astro.config.mjs +0 -7
  66. package/test/fixtures/entry-prop/node_modules/.bin/astro +0 -17
  67. package/test/fixtures/entry-prop/package.json +0 -9
  68. package/test/fixtures/entry-prop/src/content/blog/entry.mdoc +0 -9
  69. package/test/fixtures/entry-prop/src/content/config.ts +0 -9
  70. package/test/fixtures/entry-prop/src/pages/index.astro +0 -19
  71. package/test/fixtures/image-assets/astro.config.mjs +0 -10
  72. package/test/fixtures/image-assets/node_modules/.bin/astro +0 -17
  73. package/test/fixtures/image-assets/package.json +0 -9
  74. package/test/fixtures/image-assets/src/assets/alias/cityscape.jpg +0 -0
  75. package/test/fixtures/image-assets/src/assets/relative/oar.jpg +0 -0
  76. package/test/fixtures/image-assets/src/content/docs/intro.mdoc +0 -7
  77. package/test/fixtures/image-assets/src/pages/index.astro +0 -19
  78. package/test/fixtures/image-assets/src/public/favicon.svg +0 -9
  79. package/test/fixtures/render-null/astro.config.mjs +0 -7
  80. package/test/fixtures/render-null/markdoc.config.mjs +0 -26
  81. package/test/fixtures/render-null/node_modules/.bin/astro +0 -17
  82. package/test/fixtures/render-null/package.json +0 -9
  83. package/test/fixtures/render-null/src/content/blog/render-null.mdoc +0 -7
  84. package/test/fixtures/render-null/src/pages/index.astro +0 -19
  85. package/test/fixtures/render-simple/astro.config.mjs +0 -7
  86. package/test/fixtures/render-simple/node_modules/.bin/astro +0 -17
  87. package/test/fixtures/render-simple/package.json +0 -9
  88. package/test/fixtures/render-simple/src/content/blog/simple.mdoc +0 -7
  89. package/test/fixtures/render-simple/src/pages/index.astro +0 -19
  90. package/test/fixtures/render-with-components/astro.config.mjs +0 -7
  91. package/test/fixtures/render-with-components/markdoc.config.mjs +0 -28
  92. package/test/fixtures/render-with-components/node_modules/.bin/astro +0 -17
  93. package/test/fixtures/render-with-components/package.json +0 -12
  94. package/test/fixtures/render-with-components/src/components/Code.astro +0 -12
  95. package/test/fixtures/render-with-components/src/components/CustomMarquee.astro +0 -1
  96. package/test/fixtures/render-with-components/src/content/blog/with-components.mdoc +0 -17
  97. package/test/fixtures/render-with-components/src/pages/index.astro +0 -19
  98. package/test/fixtures/render-with-config/astro.config.mjs +0 -7
  99. package/test/fixtures/render-with-config/markdoc.config.mjs +0 -15
  100. package/test/fixtures/render-with-config/node_modules/.bin/astro +0 -17
  101. package/test/fixtures/render-with-config/package.json +0 -9
  102. package/test/fixtures/render-with-config/src/content/blog/with-config.mdoc +0 -13
  103. package/test/fixtures/render-with-config/src/pages/index.astro +0 -19
  104. package/test/image-assets.test.js +0 -76
  105. package/test/render.test.js +0 -150
  106. package/tsconfig.json +0 -10
package/LICENSE CHANGED
@@ -20,7 +20,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
22
22
 
23
-
24
23
  """
25
24
  This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/sveltejs/kit repository:
26
25
 
@@ -33,7 +32,6 @@ The above copyright notice and this permission notice shall be included in all c
33
32
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34
33
  """
35
34
 
36
-
37
35
  """
38
36
  This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/vitejs/vite repository:
39
37
 
package/README.md CHANGED
@@ -2,325 +2,37 @@
2
2
 
3
3
  This **[Astro integration][astro-integration]** enables the usage of [Markdoc](https://markdoc.dev/) to create components, pages, and content collection entries.
4
4
 
5
- - <strong>[Why Markdoc?](#why-markdoc)</strong>
6
- - <strong>[Installation](#installation)</strong>
7
- - <strong>[Usage](#usage)</strong>
8
- - <strong>[Configuration](#configuration)</strong>
9
- - <strong>[Examples](#examples)</strong>
10
- - <strong>[Troubleshooting](#troubleshooting)</strong>
11
- - <strong>[Contributing](#contributing)</strong>
12
- - <strong>[Changelog](#changelog)</strong>
5
+ ## Documentation
13
6
 
14
- ## Why Markdoc?
7
+ Read the [`@astrojs/markdoc` docs][docs]
15
8
 
16
- Markdoc allows you to enhance your Markdown with [Astro components][astro-components]. If you have existing content authored in Markdoc, this integration allows you to bring those files to your Astro project using content collections.
9
+ ## Support
17
10
 
18
- ## Installation
11
+ - Get help in the [Astro Discord][discord]. Post questions in our `#support` forum, or visit our dedicated `#dev` channel to discuss current development and more!
19
12
 
20
- ### Quick Install
13
+ - Check our [Astro Integration Documentation][astro-integration] for more on integrations.
21
14
 
22
- The `astro add` command-line tool automates the installation for you. Run one of the following commands in a new terminal window. (If you aren't sure which package manager you're using, run the first command.) Then, follow the prompts, and type "y" in the terminal (meaning "yes") for each one.
23
-
24
- ```sh
25
- # Using NPM
26
- npx astro add markdoc
27
- # Using Yarn
28
- yarn astro add markdoc
29
- # Using PNPM
30
- pnpm astro add markdoc
31
- ```
32
-
33
- If you run into any issues, [feel free to report them to us on GitHub](https://github.com/withastro/astro/issues) and try the manual installation steps below.
34
-
35
- ### Manual Install
36
-
37
- First, install the `@astrojs/markdoc` package using your package manager. If you're using npm or aren't sure, run this in the terminal:
38
-
39
- ```sh
40
- npm install @astrojs/markdoc
41
- ```
42
-
43
- Then, apply this integration to your `astro.config.*` file using the `integrations` property:
44
-
45
- __`astro.config.mjs`__
46
-
47
- ```js ins={2} "markdoc()"
48
- import { defineConfig } from 'astro/config';
49
- import markdoc from '@astrojs/markdoc';
50
-
51
- export default defineConfig({
52
- // ...
53
- integrations: [markdoc()],
54
- });
55
- ```
56
-
57
-
58
- ### Editor Integration
59
-
60
- [VS Code](https://code.visualstudio.com/) supports Markdown by default. However, for Markdoc editor support, you may wish to add the following setting in your VSCode config. This ensures authoring Markdoc files provides a Markdown-like editor experience.
61
-
62
- ```json title=".vscode/settings.json"
63
- "files.associations": {
64
- "*.mdoc": "markdown"
65
- }
66
- ```
67
-
68
- ## Usage
69
-
70
- Markdoc files can only be used within content collections. Add entries to any content collection using the `.mdoc` extension:
71
-
72
- ```sh
73
- src/content/docs/
74
- why-markdoc.mdoc
75
- quick-start.mdoc
76
- ```
77
-
78
- Then, query your collection using the [Content Collection APIs](https://docs.astro.build/en/guides/content-collections/#querying-collections):
79
-
80
- ```astro
81
- ---
82
- import { getEntryBySlug } from 'astro:content';
83
-
84
- const entry = await getEntryBySlug('docs', 'why-markdoc');
85
- const { Content } = await entry.render();
86
- ---
87
-
88
- <!--Access frontmatter properties with `data`-->
89
- <h1>{entry.data.title}</h1>
90
- <!--Render Markdoc contents with the Content component-->
91
- <Content />
92
- ```
93
-
94
- 📚 See the [Astro Content Collection docs][astro-content-collections] for more information.
95
-
96
- ## Configuration
97
-
98
- `@astrojs/markdoc` offers configuration options to use all of Markdoc's features and connect UI components to your content.
99
-
100
- ### Using components
101
-
102
- You can add Astro components to your Markdoc using both [Markdoc tags][markdoc-tags] and HTML element [nodes][markdoc-nodes].
103
-
104
- #### Render Markdoc tags as Astro components
105
-
106
- You may configure [Markdoc tags][markdoc-tags] that map to components. You can configure a new tag by creating a `markdoc.config.mjs|ts` file at the root of your project and configuring the `tag` attribute.
107
-
108
- This example renders an `Aside` component, and allows a `type` prop to be passed as a string:
109
-
110
- ```js
111
- // markdoc.config.mjs
112
- import { defineMarkdocConfig } from '@astrojs/markdoc/config';
113
- import Aside from './src/components/Aside.astro';
114
-
115
- export default defineMarkdocConfig({
116
- tags: {
117
- aside: {
118
- render: Aside,
119
- attributes: {
120
- // Markdoc requires type defs for each attribute.
121
- // These should mirror the `Props` type of the component
122
- // you are rendering.
123
- // See Markdoc's documentation on defining attributes
124
- // https://markdoc.dev/docs/attributes#defining-attributes
125
- type: { type: String },
126
- }
127
- },
128
- },
129
- })
130
- ```
131
-
132
- This component can now be used in your Markdoc files with the `{% aside %}` tag. Children will be passed to your component's default slot:
133
-
134
- ```md
135
- # Welcome to Markdoc 👋
136
-
137
- {% aside type="tip" %}
138
-
139
- Use tags like this fancy "aside" to add some *flair* to your docs.
140
-
141
- {% /aside %}
142
- ```
143
-
144
- #### Render Markdoc nodes / HTML elements as Astro components
145
-
146
- You may also want to map standard HTML elements like headings and paragraphs to components. For this, you can configure a custom [Markdoc node][markdoc-nodes]. This example overrides Markdoc's `heading` node to render a `Heading` component, passing the built-in `level` attribute as a prop:
147
-
148
- ```js
149
- // markdoc.config.mjs
150
- import { defineMarkdocConfig } from '@astrojs/markdoc/config';
151
- import Heading from './src/components/Heading.astro';
152
-
153
- export default defineMarkdocConfig({
154
- nodes: {
155
- heading: {
156
- render: Heading,
157
- attributes: {
158
- // Pass the attributes from Markdoc's default heading node
159
- // as component props.
160
- level: { type: String },
161
- }
162
- },
163
- },
164
- })
165
- ```
166
-
167
- Now, all Markdown headings will render with the `Heading.astro` component. This example uses a level 3 heading, automatically passing `level: 3` as the component prop:
168
-
169
- ```md
170
- ### I'm a level 3 heading!
171
- ```
172
-
173
- 📚 [Find all of Markdoc's built-in nodes and node attributes on their documentation.](https://markdoc.dev/docs/nodes#built-in-nodes)
174
-
175
- #### Use client-side UI components
176
-
177
- Today, the `components` prop does not support the `client:` directive for hydrating components. To embed client-side components, create a wrapper `.astro` file to import your component and apply a `client:` directive manually.
178
-
179
- This example wraps a `Aside.tsx` component with a `ClientAside.astro` wrapper:
180
-
181
- ```astro
182
- ---
183
- // src/components/ClientAside.astro
184
- import Aside from './Aside';
185
- ---
186
-
187
- <Aside {...Astro.props} client:load />
188
- ```
189
-
190
- This component can be passed to the `render` prop for any [tag][markdoc-tags] or [node][markdoc-nodes] in your config:
191
-
192
- ```js
193
- // markdoc.config.mjs
194
- import { defineMarkdocConfig } from '@astrojs/markdoc/config';
195
- import Aside from './src/components/Aside.astro';
196
-
197
- export default defineMarkdocConfig({
198
- tags: {
199
- aside: {
200
- render: Aside,
201
- attributes: {
202
- type: { type: String },
203
- }
204
- },
205
- },
206
- })
207
- ```
208
-
209
- ### Access frontmatter and content collection information from your templates
210
-
211
- You can access content collection information from your Markdoc templates using the `$entry` variable. This includes the entry `slug`, `collection` name, and frontmatter `data` parsed by your content collection schema (if any). This example renders the `title` frontmatter property as a heading:
212
-
213
- ```md
214
- ---
215
- title: Welcome to Markdoc 👋
216
- ---
217
-
218
- # {% $entry.data.title %}
219
- ```
220
-
221
- The `$entry` object matches [the `CollectionEntry` type](https://docs.astro.build/en/reference/api-reference/#collection-entry-type), excluding the `.render()` property.
222
-
223
- ### Markdoc config
224
-
225
- The `markdoc.config.mjs|ts` file accepts [all Markdoc configuration options](https://markdoc.dev/docs/config), including [tags](https://markdoc.dev/docs/tags) and [functions](https://markdoc.dev/docs/functions).
226
-
227
- You can pass these options from the default export in your `markdoc.config.mjs|ts` file:
228
-
229
- ```js
230
- // markdoc.config.mjs
231
- import { defineMarkdocConfig } from '@astrojs/markdoc/config';
232
-
233
- export default defineMarkdocConfig({
234
- functions: {
235
- getCountryEmoji: {
236
- transform(parameters) {
237
- const [country] = Object.values(parameters);
238
- const countryToEmojiMap = {
239
- japan: '🇯🇵',
240
- spain: '🇪🇸',
241
- france: '🇫🇷',
242
- }
243
- return countryToEmojiMap[country] ?? '🏳'
244
- },
245
- },
246
- },
247
- })
248
- ```
249
-
250
- Now, you can call this function from any Markdoc content entry:
251
-
252
- ```md
253
- ¡Hola {% getCountryEmoji("spain") %}!
254
- ```
255
-
256
- 📚 [See the Markdoc documentation](https://markdoc.dev/docs/functions#creating-a-custom-function) for more on using variables or functions in your content.
257
-
258
- ### Pass Markdoc variables
259
-
260
- You may need to pass [variables][markdoc-variables] to your content. This is useful when passing SSR parameters like A/B tests.
261
-
262
- Variables can be passed as props via the `Content` component:
263
-
264
- ```astro
265
- ---
266
- import { getEntryBySlug } from 'astro:content';
267
-
268
- const entry = await getEntryBySlug('docs', 'why-markdoc');
269
- const { Content } = await entry.render();
270
- ---
271
-
272
- <!--Pass the `abTest` param as a variable-->
273
- <Content abTestGroup={Astro.params.abTestGroup} />
274
- ```
275
-
276
- Now, `abTestGroup` is available as a variable in `docs/why-markdoc.mdoc`:
277
-
278
- ```md
279
- {% if $abTestGroup === 'image-optimization-lover' %}
280
-
281
- Let me tell you about image optimization...
282
-
283
- {% /if %}
284
- ```
285
-
286
- To make a variable global to all Markdoc files, you can use the `variables` attribute from your `markdoc.config.mjs|ts`:
287
-
288
- ```js
289
- import { defineMarkdocConfig } from '@astrojs/markdoc/config';
290
-
291
- export default defineMarkdocConfig({
292
- variables: {
293
- environment: process.env.IS_PROD ? 'prod' : 'dev',
294
- }
295
- })
296
- ```
297
-
298
- ## Examples
299
-
300
- * The [Astro Markdoc starter template](https://github.com/withastro/astro/tree/latest/examples/with-markdoc) shows how to use Markdoc files in your Astro project.
301
-
302
- ## Troubleshooting
303
-
304
- For help, check out the `#support` channel on [Discord](https://astro.build/chat). Our friendly Support Squad members are here to help!
305
-
306
- You can also check our [Astro Integration Documentation][astro-integration] for more on integrations.
15
+ - Submit bug reports and feature requests as [GitHub issues][issues].
307
16
 
308
17
  ## Contributing
309
18
 
310
- This package is maintained by Astro's Core team. You're welcome to submit an issue or PR!
19
+ This package is maintained by Astro's Core team. You're welcome to submit an issue or PR! These links will help you get started:
311
20
 
312
- ## Changelog
21
+ - [Contributor Manual][contributing]
22
+ - [Code of Conduct][coc]
23
+ - [Community Guide][community]
313
24
 
314
- See [CHANGELOG.md](https://github.com/withastro/astro/tree/main/packages/integrations/markdoc/CHANGELOG.md) for a history of changes to this integration.
25
+ ## License
315
26
 
316
- [astro-integration]: https://docs.astro.build/en/guides/integrations-guide/
317
-
318
- [astro-components]: https://docs.astro.build/en/core-concepts/astro-components/
319
-
320
- [astro-content-collections]: https://docs.astro.build/en/guides/content-collections/
27
+ MIT
321
28
 
322
- [markdoc-tags]: https://markdoc.dev/docs/tags
29
+ Copyright (c) 2023–present [Astro][astro]
323
30
 
324
- [markdoc-nodes]: https://markdoc.dev/docs/nodes
325
-
326
- [markdoc-variables]: https://markdoc.dev/docs/variables
31
+ [astro]: https://astro.build/
32
+ [docs]: https://docs.astro.build/en/guides/integrations-guide/markdoc/
33
+ [contributing]: https://github.com/withastro/astro/blob/main/CONTRIBUTING.md
34
+ [coc]: https://github.com/withastro/.github/blob/main/CODE_OF_CONDUCT.md
35
+ [community]: https://github.com/withastro/.github/blob/main/COMMUNITY_GUIDE.md
36
+ [discord]: https://astro.build/chat/
37
+ [issues]: https://github.com/withastro/astro/issues
38
+ [astro-integration]: https://docs.astro.build/en/guides/integrations-guide/
@@ -1,4 +1,5 @@
1
1
  ---
2
+ //! astro-head-inject
2
3
  import type { Config } from '@markdoc/markdoc';
3
4
  import Markdoc from '@markdoc/markdoc';
4
5
  import { ComponentNode, createTreeNode } from './TreeNode.js';
@@ -14,4 +15,10 @@ const ast = Markdoc.Ast.fromJSON(stringifiedAst);
14
15
  const content = Markdoc.transform(ast, config);
15
16
  ---
16
17
 
17
- <ComponentNode treeNode={createTreeNode(content)} />
18
+ {
19
+ Array.isArray(content) ? (
20
+ content.map(async (c) => <ComponentNode treeNode={await createTreeNode(c)} />)
21
+ ) : (
22
+ <ComponentNode treeNode={await createTreeNode(content)} />
23
+ )
24
+ }
@@ -1,17 +1,30 @@
1
- import type { AstroInstance } from 'astro';
2
- import { Fragment } from 'astro/jsx-runtime';
3
1
  import type { RenderableTreeNode } from '@markdoc/markdoc';
4
2
  import Markdoc from '@markdoc/markdoc';
5
- import { createComponent, renderComponent, render } from 'astro/runtime/server/index.js';
3
+ import type { AstroInstance } from 'astro';
4
+ import type { HTMLString } from 'astro/runtime/server/index.js';
5
+ import {
6
+ createComponent,
7
+ createHeadAndContent,
8
+ isHTMLString,
9
+ render,
10
+ renderComponent,
11
+ renderScriptElement,
12
+ renderTemplate,
13
+ renderUniqueStylesheet,
14
+ unescapeHTML,
15
+ } from 'astro/runtime/server/index.js';
6
16
 
7
17
  export type TreeNode =
8
18
  | {
9
19
  type: 'text';
10
- content: string;
20
+ content: string | HTMLString;
11
21
  }
12
22
  | {
13
23
  type: 'component';
14
24
  component: AstroInstance['default'];
25
+ collectedLinks?: string[];
26
+ collectedStyles?: string[];
27
+ collectedScripts?: string[];
15
28
  props: Record<string, any>;
16
29
  children: TreeNode[];
17
30
  }
@@ -25,6 +38,7 @@ export type TreeNode =
25
38
  export const ComponentNode = createComponent({
26
39
  factory(result: any, { treeNode }: { treeNode: TreeNode }) {
27
40
  if (treeNode.type === 'text') return render`${treeNode.content}`;
41
+
28
42
  const slots = {
29
43
  default: () =>
30
44
  render`${treeNode.children.map((child) =>
@@ -32,37 +46,76 @@ export const ComponentNode = createComponent({
32
46
  )}`,
33
47
  };
34
48
  if (treeNode.type === 'component') {
35
- return renderComponent(
36
- result,
37
- treeNode.component.name,
38
- treeNode.component,
39
- treeNode.props,
40
- slots
49
+ let styles = '',
50
+ links = '',
51
+ scripts = '';
52
+ if (Array.isArray(treeNode.collectedStyles)) {
53
+ styles = treeNode.collectedStyles
54
+ .map((style: any) =>
55
+ renderUniqueStylesheet(result, {
56
+ type: 'inline',
57
+ content: style,
58
+ })
59
+ )
60
+ .join('');
61
+ }
62
+ if (Array.isArray(treeNode.collectedLinks)) {
63
+ links = treeNode.collectedLinks
64
+ .map((link: any) => {
65
+ return renderUniqueStylesheet(result, {
66
+ type: 'external',
67
+ src: link[0] === '/' ? link : '/' + link,
68
+ });
69
+ })
70
+ .join('');
71
+ }
72
+ if (Array.isArray(treeNode.collectedScripts)) {
73
+ scripts = treeNode.collectedScripts
74
+ .map((script: any) => renderScriptElement(script))
75
+ .join('');
76
+ }
77
+
78
+ const head = unescapeHTML(styles + links + scripts);
79
+
80
+ let headAndContent = createHeadAndContent(
81
+ head,
82
+ renderTemplate`${renderComponent(
83
+ result,
84
+ treeNode.component.name,
85
+ treeNode.component,
86
+ treeNode.props,
87
+ slots
88
+ )}`
41
89
  );
90
+
91
+ // Let the runtime know that this component is being used.
92
+ result._metadata.propagators.add({
93
+ init() {
94
+ return headAndContent;
95
+ },
96
+ });
97
+
98
+ return headAndContent;
42
99
  }
43
100
  return renderComponent(result, treeNode.tag, treeNode.tag, treeNode.attributes, slots);
44
101
  },
45
- propagation: 'none',
102
+ propagation: 'self',
46
103
  });
47
104
 
48
- export function createTreeNode(node: RenderableTreeNode | RenderableTreeNode[]): TreeNode {
49
- if (typeof node === 'string' || typeof node === 'number') {
105
+ export async function createTreeNode(node: RenderableTreeNode): Promise<TreeNode> {
106
+ if (isHTMLString(node)) {
107
+ return { type: 'text', content: node as HTMLString };
108
+ } else if (typeof node === 'string' || typeof node === 'number') {
50
109
  return { type: 'text', content: String(node) };
51
- } else if (Array.isArray(node)) {
52
- return {
53
- type: 'component',
54
- component: Fragment,
55
- props: {},
56
- children: node.map((child) => createTreeNode(child)),
57
- };
58
110
  } else if (node === null || typeof node !== 'object' || !Markdoc.Tag.isTag(node)) {
59
111
  return { type: 'text', content: '' };
60
112
  }
61
113
 
114
+ const children = await Promise.all(node.children.map((child) => createTreeNode(child)));
115
+
62
116
  if (typeof node.name === 'function') {
63
117
  const component = node.name;
64
118
  const props = node.attributes;
65
- const children = node.children.map((child) => createTreeNode(child));
66
119
 
67
120
  return {
68
121
  type: 'component',
@@ -70,12 +123,38 @@ export function createTreeNode(node: RenderableTreeNode | RenderableTreeNode[]):
70
123
  props,
71
124
  children,
72
125
  };
126
+ } else if (isPropagatedAssetsModule(node.name)) {
127
+ const { collectedStyles, collectedLinks, collectedScripts } = node.name;
128
+ const component = (await node.name.getMod()).default;
129
+ const props = node.attributes;
130
+
131
+ return {
132
+ type: 'component',
133
+ component,
134
+ collectedStyles,
135
+ collectedLinks,
136
+ collectedScripts,
137
+ props,
138
+ children,
139
+ };
73
140
  } else {
74
141
  return {
75
142
  type: 'element',
76
143
  tag: node.name,
77
144
  attributes: node.attributes,
78
- children: node.children.map((child) => createTreeNode(child)),
145
+ children,
79
146
  };
80
147
  }
81
148
  }
149
+
150
+ type PropagatedAssetsModule = {
151
+ __astroPropagation: true;
152
+ getMod: () => Promise<AstroInstance>;
153
+ collectedStyles: string[];
154
+ collectedLinks: string[];
155
+ collectedScripts: string[];
156
+ };
157
+
158
+ function isPropagatedAssetsModule(module: any): module is PropagatedAssetsModule {
159
+ return typeof module === 'object' && module != null && '__astroPropagation' in module;
160
+ }
package/dist/config.d.ts CHANGED
@@ -1,2 +1,57 @@
1
- import type { ConfigType as MarkdocConfig } from '@markdoc/markdoc';
2
- export declare function defineMarkdocConfig(config: MarkdocConfig): MarkdocConfig;
1
+ import type { Config, ConfigType as MarkdocConfig, MaybePromise, NodeType, Schema } from '@markdoc/markdoc';
2
+ import _Markdoc from '@markdoc/markdoc';
3
+ import type { AstroInstance } from 'astro';
4
+ import { componentConfigSymbol } from './utils.js';
5
+ export type Render = ComponentConfig | AstroInstance['default'] | string;
6
+ export type ComponentConfig = {
7
+ type: 'package' | 'local';
8
+ path: string;
9
+ namedExport?: string;
10
+ [componentConfigSymbol]: true;
11
+ };
12
+ export type AstroMarkdocConfig<C extends Record<string, any> = Record<string, any>> = Omit<MarkdocConfig, 'tags' | 'nodes'> & Partial<{
13
+ tags: Record<string, Schema<Config, Render>>;
14
+ nodes: Partial<Record<NodeType, Schema<Config, Render>>>;
15
+ ctx: C;
16
+ extends: MaybePromise<ResolvedAstroMarkdocConfig>[];
17
+ }>;
18
+ export type ResolvedAstroMarkdocConfig = Omit<AstroMarkdocConfig, 'extends'>;
19
+ export declare const Markdoc: typeof _Markdoc;
20
+ export declare const nodes: {
21
+ heading: Schema;
22
+ document: Schema;
23
+ paragraph: Schema;
24
+ image: Schema;
25
+ fence: Schema;
26
+ blockquote: Schema;
27
+ item: Schema;
28
+ list: Schema;
29
+ hr: Schema;
30
+ table: Schema;
31
+ td: Schema;
32
+ th: Schema;
33
+ tr: Schema;
34
+ tbody: Schema;
35
+ thead: Schema;
36
+ strong: Schema;
37
+ em: Schema;
38
+ s: Schema;
39
+ inline: Schema;
40
+ link: Schema;
41
+ code: Schema;
42
+ text: Schema;
43
+ hardbreak: Schema;
44
+ softbreak: Schema;
45
+ comment: {
46
+ attributes: {
47
+ content: {
48
+ type: StringConstructor;
49
+ required: boolean;
50
+ };
51
+ };
52
+ };
53
+ error: {};
54
+ node: {};
55
+ };
56
+ export declare function defineMarkdocConfig(config: AstroMarkdocConfig): AstroMarkdocConfig;
57
+ export declare function component(pathnameOrPkgName: string, namedExport?: string): ComponentConfig;
package/dist/config.js CHANGED
@@ -1,6 +1,26 @@
1
+ import { isRelativePath } from "@astrojs/internal-helpers/path";
2
+ import _Markdoc from "@markdoc/markdoc";
3
+ import { heading } from "./heading-ids.js";
4
+ import { componentConfigSymbol } from "./utils.js";
5
+ const Markdoc = _Markdoc;
6
+ const nodes = { ...Markdoc.nodes, heading };
1
7
  function defineMarkdocConfig(config) {
2
8
  return config;
3
9
  }
10
+ function component(pathnameOrPkgName, namedExport) {
11
+ return {
12
+ type: isNpmPackageName(pathnameOrPkgName) ? "package" : "local",
13
+ path: pathnameOrPkgName,
14
+ namedExport,
15
+ [componentConfigSymbol]: true
16
+ };
17
+ }
18
+ function isNpmPackageName(pathname) {
19
+ return !isRelativePath(pathname) && !pathname.startsWith("/");
20
+ }
4
21
  export {
5
- defineMarkdocConfig
22
+ Markdoc,
23
+ component,
24
+ defineMarkdocConfig,
25
+ nodes
6
26
  };
@@ -0,0 +1,8 @@
1
+ import type { AstroConfig, ContentEntryType } from 'astro';
2
+ import type { MarkdocConfigResult } from './load-config.js';
3
+ import type { MarkdocIntegrationOptions } from './options.js';
4
+ export declare function getContentEntryType({ markdocConfigResult, astroConfig, options, }: {
5
+ astroConfig: AstroConfig;
6
+ markdocConfigResult?: MarkdocConfigResult;
7
+ options?: MarkdocIntegrationOptions;
8
+ }): Promise<ContentEntryType>;