crossroadlabs / Markdown

Swift markdown library
GNU General Public License v3.0
80 stars 10 forks source link

text is cut before the end #4

Open neywen opened 8 years ago

neywen commented 8 years ago

I use the library to display a "terms and conditions" text. The generated document is cut before the end of the source text.

the debug process:

let contents = try NSString(contentsOfFile: filepath, usedEncoding: nil) as String gives:

[...]se réserve la faculté de modifier à tout moment, de plein droit et sans formalités, les présentes CGU[...]

let md = try Markdown(string:contents)
let document = try md.document()

gives :

se réserve la faculté de modifier à tout moment, de plein droi

"

dileping commented 8 years ago

Hi @neywen, sorry for the late reply. Had a very intense business trip and was barely available.

Was trying to reproduce the bug, with no luck unfortunately. Could you elaborate, please, and send the whole file?

Best, Daniel

twostraws commented 7 years ago

I'm having a similar issue, and it might be caused by the same problem: Windows-style line breaks, i.e. \r\n rather than just \n. I believe this is also the HTML standard, so it's not uncommon.

Here's some sample code that demonstrates the problem in the current 1.0.0-alpha2 tag:

import Markdown

let test1 = "Testing1.\n\nTesting2."
let test2 = "Testing1.\r\n\r\nTesting2."

if let result1 = try? Markdown(string: test1) {
    if let doc1 = try? result1.document() {
        print(doc1)
    }
}

if let result2 = try? Markdown(string: test2) {
    if let doc2 = try? result2.document() {
        print(doc2)
    }
}

That prints the following:

<p>Testing1.</p>

<p>Testing2.</p>
<p>Testing1.</p>

<p>Testing</p>

Note the final <p> tag is incorrect - it has been chopped.

In my tests locally just replacing \r\n with \n before handing it to Markdown(string:) solves the problem.

dileping commented 7 years ago

@twostraws Thanks a lot for the example! Is there any chance you could make a PR with an automatic test for this?