I'm doing some tests on the Fetch function, and I'm using a txt file that should have like linebreaks/highlighted titles.
And when I imported the text and put into a variable, the console.log() showed up as it's supposed to. But using DOM to put into the HTML, the text just ignore everything but letters and spaces.
There's a way to correct that? Or I should try it another way?
Code below (only using the fetch function, the txt file is unnecessary I believe):
let basicText = ''
async function getBasicText(){
const resposta = await fetch('./textos/pctBasico.txt')
const texto = await resposta.text();
let basicText = document.getElementById('pctBasicoDetail')
basicText.innerHTML = texto
}
getBasicText()
Example:
*BOLD TITLE* Paragraph *ITALIC SENTENCE* *BOLD TITLE* Another paragraph
But it all goes one thing like:
TITLE PARAGRAPH SENTENCE TITLE PARAGRAPH
I think you can keep line breaks if you use pre tag. But you couldn't keep format of txt. Then how can you format text as BOLD and ITALIC in .txt file? You should use .md file.
In .md, file you can format text using **bold** and *italic*. Then you can use components displaying md files.