Skip to content
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

Sync main to dev after 0.5.11 is released. #4225

Merged
merged 3 commits into from
Dec 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@

import Markdown from 'react-markdown'

import latex from 'highlight.js/lib/languages/latex'
import rehypeHighlight from 'rehype-highlight'
import rehypeHighlightCodeLines from 'rehype-highlight-code-lines'
import rehypeKatex from 'rehype-katex'
import rehypeRaw from 'rehype-raw'
import remarkMath from 'remark-math'
import 'katex/dist/katex.min.css'

import 'katex/dist/katex.min.css'
import 'highlight.js/styles/atom-one-dark.css'
import { useClipboard } from '@/hooks/useClipboard'

import { getLanguageFromExtension } from '@/utils/codeLanguageExtension'

export const MarkdownTextMessage = memo(
({ text }: { id: string; text: string }) => {
const clipboard = useClipboard({ timeout: 1000 })

Check warning on line 22 in web/screens/Thread/ThreadCenterPanel/TextMessage/MarkdownTextMessage.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

22 line is not covered with tests

function extractCodeLines(node: { children: { children: any[] }[] }) {
const codeLines: any[] = []

Check warning on line 25 in web/screens/Thread/ThreadCenterPanel/TextMessage/MarkdownTextMessage.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

25 line is not covered with tests

// Helper function to extract text recursively from children
function getTextFromNode(node: {
Expand All @@ -30,44 +30,44 @@
value: any
children: any[]
}): string {
if (node.type === 'text') {
return node.value
} else if (node.children) {
return node.children.map(getTextFromNode).join('')

Check warning on line 36 in web/screens/Thread/ThreadCenterPanel/TextMessage/MarkdownTextMessage.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

33-36 lines are not covered with tests
}
return ''

Check warning on line 38 in web/screens/Thread/ThreadCenterPanel/TextMessage/MarkdownTextMessage.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

38 line is not covered with tests
}

// Traverse each line in the <code> block
node.children[0].children.forEach(

Check warning on line 42 in web/screens/Thread/ThreadCenterPanel/TextMessage/MarkdownTextMessage.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

42 line is not covered with tests
(lineNode: {
type: string
tagName: string
value: any
children: any[]
}) => {
if (lineNode.type === 'element' && lineNode.tagName === 'span') {
const lineContent = getTextFromNode(lineNode)
codeLines.push(lineContent)

Check warning on line 51 in web/screens/Thread/ThreadCenterPanel/TextMessage/MarkdownTextMessage.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

49-51 lines are not covered with tests
}
}
)

// Join the lines with newline characters for proper formatting
return codeLines.join('\n')

Check warning on line 57 in web/screens/Thread/ThreadCenterPanel/TextMessage/MarkdownTextMessage.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

57 line is not covered with tests
}
function wrapCodeBlocksWithoutVisit() {
return (tree: { children: any[] }) => {
tree.children = tree.children.map((node) => {
if (node.tagName === 'pre' && node.children[0]?.tagName === 'code') {

Check warning on line 62 in web/screens/Thread/ThreadCenterPanel/TextMessage/MarkdownTextMessage.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

60-62 lines are not covered with tests
const language =
node.children[0].properties.className?.[1]?.replace(

Check warning on line 64 in web/screens/Thread/ThreadCenterPanel/TextMessage/MarkdownTextMessage.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

64 line is not covered with tests
'language-',
''
)

if (extractCodeLines(node) === '') {
return node

Check warning on line 70 in web/screens/Thread/ThreadCenterPanel/TextMessage/MarkdownTextMessage.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

69-70 lines are not covered with tests
}

return {
Expand Down Expand Up @@ -199,16 +199,7 @@
rehypePlugins={[
[rehypeKatex, { throwOnError: false }],
rehypeRaw,
[
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
rehypeHighlight,
{
languages: { latex },
subset: false,
plainText: ['txt', 'text'],
},
],
rehypeHighlight,
[rehypeHighlightCodeLines, { showLineNumbers: true }],
wrapCodeBlocksWithoutVisit,
]}
Expand Down
Loading