Skip to content

Change behavior of "__" #1182

Answered by notunderctrl
Luna-devv asked this question in Q&A
Jul 4, 2023 · 2 comments · 4 replies
Discussion options

You must be logged in to vote

I don't think react markdown supports underlining using markdown. Here's a workaround you could use:

import ReactMarkdown from "react-markdown";
import rehypeRaw from "rehype-raw";

const content = "this is an __underlined__ text";

function parseUnderline(content) {
  return content.replace(/__(.*?)__/g, "<u>$1</u>");
}

export default function App() {
  return (
    <ReactMarkdown rehypePlugins={[rehypeRaw]}>
      {parseUnderline(content)}
    </ReactMarkdown>
  );
}

This makes use of the rehype-raw plugin which allows HTML as input.
The parseUnderline function will convert all the "__" to "u" HTML tags

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@ChristianMurphy
Comment options

@puopg
Comment options

@puopg
Comment options

@puopg
Comment options

Answer selected by Luna-devv
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants