jeudi 29 novembre 2018

Load file and parse document

I have a code for displaying whole document in a HTML

    <!DOCTYPE HTML>
   <html>
    <head>
    <script>
      let openFile = function(event) {
        let input = event.target;
        let reader = new FileReader();
        reader.onload = function(){
          let text = reader.result;
          let node = document.getElementById('output');
                node.innerText = text;
          console.log(reader.result.substring(0, 200));
        };
        reader.readAsText(input.files[0]);
      };
    </script>
    </head>
    <body>
    <input type='file' accept='text/plain' onchange='openFile(event)'><br>
    <div id='output'>
    </div>
    </body>
    </html>

I need to load a document then display only strings I need - names and url like:

Document example:

#NAME:Elis:
http://elis.com
#NAME: Emma
http://emma.com

Display:

<a href=http://elis.com>Elis</a>
<a href=http://emma.com>Emma</a>




Aucun commentaire:

Enregistrer un commentaire