Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text is cut before the end #4

Open
neywen opened this issue Sep 12, 2016 · 3 comments
Open

text is cut before the end #4

neywen opened this issue Sep 12, 2016 · 3 comments

Comments

@neywen
Copy link

neywen commented Sep 12, 2016

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
Copy link
Member

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
Copy link

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
Copy link
Member

dileping commented Dec 1, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants