Created
March 10, 2025 12:17
-
-
Save hrdyjan1/5f8571847fb5d56026c21366cbd7a1af to your computer and use it in GitHub Desktop.
Anoto - New Transcript Text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'katex/dist/katex.min.css'; | |
| import { memo } from 'react'; | |
| import ReactMarkdown from 'react-markdown'; | |
| import { ContentRegion } from '~/models'; | |
| import Latex from 'react-latex-next'; | |
| import { formatTranscriptionsForDisplay, getPageTranscriptionsByFormat } from '~/lib/transcribe/utils'; | |
| interface TranscriptTextProps { | |
| contentRegions?: ContentRegion[]; | |
| } | |
| const formatLatex = (latexString: string, spacing = '10pt') => ` | |
| $$ | |
| ${latexString.trim().split('\n\n').join(` \\\\[${spacing}] \n`)} | |
| $$ | |
| `; | |
| function TranscriptText({ contentRegions = [] }: TranscriptTextProps) { | |
| const transcriptsByFormat = getPageTranscriptionsByFormat(contentRegions); | |
| const formattedTranscriptions = formatTranscriptionsForDisplay(transcriptsByFormat); | |
| return ( | |
| <div className="flex-1 text-sm" data-testid="transcript-text"> | |
| {formattedTranscriptions.map((transcription) => ( | |
| <div key={transcription.key} className="mb-5"> | |
| <div className="p-2 bg-gray-50 rounded-md"> | |
| <div className="flex items-center mb-2"> | |
| <transcription.Icon className="h-4 w-4 mr-2" /> | |
| <p className="text-sm font-medium">{transcription.name}</p> | |
| </div> | |
| {transcription.content ? ( | |
| <div className="overflow-auto max-h-80 bg-gray-100 rounded p-2"> | |
| {transcription.key === 'MARKDOWN' && ( | |
| <div className="[&>p]:mb-2 [&>p:last-child]:mb-0"> | |
| <ReactMarkdown>{transcription.content}</ReactMarkdown> | |
| </div> | |
| )} | |
| {transcription.key === 'LATEX' && transcription.content && ( | |
| <div className="[&_.katex-display_.katex]:text-left"> | |
| <Latex>{formatLatex(transcription.content)}</Latex> | |
| </div> | |
| )} | |
| {(transcription.key === 'HTML' || | |
| transcription.key === 'CSV' || | |
| transcription.key === 'MERMAID' || | |
| transcription.key === 'WOLFRAM_LANGUAGE') && ( | |
| <div className="whitespace-pre-wrap"> | |
| <p>{transcription.content}</p> | |
| </div> | |
| )} | |
| </div> | |
| ) : ( | |
| <div className="overflow-auto max-h-80 bg-gray-100 rounded p-2"> | |
| <div className="text-gray-500 italic border border-dashed border-gray-300 p-2 rounded"> | |
| <pre className="text-sm">{transcription.placeholder}</pre> | |
| </div> | |
| </div> | |
| )} | |
| </div> | |
| </div> | |
| ))} | |
| </div> | |
| ); | |
| } | |
| export default memo(TranscriptText); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment