@pterodoc/core 0.2.0

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 (130) hide show
  1. package/LICENCE.md +10 -0
  2. package/README.md +12 -0
  3. package/lib/chunks/capture-BhdvHwrN.js +428 -0
  4. package/lib/chunks/capture-BhdvHwrN.js.map +1 -0
  5. package/lib/chunks/issues-DBsPh6ek.js +55 -0
  6. package/lib/chunks/issues-DBsPh6ek.js.map +1 -0
  7. package/lib/chunks/mime-2SUyOolJ.js +62 -0
  8. package/lib/chunks/mime-2SUyOolJ.js.map +1 -0
  9. package/lib/chunks/paths-Bh6UsRI9.js +177 -0
  10. package/lib/chunks/paths-Bh6UsRI9.js.map +1 -0
  11. package/lib/config/load.d.ts +123 -0
  12. package/lib/config/load.d.ts.map +1 -0
  13. package/lib/config/types.d.ts +136 -0
  14. package/lib/config/types.d.ts.map +1 -0
  15. package/lib/errors.d.ts +53 -0
  16. package/lib/errors.d.ts.map +1 -0
  17. package/lib/index.d.ts +23 -0
  18. package/lib/index.d.ts.map +1 -0
  19. package/lib/index.js +807 -0
  20. package/lib/index.js.map +1 -0
  21. package/lib/model/capture.d.ts +37 -0
  22. package/lib/model/capture.d.ts.map +1 -0
  23. package/lib/model/index.d.ts +13 -0
  24. package/lib/model/index.d.ts.map +1 -0
  25. package/lib/model/index.js +7 -0
  26. package/lib/model/index.js.map +1 -0
  27. package/lib/model/reader.d.ts +25 -0
  28. package/lib/model/reader.d.ts.map +1 -0
  29. package/lib/model/tree.d.ts +81 -0
  30. package/lib/model/tree.d.ts.map +1 -0
  31. package/lib/model/types.d.ts +166 -0
  32. package/lib/model/types.d.ts.map +1 -0
  33. package/lib/render/admonitions.d.ts +26 -0
  34. package/lib/render/admonitions.d.ts.map +1 -0
  35. package/lib/render/blocks.d.ts +39 -0
  36. package/lib/render/blocks.d.ts.map +1 -0
  37. package/lib/render/code.d.ts +37 -0
  38. package/lib/render/code.d.ts.map +1 -0
  39. package/lib/render/components.d.ts +49 -0
  40. package/lib/render/components.d.ts.map +1 -0
  41. package/lib/render/excerpt.d.ts +9 -0
  42. package/lib/render/excerpt.d.ts.map +1 -0
  43. package/lib/render/images.d.ts +58 -0
  44. package/lib/render/images.d.ts.map +1 -0
  45. package/lib/render/index.d.ts +80 -0
  46. package/lib/render/index.d.ts.map +1 -0
  47. package/lib/render/index.js +1336 -0
  48. package/lib/render/index.js.map +1 -0
  49. package/lib/render/inline.d.ts +25 -0
  50. package/lib/render/inline.d.ts.map +1 -0
  51. package/lib/render/links.d.ts +45 -0
  52. package/lib/render/links.d.ts.map +1 -0
  53. package/lib/render/mdx.d.ts +37 -0
  54. package/lib/render/mdx.d.ts.map +1 -0
  55. package/lib/render/page.d.ts +85 -0
  56. package/lib/render/page.d.ts.map +1 -0
  57. package/lib/render/parse.d.ts +27 -0
  58. package/lib/render/parse.d.ts.map +1 -0
  59. package/lib/render/references.d.ts +20 -0
  60. package/lib/render/references.d.ts.map +1 -0
  61. package/lib/render/renderers.d.ts +57 -0
  62. package/lib/render/renderers.d.ts.map +1 -0
  63. package/lib/render/slug.d.ts +34 -0
  64. package/lib/render/slug.d.ts.map +1 -0
  65. package/lib/render/theme.d.ts +62 -0
  66. package/lib/render/theme.d.ts.map +1 -0
  67. package/lib/sync/artifacts.d.ts +46 -0
  68. package/lib/sync/artifacts.d.ts.map +1 -0
  69. package/lib/sync/plan.d.ts +59 -0
  70. package/lib/sync/plan.d.ts.map +1 -0
  71. package/lib/sync/run.d.ts +39 -0
  72. package/lib/sync/run.d.ts.map +1 -0
  73. package/lib/target/index.d.ts +8 -0
  74. package/lib/target/index.d.ts.map +1 -0
  75. package/lib/target/index.js +2 -0
  76. package/lib/target/index.js.map +1 -0
  77. package/lib/target/target.d.ts +152 -0
  78. package/lib/target/target.d.ts.map +1 -0
  79. package/lib/util/hash.d.ts +10 -0
  80. package/lib/util/hash.d.ts.map +1 -0
  81. package/lib/util/index.d.ts +14 -0
  82. package/lib/util/index.d.ts.map +1 -0
  83. package/lib/util/index.js +7 -0
  84. package/lib/util/index.js.map +1 -0
  85. package/lib/util/issues.d.ts +52 -0
  86. package/lib/util/issues.d.ts.map +1 -0
  87. package/lib/util/mime.d.ts +16 -0
  88. package/lib/util/mime.d.ts.map +1 -0
  89. package/lib/util/paths.d.ts +42 -0
  90. package/lib/util/paths.d.ts.map +1 -0
  91. package/lib/version.d.ts +6 -0
  92. package/lib/version.d.ts.map +1 -0
  93. package/package.json +43 -0
  94. package/src/config/load.ts +387 -0
  95. package/src/config/types.ts +137 -0
  96. package/src/errors.ts +77 -0
  97. package/src/globals.d.ts +10 -0
  98. package/src/index.ts +31 -0
  99. package/src/model/capture.ts +92 -0
  100. package/src/model/index.ts +25 -0
  101. package/src/model/reader.ts +37 -0
  102. package/src/model/tree.ts +416 -0
  103. package/src/model/types.ts +167 -0
  104. package/src/render/admonitions.ts +74 -0
  105. package/src/render/blocks.ts +79 -0
  106. package/src/render/code.ts +112 -0
  107. package/src/render/components.ts +230 -0
  108. package/src/render/excerpt.ts +16 -0
  109. package/src/render/images.ts +113 -0
  110. package/src/render/index.ts +129 -0
  111. package/src/render/inline.ts +62 -0
  112. package/src/render/links.ts +94 -0
  113. package/src/render/mdx.ts +178 -0
  114. package/src/render/page.ts +289 -0
  115. package/src/render/parse.ts +65 -0
  116. package/src/render/references.ts +69 -0
  117. package/src/render/renderers.ts +346 -0
  118. package/src/render/slug.ts +63 -0
  119. package/src/render/theme.ts +92 -0
  120. package/src/sync/artifacts.ts +70 -0
  121. package/src/sync/plan.ts +69 -0
  122. package/src/sync/run.ts +641 -0
  123. package/src/target/index.ts +18 -0
  124. package/src/target/target.ts +146 -0
  125. package/src/util/hash.ts +14 -0
  126. package/src/util/index.ts +23 -0
  127. package/src/util/issues.ts +86 -0
  128. package/src/util/mime.ts +47 -0
  129. package/src/util/paths.ts +101 -0
  130. package/src/version.ts +31 -0
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Finding and resolving the files a document references.
3
+ *
4
+ * Images are found wherever they sit — in a paragraph, behind a reference,
5
+ * inside raw HTML — because the one place they never sit is at the top level
6
+ * of a document, which is where an earlier version of this code looked.
7
+ */
8
+ import { type MarkdownFormat } from './parse';
9
+ /** An image a document points at. */
10
+ export interface ImageReference {
11
+ /** The URL exactly as written in the source. */
12
+ url: string;
13
+ /** Alternative text. */
14
+ alt: string;
15
+ /** Title, which becomes a caption. */
16
+ title?: string | undefined;
17
+ }
18
+ /** Where an image URL actually points. */
19
+ export type ResolvedImage = {
20
+ kind: 'external';
21
+ url: string;
22
+ } | {
23
+ kind: 'file';
24
+ url: string;
25
+ file: string;
26
+ } | {
27
+ kind: 'missing';
28
+ url: string;
29
+ };
30
+ /** Where to look when resolving a relative or absolute reference. */
31
+ export interface ImageResolutionContext {
32
+ /** Absolute path of the document's own source file. */
33
+ sourceAbsolutePath: string;
34
+ /** The version's content directory. */
35
+ contentPath: string;
36
+ /** The localised content directory, preferred when the file exists in both. */
37
+ contentPathLocalized: string;
38
+ /** Absolute paths of the site's static directories. */
39
+ staticDirs: string[];
40
+ /** The site's base URL, stripped from absolute references when present. */
41
+ baseUrl: string;
42
+ /** The Docusaurus site directory, for `@site/` references. */
43
+ siteDir: string;
44
+ /** Injected so resolution can be tested without a filesystem. */
45
+ exists?: (file: string) => boolean;
46
+ }
47
+ /** Every image a document references, including ones behind a reference definition. */
48
+ export declare function collectImages(markdown: string, format?: MarkdownFormat): ImageReference[];
49
+ /**
50
+ * Work out which file an image URL points at.
51
+ *
52
+ * The order matches how Docusaurus itself resolves them: an absolute URL is
53
+ * left alone, `@site/` is site-relative, a leading slash is served from a
54
+ * static directory, and anything else is relative to the document — preferring
55
+ * the localised copy when there is one.
56
+ */
57
+ export declare function resolveImage(url: string, ctx: ImageResolutionContext): ResolvedImage;
58
+ //# sourceMappingURL=images.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"images.d.ts","sourceRoot":"","sources":["../../src/render/images.ts"],"names":[],"mappings":"AA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endering a document: parse, resolve, and serialise to blocks.
3
+ *
4
+ * This layer is pure. It never reaches the network, never loads Docusaurus and
5
+ * knows nothing about the target beyond the URLs a resolver hands back.
6
+ */
7
+ import { type MarkdownFormat } from './parse';
8
+ import { type UnknownPolicy } from './mdx';
9
+ import { type LinkResolver } from './links';
10
+ import type { Theme } from './theme';
11
+ import { IssueCollector } from '../util/issues';
12
+ export { createTheme, DEFAULT_STRINGS } from './theme';
13
+ export type { Theme, Strings, BlockVocabulary } from './theme';
14
+ export { parseMarkdown, detectFormat } from './parse';
15
+ export type { MarkdownFormat } from './parse';
16
+ export { renderBlock, renderBody, createRenderContext } from './renderers';
17
+ export type { RenderContext } from './renderers';
18
+ export { excerptFrom } from './excerpt';
19
+ export { serializeBlock, serializeVoidBlock, serializeAttrs, escapeCode, escapeText, joinBlocks } from './blocks';
20
+ export { renderInline } from './inline';
21
+ export { headingIdFor, createSlugger } from './slug';
22
+ export { resolveReferences } from './references';
23
+ export { rewriteLinks, toInternalPath, isAbsoluteUrl } from './links';
24
+ export type { LinkResolver, ResolvedLink } from './links';
25
+ export { DEFAULT_ADMONITION_KEYWORDS } from './admonitions';
26
+ export { lowerMdx, isTranslatable, KNOWN_COMPONENTS } from './mdx';
27
+ export type { UnknownPolicy } from './mdx';
28
+ export { renderJsxBlock, attribute } from './components';
29
+ export { collectImages, resolveImage } from './images';
30
+ export type { ImageReference, ResolvedImage } from './images';
31
+ export { composePage, DEFAULT_LAYOUT, renderNavigationStub, renderVersionBanner } from './page';
32
+ export type { ComposePageInput, PageLayout, PageLike } from './page';
33
+ /** What to render, and how. */
34
+ export interface RenderDocInput {
35
+ /** The document body, front matter included or not. */
36
+ markdown: string;
37
+ /** Absolute or site-relative path, used for issue positions and format detection. */
38
+ file?: string;
39
+ /** Permalink of this document, which relative links resolve against. */
40
+ permalink: string;
41
+ /** Which flavour to parse as; detected from `file` when omitted. */
42
+ format?: MarkdownFormat;
43
+ /** Class names and strings. */
44
+ theme: Theme;
45
+ /** Where each link should point. */
46
+ resolveLink?: LinkResolver;
47
+ /** Directive names that mean "admonition" on this site. */
48
+ admonitionKeywords?: Iterable<string>;
49
+ /** Whether Docusaurus keeps heading case when generating anchors. */
50
+ maintainCase?: boolean;
51
+ /** Drop a leading H1 that repeats the page title. */
52
+ dedupeTitle?: boolean;
53
+ /** Uploaded media, keyed by the URL as written in the source. */
54
+ media?: Map<string, {
55
+ id: number;
56
+ url: string;
57
+ }>;
58
+ /** What to do about JSX with no translation. */
59
+ onUnknownJsx?: UnknownPolicy;
60
+ /** Collector to record issues into; a fresh one is made when omitted. */
61
+ issues?: IssueCollector;
62
+ }
63
+ /** A rendered document body and what was learned while rendering it. */
64
+ export interface RenderedDoc {
65
+ /** The block markup. */
66
+ body: string;
67
+ /** Tree paths of the pages this document links to. */
68
+ links: Set<string>;
69
+ /** Plain text of the first paragraph, for an excerpt. */
70
+ firstParagraph: string;
71
+ /** Everything worth telling the user about this document. */
72
+ issues: IssueCollector;
73
+ }
74
+ /**
75
+ * Render one document to Gutenberg block markup.
76
+ */
77
+ export declare function renderDoc(input: RenderDocInput): RenderedDoc;
78
+ /** Build an excerpt from a description, falling back to the opening paragraph. */
79
+ export declare function excerptFor(description: string, firstParagraph: string, max?: number): string;
80
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/render/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAA+B,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAE3E,OAAO,EAAY,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,SAAS,CAAC;AAK1D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,SAAS,CAA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