Customized plain text render to hide select elements #686
Replies: 3 comments 1 reply
-
So, I'm currently looking for the exact same feature. With the code snippet you have linked it seems to be a one line addition (now in here). Just adding a class that hides the element in plainText mode. I've searched for it, but didn't find a PR. Did you open one yet? |
Beta Was this translation helpful? Give feedback.
-
Here is a PR: #1922 |
Beta Was this translation helpful? Give feedback.
-
Here's a better idea: we can simply store the rendering options in some global variable, and return it in a hook-like function import { useRenderingOptions } from '@react-email/render';
function MyEmail() {
const renderingOptions = useRenderingOptions();
if (renderingOptions.plainText) {
return 'This is the text according to what I would prefer';
}
return <a href="https://react.email">This is the text according to what I would prefer</a>;
} @thena-seer I see you made a PR with the other proposal, if you'd like to contribute an implementation of this, feel free to use this instead. I had this planned a while back from a discussion I had on Discord. |
Beta Was this translation helpful? Give feedback.
-
Goals
Background
The company logo in our email template is hyperlinked to our website and rendering our emails to plaintext gives us:
Email code:
What I want is to hide that link that wraps our logo:
Proposal
This could be solved w/ a special classname or data attribute that can be passed which filter uses in it's rules to remove:
https://github.com/resendlabs/react-email/blob/d158ad77e3798808b4efbd322b618922da12529e/packages/render/src/render.ts#L31-L34
Suggested options
dataPlainText={false}
(or similar) attribute inrenderAsPlainText
__react-email-plaintext-skip
to hide elements inrenderAsPlainText
<PlainText hide={true}>{children}</PlainText>
or similar component that can wrap elements to hide on plaintext renders<Visible plaintext>{children}</Visible>
/<Visible html>{children}</Visible>
/<Visible html plaintext>{children}</Visible>
that can wrap elements and the user can explicitly set if they want something to render on one or the other.Current workaround
My current hack is to use
__react-email-preview
, although it's not good HTML to have multiples of the sameid
attr.Beta Was this translation helpful? Give feedback.
All reactions