|
1 | 1 | // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. |
2 | 2 |
|
3 | 3 | import { instantiate } from "./deno_doc_wasm.generated.js"; |
4 | | -import type { DocNode, Location } from "./types.d.ts"; |
| 4 | +import type { Document, Location } from "./types.d.ts"; |
5 | 5 | import type { Page } from "./html_types.d.ts"; |
6 | 6 | import { createCache } from "@deno/cache-dir"; |
7 | 7 | import type { CacheSetting, LoadResponse } from "@deno/graph"; |
@@ -87,7 +87,7 @@ export interface DocOptions { |
87 | 87 | export async function doc( |
88 | 88 | specifiers: string[], |
89 | 89 | options: DocOptions = {}, |
90 | | -): Promise<Record<string, Array<DocNode>>> { |
| 90 | +): Promise<Record<string, Document>> { |
91 | 91 | const { |
92 | 92 | load = createCache().load, |
93 | 93 | includeAll = false, |
@@ -128,6 +128,18 @@ export async function doc( |
128 | 128 | ); |
129 | 129 | } |
130 | 130 |
|
| 131 | +/** |
| 132 | + * Convert a v1 doc nodes array (flat array of doc nodes) to the v2 |
| 133 | + * {@linkcode Document} format. |
| 134 | + */ |
| 135 | +export async function docnodesV1ToV2( |
| 136 | + // deno-lint-ignore no-explicit-any |
| 137 | + v1Nodes: any[], |
| 138 | +): Promise<Document> { |
| 139 | + const wasm = await instantiate(); |
| 140 | + return wasm.docnodes_v1_to_v2(v1Nodes); |
| 141 | +} |
| 142 | + |
131 | 143 | export interface ShortPath { |
132 | 144 | /** Name identifier for the path. */ |
133 | 145 | path: string; |
@@ -303,12 +315,12 @@ const defaultUsageComposer: UsageComposer = { |
303 | 315 | }; |
304 | 316 |
|
305 | 317 | /** |
306 | | - * Generate HTML files for provided {@linkcode DocNode}s. |
| 318 | + * Generate HTML files for provided {@linkcode Document}s. |
307 | 319 | * @param docNodesByUrl DocNodes keyed by their absolute URL. |
308 | 320 | * @param options Options for the generation. |
309 | 321 | */ |
310 | 322 | export async function generateHtml( |
311 | | - docNodesByUrl: Record<string, Array<DocNode>>, |
| 323 | + docNodesByUrl: Record<string, Document>, |
312 | 324 | options: GenerateOptions, |
313 | 325 | ): Promise<Record<string, string>> { |
314 | 326 | const { |
@@ -346,7 +358,7 @@ export async function generateHtml( |
346 | 358 | * @param options Options for the generation. |
347 | 359 | */ |
348 | 360 | export async function generateHtmlAsJSON( |
349 | | - docNodesByUrl: Record<string, Array<DocNode>>, |
| 361 | + docNodesByUrl: Record<string, Document>, |
350 | 362 | options: GenerateOptions, |
351 | 363 | ): Promise<Record<string, Page>> { |
352 | 364 | const { |
|
0 commit comments