bun-types-no-globals 1.3.7-canary.20260128T141311 → 1.3.8-canary.20260129T141834

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.
package/lib/bun.d.ts CHANGED
@@ -905,6 +905,417 @@ declare module "bun" {
905
905
  export function stringify(input: unknown, replacer?: undefined | null, space?: string | number): string;
906
906
  }
907
907
 
908
+ /**
909
+ * Markdown related APIs.
910
+ *
911
+ * Provides fast markdown parsing and rendering with three output modes:
912
+ * - `html()` — render to an HTML string
913
+ * - `render()` — render with custom callbacks for each element
914
+ * - `react()` — parse to React-compatible JSX elements
915
+ *
916
+ * Supports GFM extensions (tables, strikethrough, task lists, autolinks) and
917
+ * component overrides to replace default HTML tags with custom components.
918
+ *
919
+ * @example
920
+ * ```tsx
921
+ * // Render markdown to HTML
922
+ * const html = Bun.markdown.html("# Hello **world**");
923
+ * // "<h1>Hello <strong>world</strong></h1>\n"
924
+ *
925
+ * // Render with custom callbacks
926
+ * const ansi = Bun.markdown.render("# Hello **world**", {
927
+ * heading: (children, { level }) => `\x1b[1m${children}\x1b[0m\n`,
928
+ * strong: (children) => `\x1b[1m${children}\x1b[22m`,
929
+ * paragraph: (children) => children + "\n",
930
+ * });
931
+ *
932
+ * // Render as a React component
933
+ * function Markdown({ text }: { text: string }) {
934
+ * return Bun.markdown.react(text);
935
+ * }
936
+ *
937
+ * // With component overrides
938
+ * const element = Bun.markdown.react("# Hello", { h1: MyHeadingComponent });
939
+ * ```
940
+ */
941
+ namespace markdown {
942
+ /**
943
+ * Options for configuring the markdown parser.
944
+ *
945
+ * By default, GFM extensions (tables, strikethrough, task lists) are enabled.
946
+ */
947
+ interface Options {
948
+ /** Enable GFM tables. Default: `true`. */
949
+ tables?: boolean;
950
+ /** Enable GFM strikethrough (`~~text~~`). Default: `true`. */
951
+ strikethrough?: boolean;
952
+ /** Enable GFM task lists (`- [x] item`). Default: `true`. */
953
+ tasklists?: boolean;
954
+ /** Treat soft line breaks as hard line breaks. Default: `false`. */
955
+ hardSoftBreaks?: boolean;
956
+ /** Enable wiki-style links (`[[target]]` or `[[target|label]]`). Default: `false`. */
957
+ wikiLinks?: boolean;
958
+ /** Enable underline syntax (`__text__` renders as `<u>` instead of `<strong>`). Default: `false`. */
959
+ underline?: boolean;
960
+ /** Enable LaTeX math (`$inline$` and `$$display$$`). Default: `false`. */
961
+ latexMath?: boolean;
962
+ /** Collapse whitespace in text content. Default: `false`. */
963
+ collapseWhitespace?: boolean;
964
+ /** Allow ATX headers without a space after `#`. Default: `false`. */
965
+ permissiveAtxHeaders?: boolean;
966
+ /** Disable indented code blocks. Default: `false`. */
967
+ noIndentedCodeBlocks?: boolean;
968
+ /** Disable HTML blocks. Default: `false`. */
969
+ noHtmlBlocks?: boolean;
970
+ /** Disable inline HTML spans. Default: `false`. */
971
+ noHtmlSpans?: boolean;
972
+ /**
973
+ * Enable the GFM tag filter, which replaces `<` with `&lt;` for disallowed
974
+ * HTML tags (e.g. `<script>`, `<style>`, `<iframe>`). Default: `false`.
975
+ */
976
+ tagFilter?: boolean;
977
+ /**
978
+ * Enable autolinks. Pass `true` to enable all autolink types (URL, WWW, email),
979
+ * or an object to enable individually.
980
+ *
981
+ * @example
982
+ * ```ts
983
+ * // Enable all autolinks
984
+ * { autolinks: true }
985
+ * // Enable only URL and email autolinks
986
+ * { autolinks: { url: true, email: true } }
987
+ * ```
988
+ */
989
+ autolinks?: boolean | { url?: boolean; www?: boolean; email?: boolean };
990
+ /**
991
+ * Configure heading IDs and autolink headings. Pass `true` to enable both
992
+ * heading IDs and autolink headings, or an object to configure individually.
993
+ *
994
+ * @example
995
+ * ```ts
996
+ * // Enable both heading IDs and autolink headings
997
+ * { headings: true }
998
+ * // Enable only heading IDs
999
+ * { headings: { ids: true } }
1000
+ * ```
1001
+ */
1002
+ headings?: boolean | { ids?: boolean; autolink?: boolean };
1003
+ }
1004
+
1005
+ /** A component that accepts props `P`: a function, class, or HTML tag name. */
1006
+ type Component<P = {}> = string | ((props: P) => any) | (new (props: P) => any);
1007
+
1008
+ interface ChildrenProps {
1009
+ children: import("./jsx.d.ts").JSX.Element[];
1010
+ }
1011
+ interface HeadingProps extends ChildrenProps {
1012
+ /** Heading ID slug. Set when `headings: { ids: true }` is enabled. */
1013
+ id?: string;
1014
+ }
1015
+ interface OrderedListProps extends ChildrenProps {
1016
+ /** The start number. */
1017
+ start: number;
1018
+ }
1019
+ interface ListItemProps extends ChildrenProps {
1020
+ /** Task list checked state. Set for `- [x]` / `- [ ]` items. */
1021
+ checked?: boolean;
1022
+ }
1023
+ interface CodeBlockProps extends ChildrenProps {
1024
+ /** The info-string language (e.g. `"js"`). */
1025
+ language?: string;
1026
+ }
1027
+ interface CellProps extends ChildrenProps {
1028
+ /** Column alignment. */
1029
+ align?: "left" | "center" | "right";
1030
+ }
1031
+ interface LinkProps extends ChildrenProps {
1032
+ /** Link URL. */
1033
+ href: string;
1034
+ /** Link title attribute. */
1035
+ title?: string;
1036
+ }
1037
+ interface ImageProps {
1038
+ /** Image URL. */
1039
+ src: string;
1040
+ /** Alt text. */
1041
+ alt?: string;
1042
+ /** Image title attribute. */
1043
+ title?: string;
1044
+ }
1045
+
1046
+ /**
1047
+ * Component overrides for `react()`.
1048
+ *
1049
+ * Replace default HTML tags with custom React components. Each override
1050
+ * receives the same props the default element would get.
1051
+ *
1052
+ * @example
1053
+ * ```tsx
1054
+ * function Code({ language, children }: { language?: string; children: React.ReactNode }) {
1055
+ * return <pre data-language={language}><code>{children}</code></pre>;
1056
+ * }
1057
+ * Bun.markdown.react(text, { pre: Code });
1058
+ * ```
1059
+ */
1060
+ interface ComponentOverrides {
1061
+ h1?: Component<HeadingProps>;
1062
+ h2?: Component<HeadingProps>;
1063
+ h3?: Component<HeadingProps>;
1064
+ h4?: Component<HeadingProps>;
1065
+ h5?: Component<HeadingProps>;
1066
+ h6?: Component<HeadingProps>;
1067
+ p?: Component<ChildrenProps>;
1068
+ blockquote?: Component<ChildrenProps>;
1069
+ ul?: Component<ChildrenProps>;
1070
+ ol?: Component<OrderedListProps>;
1071
+ li?: Component<ListItemProps>;
1072
+ pre?: Component<CodeBlockProps>;
1073
+ hr?: Component<{}>;
1074
+ html?: Component<ChildrenProps>;
1075
+ table?: Component<ChildrenProps>;
1076
+ thead?: Component<ChildrenProps>;
1077
+ tbody?: Component<ChildrenProps>;
1078
+ tr?: Component<ChildrenProps>;
1079
+ th?: Component<CellProps>;
1080
+ td?: Component<CellProps>;
1081
+ em?: Component<ChildrenProps>;
1082
+ strong?: Component<ChildrenProps>;
1083
+ a?: Component<LinkProps>;
1084
+ img?: Component<ImageProps>;
1085
+ code?: Component<ChildrenProps>;
1086
+ del?: Component<ChildrenProps>;
1087
+ math?: Component<ChildrenProps>;
1088
+ u?: Component<ChildrenProps>;
1089
+ br?: Component<{}>;
1090
+ }
1091
+
1092
+ /**
1093
+ * Callbacks for `render()`. Each callback receives the accumulated children
1094
+ * as a string and optional metadata, and returns a string.
1095
+ *
1096
+ * Return `null` or `undefined` to omit the element from the output.
1097
+ * If no callback is registered for an element, its children pass through unchanged.
1098
+ */
1099
+ /** Meta passed to the `heading` callback. */
1100
+ interface HeadingMeta {
1101
+ /** Heading level (1–6). */
1102
+ level: number;
1103
+ /** Heading ID slug. Set when `headings: { ids: true }` is enabled. */
1104
+ id?: string;
1105
+ }
1106
+
1107
+ /** Meta passed to the `code` callback. */
1108
+ interface CodeBlockMeta {
1109
+ /** The info-string language (e.g. `"js"`). */
1110
+ language?: string;
1111
+ }
1112
+
1113
+ /** Meta passed to the `list` callback. */
1114
+ interface ListMeta {
1115
+ /** Whether this is an ordered list. */
1116
+ ordered: boolean;
1117
+ /** The start number for ordered lists. */
1118
+ start?: number;
1119
+ }
1120
+
1121
+ /** Meta passed to the `listItem` callback. */
1122
+ interface ListItemMeta {
1123
+ /** Task list checked state. Set for `- [x]` / `- [ ]` items. */
1124
+ checked?: boolean;
1125
+ }
1126
+
1127
+ /** Meta passed to `th` and `td` callbacks. */
1128
+ interface CellMeta {
1129
+ /** Column alignment. */
1130
+ align?: "left" | "center" | "right";
1131
+ }
1132
+
1133
+ /** Meta passed to the `link` callback. */
1134
+ interface LinkMeta {
1135
+ /** Link URL. */
1136
+ href: string;
1137
+ /** Link title attribute. */
1138
+ title?: string;
1139
+ }
1140
+
1141
+ /** Meta passed to the `image` callback. */
1142
+ interface ImageMeta {
1143
+ /** Image URL. */
1144
+ src: string;
1145
+ /** Image title attribute. */
1146
+ title?: string;
1147
+ }
1148
+
1149
+ interface RenderCallbacks {
1150
+ /** Heading (level 1–6). `id` is set when `headings: { ids: true }` is enabled. */
1151
+ heading?: (children: string, meta: HeadingMeta) => string | null | undefined;
1152
+ /** Paragraph. */
1153
+ paragraph?: (children: string) => string | null | undefined;
1154
+ /** Blockquote. */
1155
+ blockquote?: (children: string) => string | null | undefined;
1156
+ /** Code block. `meta.language` is the info-string (e.g. `"js"`). Only passed for fenced code blocks with a language. */
1157
+ code?: (children: string, meta?: CodeBlockMeta) => string | null | undefined;
1158
+ /** Ordered or unordered list. `start` is the first item number for ordered lists. */
1159
+ list?: (children: string, meta: ListMeta) => string | null | undefined;
1160
+ /** List item. `meta.checked` is set for task list items (`- [x]` / `- [ ]`). Only passed for task list items. */
1161
+ listItem?: (children: string, meta?: ListItemMeta) => string | null | undefined;
1162
+ /** Horizontal rule. */
1163
+ hr?: (children: string) => string | null | undefined;
1164
+ /** Table. */
1165
+ table?: (children: string) => string | null | undefined;
1166
+ /** Table head. */
1167
+ thead?: (children: string) => string | null | undefined;
1168
+ /** Table body. */
1169
+ tbody?: (children: string) => string | null | undefined;
1170
+ /** Table row. */
1171
+ tr?: (children: string) => string | null | undefined;
1172
+ /** Table header cell. `meta.align` is set when column alignment is specified. */
1173
+ th?: (children: string, meta?: CellMeta) => string | null | undefined;
1174
+ /** Table data cell. `meta.align` is set when column alignment is specified. */
1175
+ td?: (children: string, meta?: CellMeta) => string | null | undefined;
1176
+ /** Raw HTML content. */
1177
+ html?: (children: string) => string | null | undefined;
1178
+ /** Strong emphasis (`**text**`). */
1179
+ strong?: (children: string) => string | null | undefined;
1180
+ /** Emphasis (`*text*`). */
1181
+ emphasis?: (children: string) => string | null | undefined;
1182
+ /** Link. `href` is the URL, `title` is the optional title attribute. */
1183
+ link?: (children: string, meta: LinkMeta) => string | null | undefined;
1184
+ /** Image. `src` is the URL, `title` is the optional title attribute. */
1185
+ image?: (children: string, meta: ImageMeta) => string | null | undefined;
1186
+ /** Inline code (`` `code` ``). */
1187
+ codespan?: (children: string) => string | null | undefined;
1188
+ /** Strikethrough (`~~text~~`). */
1189
+ strikethrough?: (children: string) => string | null | undefined;
1190
+ /** Plain text content. */
1191
+ text?: (text: string) => string | null | undefined;
1192
+ }
1193
+
1194
+ /** Options for `react()` — parser options and element symbol configuration. */
1195
+ interface ReactOptions extends Options {
1196
+ /**
1197
+ * Which `$$typeof` symbol to use on the generated elements.
1198
+ * - `19` (default): `Symbol.for('react.transitional.element')`
1199
+ * - `18`: `Symbol.for('react.element')` — use this for React 18 and older
1200
+ */
1201
+ reactVersion?: 18 | 19;
1202
+ }
1203
+
1204
+ /**
1205
+ * Render markdown to an HTML string.
1206
+ *
1207
+ * @param input The markdown string or buffer to render
1208
+ * @param options Parser options
1209
+ * @returns An HTML string
1210
+ *
1211
+ * @example
1212
+ * ```ts
1213
+ * const html = Bun.markdown.html("# Hello **world**");
1214
+ * // "<h1>Hello <strong>world</strong></h1>\n"
1215
+ *
1216
+ * // With options
1217
+ * const html = Bun.markdown.html("## Hello", { headings: { ids: true } });
1218
+ * // '<h2 id="hello">Hello</h2>\n'
1219
+ * ```
1220
+ */
1221
+ export function html(
1222
+ input: string | NodeJS.TypedArray | DataView<ArrayBuffer> | ArrayBufferLike,
1223
+ options?: Options,
1224
+ ): string;
1225
+
1226
+ /**
1227
+ * Render markdown with custom JavaScript callbacks for each element.
1228
+ *
1229
+ * Each callback receives the accumulated children as a string and optional
1230
+ * metadata, and returns a string. Return `null` or `undefined` to omit
1231
+ * an element. If no callback is registered, children pass through unchanged.
1232
+ *
1233
+ * Parser options are passed as a separate third argument.
1234
+ *
1235
+ * @param input The markdown string to render
1236
+ * @param callbacks Callbacks for each element type
1237
+ * @param options Parser options
1238
+ * @returns The accumulated string output
1239
+ *
1240
+ * @example
1241
+ * ```ts
1242
+ * // Custom HTML with classes
1243
+ * const html = Bun.markdown.render("# Title\n\nHello **world**", {
1244
+ * heading: (children, { level }) => `<h${level} class="title">${children}</h${level}>`,
1245
+ * paragraph: (children) => `<p>${children}</p>`,
1246
+ * strong: (children) => `<b>${children}</b>`,
1247
+ * });
1248
+ *
1249
+ * // ANSI terminal output
1250
+ * const ansi = Bun.markdown.render("# Hello\n\n**bold**", {
1251
+ * heading: (children) => `\x1b[1;4m${children}\x1b[0m\n`,
1252
+ * paragraph: (children) => children + "\n",
1253
+ * strong: (children) => `\x1b[1m${children}\x1b[22m`,
1254
+ * });
1255
+ *
1256
+ * // With parser options as third argument
1257
+ * const text = Bun.markdown.render("Visit www.example.com", {
1258
+ * link: (children, { href }) => `[${children}](${href})`,
1259
+ * paragraph: (children) => children,
1260
+ * }, { autolinks: true });
1261
+ * ```
1262
+ */
1263
+ export function render(
1264
+ input: string | NodeJS.TypedArray | DataView<ArrayBuffer> | ArrayBufferLike,
1265
+ callbacks?: RenderCallbacks,
1266
+ options?: Options,
1267
+ ): string;
1268
+
1269
+ /**
1270
+ * Render markdown to React JSX elements.
1271
+ *
1272
+ * Returns a React Fragment containing the parsed markdown as children.
1273
+ * Can be returned directly from a component or passed to `renderToString()`.
1274
+ *
1275
+ * Override any HTML element with a custom component by passing it in the
1276
+ * second argument, keyed by tag name. Custom components receive the same props
1277
+ * the default elements would (e.g. `href` for links, `language` for code blocks).
1278
+ *
1279
+ * Parser options (including `reactVersion`) are passed as a separate third argument.
1280
+ * Uses `Symbol.for('react.transitional.element')` by default (React 19).
1281
+ * Pass `reactVersion: 18` for React 18 and older.
1282
+ *
1283
+ * @param input The markdown string or buffer to parse
1284
+ * @param components Component overrides keyed by HTML tag name
1285
+ * @param options Parser options and element symbol configuration
1286
+ * @returns A React Fragment element containing the parsed markdown
1287
+ *
1288
+ * @example
1289
+ * ```tsx
1290
+ * // Use directly as a component return value
1291
+ * function Markdown({ text }: { text: string }) {
1292
+ * return Bun.markdown.react(text);
1293
+ * }
1294
+ *
1295
+ * // Server-side rendering
1296
+ * import { renderToString } from "react-dom/server";
1297
+ * const html = renderToString(Bun.markdown.react("# Hello **world**"));
1298
+ *
1299
+ * // Custom components receive element props
1300
+ * function Code({ language, children }: { language?: string; children: React.ReactNode }) {
1301
+ * return <pre data-language={language}><code>{children}</code></pre>;
1302
+ * }
1303
+ * function Link({ href, children }: { href: string; children: React.ReactNode }) {
1304
+ * return <a href={href} target="_blank">{children}</a>;
1305
+ * }
1306
+ * const el = Bun.markdown.react(text, { pre: Code, a: Link });
1307
+ *
1308
+ * // For React 18 and older
1309
+ * const el18 = Bun.markdown.react(text, undefined, { reactVersion: 18 });
1310
+ * ```
1311
+ */
1312
+ export function react(
1313
+ input: string | NodeJS.TypedArray | DataView<ArrayBuffer> | ArrayBufferLike,
1314
+ components?: ComponentOverrides,
1315
+ options?: ReactOptions,
1316
+ ): import("./jsx.d.ts").JSX.Element;
1317
+ }
1318
+
908
1319
  /**
909
1320
  * JSON5 related APIs
910
1321
  */
package/lib/jsx.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export {};
2
+ export namespace JSX {
3
+ export type Element = ReactElement;
4
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bun-types-no-globals",
3
- "version": "1.3.7-canary.20260128T141311",
3
+ "version": "1.3.8-canary.20260129T141834",
4
4
  "main": "./generator/index.ts",
5
5
  "types": "./lib/index.d.ts",
6
6
  "description": "TypeScript type definitions for Bun without global types pollution",