Hello,
My friend gave me a code to try a bit. What it does is that it gets a text and format it. Here it is:

function boldAndItalicize(text) {
  return text.replace(/&/g, '&').replace(/</g, '<')
      .replace(/(\*+)([^*]{1,1024})(\*+)/g,
               function (whole, open, content, close) {
                 if (open.length === close.length) {
                   switch (open.length) {
                     case 1: return '<i>' + content + '</i>';
                     case 2: return '<b>' + content + '</b>';
                   }
                 }
                 return whole;
               });
}

But I want to know how I could input a plain text file(like test.txt , that is on the same folder as the script) in the text parameter?

Best Regards,
Nathan Paulino Campos

It's best to use php, for example, to echo the file into the javascript var.

var text = <?php echo json_encode(file_get_contents('test.txt')); ?>;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.