-
Notifications
You must be signed in to change notification settings - Fork 1
[CAI-558] [CAI-569] Fix link parsing in chat, update documentation parsing for special character \ #1712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[CAI-558] [CAI-569] Fix link parsing in chat, update documentation parsing for special character \ #1712
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"gitbook-docs": minor | ||
"nextjs-website": minor | ||
--- | ||
|
||
Fix chat message parsing and update markdown parsing |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,7 +1,9 @@ | ||||||
import ChatLink from '@/components/atoms/ChatLink/ChatLink'; | ||||||
import Markdoc, { Config, ConfigType, Node } from '@markdoc/markdoc'; | ||||||
import Markdoc, { Config, ConfigType, Node, Tag } from '@markdoc/markdoc'; | ||||||
import React, { ReactNode } from 'react'; | ||||||
|
||||||
import { PageTitlePath } from '@/helpers/parseS3Doc.helpers'; | ||||||
const capitalizeFirstLetter = (text: string): string => | ||||||
text.charAt(0).toUpperCase() + text.slice(1); | ||||||
const chatMarkdocConfig: ConfigType = { | ||||||
nodes: { | ||||||
link: { | ||||||
|
@@ -12,12 +14,39 @@ const chatMarkdocConfig: ConfigType = { | |||||
title: { type: String }, | ||||||
}, | ||||||
transform(node: Node, config: Config) { | ||||||
const attributes = node.transformAttributes(config); | ||||||
return new Markdoc.Tag( | ||||||
'Link', | ||||||
attributes, | ||||||
node.transformChildren(config) | ||||||
const attrs = node.transformAttributes(config); | ||||||
const gitBookPagesWithTitle: ReadonlyArray<PageTitlePath> = | ||||||
config.variables ? [...config.variables.gitBookPagesWithTitle] : []; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The spread operator creates a new array unnecessarily. Since you're only reading from the array, you can use it directly:
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
const page = gitBookPagesWithTitle.find( | ||||||
({ path }) => path === attrs.href | ||||||
); | ||||||
|
||||||
const childrenTreeNode = node.transformChildren(config); | ||||||
|
||||||
const titleFromPage = | ||||||
childrenTreeNode && | ||||||
typeof childrenTreeNode[0] === 'string' && | ||||||
childrenTreeNode[0].endsWith('.md') && | ||||||
page | ||||||
? page.title | ||||||
: undefined; | ||||||
Comment on lines
+26
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] This complex conditional logic should be extracted into a helper function for better readability and testability. Consider creating a Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
|
||||||
const titleFromAnchor = | ||||||
childrenTreeNode && | ||||||
typeof childrenTreeNode[0] === 'string' && | ||||||
childrenTreeNode[0].startsWith('#') | ||||||
? capitalizeFirstLetter( | ||||||
childrenTreeNode[0].replace('#', '').replaceAll('-', ' ') | ||||||
) | ||||||
: undefined; | ||||||
Comment on lines
+34
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] Similar to the previous comment, this conditional logic should also be extracted into a helper function like Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
|
||||||
const children = titleFromPage | ||||||
? [titleFromPage] | ||||||
: titleFromAnchor | ||||||
? [titleFromAnchor] | ||||||
: childrenTreeNode; | ||||||
|
||||||
return new Tag('Link', attrs, children); | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.