#Modify html before sending to browser

1 messages · Page 1 of 1 (latest)

misty geyser
#

I have a requirement to add a superscript tag for all registered marks in a page. I need to run a string replace regex on the final html generated by nextjs server. How can I achieve this?

wooden apexBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

crystal temple
#

wait I don't think thats available

crystal temple
#

I think you can wrap everything in a server component, by converting the children prop

#

What you can do is wrap something like

       <SuperscriptRegistered>
          We love BrandX® and BrandY®. The BrandZ® series is coming soon.
        </SuperscriptRegistered>

and SuperscriptRegistered

import React from 'react';

type Props = {
  children: string;
};

export default function SuperscriptRegistered({ children }: Props) {
  // Replace all occurrences of ® with superscript
  const replaced = children.replace(/®/g, '<sup>®</sup>');

  return (
    <span dangerouslySetInnerHTML={{ __html: replaced }} />
  );
}

You can wrap it around every text.

Or you can use a similar approach to wrap everything, but I'm not sure if it'll work, as it'll be too complex