Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Markdown JSON string

Tags:

json

markdown

I'm trying to send a json string with markdown signs to an API. If I'm sending the following string it works fine:
"## Heading 2 \n * List item \n * List item"

But if I use the following string:

"## Heading 2 \n ## Heading 2 \n * List item \n * List item"

It will not work at all. The first \n just disappears and it makes a heading like:

Heading 2 ## Heading 2

What I need to achieve is this:

<p>A paragraph with some text.</p>
<h2>A heading</h2>
<ul>
    <li> item 1 </li>
    <li> item 1 </li>
</ul>
like image 391
Wouter den Ouden Avatar asked May 19 '16 11:05

Wouter den Ouden


1 Answers

This is because you space characters after your new line characters, so the actual Markdown code is this:

## Heading 2 
 ## Heading 2 
 * List item 
 * List item

How this is rendered depends a bit on your Markdown implementation, but it’s possible that there is some Markdown implementation that would add that second line after the heading on the first line.

You should remove those spaces to make sure that the code looks like this:

## Heading 2
## Heading 2
* List item
* List item

If that doesn’t work, try adding spaces between those segments:

## Heading 2

## Heading 2

* List item
* List item

Finally, if you want a paragraph before the heading, it should look like this:

A paragraph with some text.

## A heading

* item 1
* item 1
like image 94
poke Avatar answered Oct 19 '22 02:10

poke