functional implementation with ramda
import { always, curry, ifElse, isEmpty, pipe, split, join, map } from "ramda" const html = curry((tagName, str) => `<${tagName}>${str}</${tagName}>`) const h1 = html("h1") const p = html("p") const br = always("<br>") const formatLines = map(ifElse(isEmpty, br, p)) const formatText = ([title, ...lines]) => [h1(title), ...formatLines(lines)] const textToHTML = pipe( split("\n"), formatText, join("\n") )
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
functional implementation with ramda