@connectif/ui-components 2.0.15 → 2.0.16

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.
@@ -4,8 +4,12 @@ type MarkdownContainerProps = {
4
4
  color: string;
5
5
  backgroundColor?: string;
6
6
  variant?: TypographyVariant;
7
+ /**
8
+ * Class Name to append to container
9
+ */
10
+ className?: string;
7
11
  };
8
- declare const MarkdownRenderer: ({ text, ...rest }: MarkdownContainerProps & {
12
+ declare const MarkdownRenderer: ({ text, className, ...rest }: MarkdownContainerProps & {
9
13
  text: string;
10
14
  }) => import("react/jsx-runtime").JSX.Element;
11
15
  export default MarkdownRenderer;
package/dist/index.js CHANGED
@@ -24264,24 +24264,17 @@ var MarkdownContainer = styled8("div")(
24264
24264
  backgroundColor: backgroundColor2,
24265
24265
  borderRadius: "8px",
24266
24266
  overflowWrap: "break-word",
24267
- "& h1, & h2, & h3": {
24268
- color: color2
24269
- },
24267
+ "& h1, & h2, & h3": { color: color2 },
24270
24268
  "& h1": { fontSize: "1.75rem" },
24271
24269
  "& h2": { fontSize: "1.5rem" },
24272
24270
  "& h3": { fontSize: "1.25rem" },
24273
- "& p": {
24274
- ...variants[variant || "body2"],
24275
- margin: "0.5em 0"
24276
- },
24271
+ "& p": { ...variants[variant || "body2"], margin: "0.5em 0" },
24277
24272
  "& ul, & ol": {
24278
24273
  ...variants[variant || "body2"],
24279
24274
  paddingLeft: "1.5em",
24280
24275
  margin: "0.5em 0"
24281
24276
  },
24282
- "& li": {
24283
- marginBottom: "0.25em"
24284
- },
24277
+ "& li": { marginBottom: "0.25em" },
24285
24278
  "& code": {
24286
24279
  background: grey800,
24287
24280
  padding: "2px 6px",
@@ -24290,11 +24283,7 @@ var MarkdownContainer = styled8("div")(
24290
24283
  fontSize: "0.9em",
24291
24284
  color: white
24292
24285
  },
24293
- "& pre code": {
24294
- display: "block",
24295
- padding: "12px",
24296
- overflowX: "auto"
24297
- },
24286
+ "& pre code": { display: "block", padding: "12px", overflowX: "auto" },
24298
24287
  "& table": {
24299
24288
  width: "100%",
24300
24289
  borderCollapse: "collapse",
@@ -24305,37 +24294,38 @@ var MarkdownContainer = styled8("div")(
24305
24294
  padding: "8px",
24306
24295
  textAlign: "left"
24307
24296
  },
24308
- "& th": {
24309
- backgroundColor: grey900,
24310
- color: white
24311
- },
24312
- "& a": {
24313
- color: primary200,
24314
- textDecoration: "none"
24315
- },
24316
- "& a:hover": {
24317
- textDecoration: "underline"
24318
- }
24297
+ "& th": { backgroundColor: grey900, color: white },
24298
+ "& a": { color: primary200, textDecoration: "none" },
24299
+ "& a:hover": { textDecoration: "underline" }
24319
24300
  })
24320
24301
  );
24302
+ var normalizeLatexDelimiters = (s) => {
24303
+ if (!s) {
24304
+ return s;
24305
+ }
24306
+ s = s.replace(/\\\\?\[([\s\S]*?)\\\\?\]/g, (_, inner) => `$$${inner}$$`);
24307
+ s = s.replace(/\\\\?\(([\s\S]*?)\\\\?\)/g, (_, inner) => `$${inner}$`);
24308
+ return s;
24309
+ };
24321
24310
  var renderWithMath = (text) => {
24322
24311
  const parts = [];
24323
- const regex = /\$\$([\s\S]+?)\$\$|\$([\s\S]+?)\$/g;
24312
+ const regex = /\$\$([\s\S]+?)\$\$|\$(?!\$)([\s\S]+?)\$/g;
24324
24313
  let lastIndex = 0;
24325
24314
  let match;
24326
24315
  while ((match = regex.exec(text)) !== null) {
24327
- const [full, blockExpr, inlineExpr] = match;
24328
24316
  const start = match.index;
24329
24317
  if (start > lastIndex) {
24330
24318
  parts.push(text.slice(lastIndex, start));
24331
24319
  }
24332
- if (blockExpr) {
24320
+ const block = match[1];
24321
+ const inline = match[2];
24322
+ if (block !== void 0) {
24333
24323
  parts.push(
24334
- /* @__PURE__ */ jsx137(KatexRenderer_default, { block: true, children: blockExpr.trim() }, start)
24324
+ /* @__PURE__ */ jsx137(KatexRenderer_default, { block: true, children: block.trim() }, start)
24335
24325
  );
24336
- } else if (inlineExpr) {
24326
+ } else if (inline !== void 0) {
24337
24327
  parts.push(
24338
- /* @__PURE__ */ jsx137(KatexRenderer_default, { children: inlineExpr.trim() }, start)
24328
+ /* @__PURE__ */ jsx137(KatexRenderer_default, { children: inline.trim() }, start)
24339
24329
  );
24340
24330
  }
24341
24331
  lastIndex = regex.lastIndex;
@@ -24345,34 +24335,61 @@ var renderWithMath = (text) => {
24345
24335
  }
24346
24336
  return parts;
24347
24337
  };
24338
+ var renderChildrenWithMath = (children) => React76.Children.map(children, (child) => {
24339
+ if (typeof child === "string") {
24340
+ return renderWithMath(child);
24341
+ }
24342
+ if (React76.isValidElement(child)) {
24343
+ return React76.cloneElement(child, {
24344
+ ...child.props,
24345
+ children: renderChildrenWithMath(child.props.children)
24346
+ });
24347
+ }
24348
+ return child;
24349
+ });
24350
+ var CodeOrMath = ({ children, ...props }) => {
24351
+ const raw = Array.isArray(children) ? children.map((c) => typeof c === "string" ? c : "").join("") : typeof children === "string" ? children : "";
24352
+ const s = raw.trim();
24353
+ const fullMath = /^\$\$([\s\S]+)\$\$$|^\$(?!\$)([\s\S]+)\$$/;
24354
+ const m = s.match(fullMath);
24355
+ if (m) {
24356
+ const expr = m[1] || m[2] || "";
24357
+ const isBlock = Boolean(m[1]);
24358
+ return /* @__PURE__ */ jsx137(KatexRenderer_default, { block: isBlock, children: expr.trim() });
24359
+ }
24360
+ const maybe = renderWithMath(s);
24361
+ const onlyText = maybe.length === 1 && typeof maybe[0] === "string";
24362
+ return onlyText ? /* @__PURE__ */ jsx137("code", { ...props, children }) : /* @__PURE__ */ jsx137("span", { children: maybe });
24363
+ };
24348
24364
  var MarkdownRenderer = ({
24349
24365
  text,
24366
+ className,
24350
24367
  ...rest
24351
- }) => /* @__PURE__ */ jsx137(MarkdownContainer, { ...rest, children: /* @__PURE__ */ jsx137(
24352
- Markdown,
24353
- {
24354
- options: {
24355
- forceBlock: true,
24356
- overrides: {
24357
- p: {
24358
- component: ({ children, ...props }) => {
24359
- const renderChildren = React76.Children.map(
24360
- children,
24361
- (child) => {
24362
- if (typeof child === "string") {
24363
- return renderWithMath(child);
24364
- }
24365
- return child;
24366
- }
24367
- );
24368
- return /* @__PURE__ */ jsx137("p", { ...props, children: renderChildren });
24369
- }
24368
+ }) => {
24369
+ const normalized = normalizeLatexDelimiters(text || "");
24370
+ return /* @__PURE__ */ jsx137(
24371
+ MarkdownContainer,
24372
+ {
24373
+ className: `markdown-container ${className || ""}`,
24374
+ ...rest,
24375
+ children: /* @__PURE__ */ jsx137(
24376
+ Markdown,
24377
+ {
24378
+ options: {
24379
+ forceBlock: true,
24380
+ overrides: {
24381
+ p: {
24382
+ component: ({ children, ...props }) => /* @__PURE__ */ jsx137("p", { ...props, children: renderChildrenWithMath(children) })
24383
+ },
24384
+ code: { component: CodeOrMath }
24385
+ }
24386
+ },
24387
+ children: normalized
24370
24388
  }
24371
- }
24372
- },
24373
- children: text
24374
- }
24375
- ) });
24389
+ )
24390
+ }
24391
+ );
24392
+ };
24376
24393
  var MarkdownRenderer_default = MarkdownRenderer;
24377
24394
 
24378
24395
  // src/components/navbar/Navbar.tsx