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

p component overriding img component #813

Closed
4 tasks done
mdroidian opened this issue Feb 3, 2024 · 4 comments
Closed
4 tasks done

p component overriding img component #813

mdroidian opened this issue Feb 3, 2024 · 4 comments
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on

Comments

@mdroidian
Copy link

Initial checklist

Affected packages and versions

"react-markdown": "^9.0.1", "remark-gfm": "^4.0.0"

Link to runnable example

No response

Steps to reproduce

minimal vite app with react-pdf
pass content to

node: v18.17.0
npm: 9.6.7

import React from "react";
import {
  Document,
  Page,
  Text,
  View,
  PDFViewer,
  Image,
} from "@react-pdf/renderer";
import Markdown, { Components } from "react-markdown";
import remarkGfm from "remark-gfm";

type PdfProps = {
  content: string;
};

const components: Components = {
  img: ({ src }) => (
    <Image
      src={src}
      style={{
        objectFit: "contain",
      }}
    />
  ),
  p: ({ children }) => (
    <Text
      style={{
        marginBottom: 12,
        fontSize: 14,
      }}
    >
      {children}
    </Text>
  ),
};

const image1 = "https://i.imgur.com/t9nin3y.png";
const image2 = "https://i.imgur.com/OpJ2Y6L.png";
const image3 = "https://i.imgur.com/tjdLtYY.png";
const image4 = "https://i.imgur.com/hH8MxKm.png";

const Pdf: React.FC<PdfProps> = () => {
  const content = `images

  ![image1](${image1})

  ![image2](${image2})

  some text

  ![image3](${image3})

  ![image4](${image4})
  
  `;

  return (
      <PDFViewer style={{ height: "90vh", width: "90vw" }}>
        <Document>
          <Page>
            <View>
              <Markdown
                components={components}
                remarkPlugins={[[remarkGfm, { singleTilde: false }]]}
              >
                {content}
              </Markdown>
            </View>
          </Page>
        </Document>
      </PDFViewer>
  );
};

export default Pdf;

Expected behavior

Images adhere to objectFit: "contain"
Text is rendered

Actual behavior

Images are all tiny

image

If I remove the p component, images adhere to objectFit: "contain", but no text is shown

image

I am curious as to why this is the case.
How can I have images adhere to img and not p

Runtime

Other (please specify in steps to reproduce)

Package manager

Other (please specify in steps to reproduce)

OS

Windows

Build and bundle tools

Vite

@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 Feb 3, 2024
@ChristianMurphy
Copy link
Member

Welcome @mdroidian!
Sorry you ran into confusion.

CommonMark, the markdown standard this project follows wraps images in paragraph tags.

Either account for this in your styles.
Or apply https://github.com/remarkjs/remark-unwrap-images to change the document structure to remove the paragraphs.

@ChristianMurphy ChristianMurphy closed this as not planned Won't fix, can't repro, duplicate, stale Feb 3, 2024

This comment has been minimized.

@ChristianMurphy ChristianMurphy added the 🙋 no/question This does not need any changes label Feb 3, 2024
Copy link

github-actions bot commented Feb 3, 2024

Hi! Thanks for reaching out! Because we treat issues as our backlog, we close issues that are questions since they don’t represent a task to be completed.

See our support docs for how and where to ask questions.

Thanks,
— bb

@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 Feb 3, 2024
@mdroidian
Copy link
Author

@ChristianMurphy Thanks for the quick reply! 🙌 I'll give it a go tomorrow.

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