used replace with regex to add a space to line endings where needed before the split. This makes up for the fact that textContent removes newlines.