0

As title indicates. I get a txt file and convert it to web content. The problem is it doesn't display diacritic signs, like o with dash over it or z with dot over. Charset is set to utf-8, language to "pl" and normally there was never any problems.

    <head>
    <meta charset="UTF-8">
  </head>
  <body>
    <button id="button">Display data</button>
    <div id="show">
    </div>
    <script>

    const data = [];
    const single = [];
    const button = document.querySelector("#button");
    const show = document.querySelector("#show");

    fetch('data.txt')
    .then(response => response.text())
    .then(text => data.push(text));

    function display() {
      const allOfThem = data[0].split("\r"); 
      allOfThem.forEach((person) => {
        let newP = document.createElement("p");
        newP.innerHTML = "Person's data:  " + person;
        show.appendChild(newP);
      })
    }

    button.addEventListener("click", display);
    </script>
  </body>
  • Most likely the textfile itself is not utf-8 encoded. You've to save the file as utf-8 encoded. – Teemu Mar 03 '18 at 15:16
  • National signs? language to "pl"? – Bergi Mar 03 '18 at 15:58
  • "*Charset is set to utf-8*"? Where did you do that, in the HTTP header? And the content is actually utf-8 as well? – Bergi Mar 03 '18 at 15:59
  • 1
    First, what is the character encoding of the text file? Next, please show minimal code to read the file "and convert it to web content". – Tom Blodget Mar 04 '18 at 04:58
  • Text file is saved as unicode text document in Notepad. Lang="pl" is attached to html . – Marcin Górecki Mar 04 '18 at 10:21
  • 1
    Notepad as in Windows' ye olde notepad? "Unicode" in that context means UTF16LE: https://stackoverflow.com/questions/13894898/unicode-file-in-notepad – Ilja Everilä Mar 04 '18 at 10:30
  • What does the HTTP Content-Type response header say for 'data.txt'? )(Open browser dev tools using the F12 key or equiv.) I.E., how are you communicating its character encoding? – Tom Blodget Mar 04 '18 at 22:29

1 Answers1

1

Okay guys, thank you for help. You were right : neither notepad nor WordPad encode txt to utf-8. I created a txt file with Atom, copypasted the text and read from that. And all characters are now as they should be.

Thank you, problem solved :)