Markdown Line Breaks

I have a json file that has a list of ingredients for a recipe. The ingredient variable has a bunch of line breaks \n to denote a new line in markdown. When I display this in my notebook in a JavaScript cell it works fine, but when I display it in a markdown cell it does not seem to notice the line breaks?

Here is the notebook: Paprika / Scott Franz | Observable

1 Like

Markdown on Observable accepts basic HTML so you could use <br> elements to generate line breaks. To do that programmatically, try:

${recipes[0].ingredients.replace(/\n/g, '<br>\n')}

in your markdown cell. Even better, you might try

- ${recipes[0].ingredients.replace(/\n/g, '\n- ')}

to generate a bulleted list. :slight_smile:

1 Like