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

Markdown component not rendering images and also not rendering text in latex format #857

Closed
4 tasks done
agrajgarg opened this issue Sep 6, 2024 · 2 comments
Closed
4 tasks done
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on

Comments

@agrajgarg
Copy link

agrajgarg commented Sep 6, 2024

Initial checklist

Affected packages and versions

^9.0.0

Link to runnable example

No response

Steps to reproduce

import Markdown from 'react-markdown';
import rehypeRaw from 'rehype-raw';
import rehypeKatex from 'rehype-katex';
import remarkMath from 'remark-math';
import 'property-information';

const preprocessLaTeX = (content) => {

        const blockProcessedContent = content.replace(
          /\\\[(.*?)\\\]/gs,
          (_, equation) => `$$${equation}$$`,
        );
        
        const inlineProcessedContent = blockProcessedContent.replace(
          /\\\((.*?)\\\)/gs,
          (_, equation) => `$${equation}$`,
        );
        return inlineProcessedContent;
    };
    
    return (
         <>
            {text && text.length > 0 &&
                            text.map((message, index) => (
                                <div key={index} className="markdown" id="bot-msg">
                                    <Markdown
                                        remarkPlugins={[remarkMath]} 
                                        rehypePlugins={[rehypeRaw, rehypeKatex]}
                                        components={{
                                            img: ({node, ...props}) => <img style={{maxWidth: '100%'}} {...props} />
                                        }}
                                    >
                                        {preprocessLaTeX(message)}
                                    </Markdown>
                                </div>
                            ))
                        }
         </>
    )

When the text value is

! [Image 1] (image url)
! [Image 2] (image url)

This code was working till few days back. Without making any changes in the code, the functionality is not working for image rendering.

I am using Parcel as the bundler for my react web app

Expected behavior

Should render appropriate image using image tags and the href attribute of img tag set to the image url

Actual behavior

Rendering plain text. Not rendering appropriate img tags

Runtime

No response

Package manager

npm 8

OS

Windows

Build and bundle tools

Parcel

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Sep 6, 2024
@ChristianMurphy
Copy link
Member

Welcome @agrajgarg! 👋
Nothing has changed in react-markdown recently.

A few things which come to mind.

  1. the examples you give of images, aren't valid, image syntax doesn't allow spaces between ! and [ or between ] and (
  2. Your regex appears to turn the parts of image syntax () and [] into latex formulas instead

This doesn't appear to be a bug in react-markdown, you're welcome to ask follow up question in https://github.com/orgs/remarkjs/discussions, I'd recommend including a minimal reproducible example based off https://stackblitz.com/github/remarkjs/.github/tree/main/sandbox-templates/react-markdown-with-vite

@ChristianMurphy ChristianMurphy closed this as not planned Won't fix, can't repro, duplicate, stale Sep 6, 2024
@ChristianMurphy ChristianMurphy added the 🙋 no/question This does not need any changes label Sep 6, 2024

This comment has been minimized.

@github-actions github-actions bot added 👎 phase/no Post cannot or will not be acted on and removed 🤞 phase/open Post is being triaged manually labels Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

2 participants