0

I am working on a React project and I am making a UI where it will show the shell script to the users and they can choose options from the dropdown.

Example of what user see on the UI:

!#/bin/bash

###Dropdown1
echo {option1}

###Dropdown2
echo {option2}

my code below

// in MainPage.js

const Script = (option1, option2) => {
  return `
!#/bin/bash

###Dropdown1
echo {option1}

\n###Dropdown2
echo {option2}
`;
};

function MainPage() {
  return (
    <div className="left">
      <pre> {Script(option1, option2)}; </pre>
    </div>
  );
}

I would like to prettify it as the dropdown options may be very long in text, so it will look cluttered.

Any ideas how I can do this on React? I was looking at prettier-plugin-sh but that seems to be prettify the code on the IDE, instead of my UI. I am new to React so I am not sure how to approach this. Thanks!

5
  • Do you have the code you've tried already? See stackoverflow.com/help/minimal-reproducible-example Commented Jun 25 at 16:58
  • Added my code, thanks!
    – vvv-1234
    Commented Jun 26 at 2:06
  • What do you mean by prettify in this case? Are you talking about having syntax highlighting by any chance? Or do you mean re-formatting the code inside the pre tag?
    – moonstar-x
    Commented Jun 26 at 14:51
  • @moonstar-x i meant like indentation and styling.
    – vvv-1234
    Commented Jun 27 at 15:35
  • I think you are looking for prettier.
    – Shuo
    Commented Jul 2 at 2:00

0

Browse other questions tagged or ask your own question.