0

I have a string in Java:

String str = "first line\nsecond line";

This string is fed to a field which reads the daringfireball markdown. \n is not recognized so I use

String str = "first line<br/>second line";

However this html markup is quite unnecessary in the other output formats that I use for this string.

=> Is there a way I can can get a line break in markdown without including <br/> in my java string?

[background: through the API of this website I feed a string to the description field of a resource which accepts markdown, here: http://datahub.io/dataset/testapi/resource/6ad9aaba-cb47-45ff-98ed-c92ead0a1c35. As you can see there are neat line breaks between image.agent, image.date, etc. I obtain them by putting some <br/> markup, but I find that it defeats the purpose of makrdown.]

seinecle
  • 10,118
  • 14
  • 61
  • 120
  • I think you mean `
    ` rather than ``. Also, you haven't given enough information to know what you're *doing* with this string value.
    – Jon Skeet Jan 24 '13 at 15:10
  • 2
    Markdown shouldn't need anything other than newlines to represent newlines. Without knowing how it's being parsed or what you're actually doing it's difficult to help. – Dave Newton Jan 24 '13 at 15:11
  • maybe _System.getProperty("line.separator")_ would do the job. – Juvanis Jan 24 '13 at 15:12
  • Thanks for the correction. This string value can be later put in an xml format, for instance. I don't want to get embroiled in unescaping html stuff from my string if I can. – seinecle Jan 24 '13 at 15:13
  • Did you try `\n\r` or what @Juvanis sugested? – Moritz Petersen Jan 24 '13 at 15:19

1 Answers1

1

From http://daringfireball.net/projects/markdown/syntax#p

When you do want to insert a <br /> break tag using Markdown, you end a line with two or more spaces, then type return.

Is this what you're looking for?

Joe Bane
  • 1,556
  • 1
  • 15
  • 30
  • Yes I read that but I can't type "return", as the text is not inserted manually but programmatically through java code. Tried to put several spaces to flag the end of the line but that does not do it. – seinecle Jan 24 '13 at 15:40
  • OK, but have you tried using two or more spaces followed by a '\n' or '\r\n' character? – Joe Bane Jan 24 '13 at 15:42
  • You could also try using two newline characters "\n\n" (which creates a blank line that markdown will interpret as a new paragraph). – Joe Bane Jan 24 '13 at 15:49