handlebars-lang / handlebars-lang/handlebars.js

Be able to globally allow \n characters, convert to <br />

Open
#1,738 2 comments 1 reaction 0 assignees View on GitHub
breaking change feature
Dominant language
JavaScript
Stars
18.7k
Forks
2.1k
PR merge metrics
No merged PRs in 30d

Description

I use handlebars with Mpdf, which reads html and converts to pdf.

I have a large set of values, SOME may have newlines in them ```\n```, some may not. They currently do not carry through, meaning some values will not have their new lines represented properly.

I'm currently stuck with two choices, both are ugly workarounds:
- Convert all newline characters in values to ```
``` in advance, and then make ALL the Handlebars placeholders three brackets. This is undesirable as the template will be a pain to read, two brackets is plenty enough to deal with
- Try to do use a global css rule that uses white-space:pre-line, which risks breaking other aspects of the template.

New line characters are a special case in HTML as they don't really correspond to HTML entities the same way other special characters do. An ability to passive convert values in two brackets placeholders to ```
``` is the truest way to handle a situation like this. Even if it's just opt-in, I think it would be extremely useful.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing Handlebars' escaped and unescaped value-rendering behavior and how newline characters are currently handled. Define the opt-in behavior for converting newlines in double-brace placeholders to
, then add coverage demonstrating that enabled and disabled modes produce the expected output.

Written by the indexing model from the issue text.

Assessment

Tech stack
handlebars, javascript
Domain
web-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.