Tuesday, 3 March 2020

Create an html file with paragraphs

I'm currently in the process of building an application with Electron, it's supposed to be a simple in-house application for my users to easily run files, get news, and check our knowledge base.Currently I have an `iframe` that loads my `news.html` file. I've created a form that takes the entered variables `title`, `date`, `author` and outputs them as my `news.html` however the body of the news is what is giving me pause. I am not sure how to turn paragraphs so that they are compatible with my html. I was thinking I'd have every new line (except the first) append `

` to the end of it.Here is the bulk of the code.function newsSubmit(){ let title = document.getElementById('news-title').value; let date = document.getElementById('news-date').value; let author = document.getElementById('news-author').value; let body = document.getElementById('news-body').value; printToText(title, date, author, body); } function printToText(title, date, author, body) { var header = ''+'\n'+'

'+'\n'+' '+'\n'+''+'\n'+''; var footer = ''+'\n'+''; var codeTitle = '

'+title+'

'; var codeDate = '

'+date+'

'; var codeAuthor = '

'+author+'

'; var content = header+'\n'+codeTitle + '\n' + codeDate + '\n' + codeAuthor+'\n'+footer; fs.writeFile('/path/to/the/news.html', content, function(err) { if (err) { return console.log(err); } }); } I have no issue pulling the data and saving it to an html file but trying to parse the `body` variable, for new paragraphs just isn't something I can wrap my head around at the moment.Yes I do also know that my code isn't the greatest looking or most efficient, cleaning will come later (maybe).Does anyone have an idea how I'd parse the `body` and turn line breaks into paragraphs?

Submitted March 03, 2020 at 08:02PM by akblais

No comments:

Post a Comment