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

Serialization to markdown fails when two marks start or end in the same position #216

Closed
katemihalikova opened this issue Feb 24, 2016 · 8 comments

Comments

@katemihalikova
Copy link
Contributor

Steps to reproduce

Bold text:
image
Link/code added to one of the words:
image
image
image
The markdown output contains mixed marks:
image
image
image

Version

Detected in v0.3.0 and v0.4.0, using Windows Chrome 48. Most recent commit is the v0.4.0 now.

@ericandrewlewis
Copy link
Collaborator

Thanks for the bug report @katemihalikova! I was able to reproduce this as well.

We'll need to look into how the document is being transformed to Markdown, and whether it's a bug in PM or something to do with markdown-it, our Markdown utility library.

@marijnh
Copy link
Member

marijnh commented Feb 24, 2016

It's almost certainly our serializer — markdown-it has been very solid so far. If someone knows of a Markdown-generation library (the escaping is non-trivial), I'd gladly switch to that. If it doesn't exist, we'll just have to continue shaping up ours.

@asteadman
Copy link

I've observed this behavior but was unable to pin down the source until now. Looking at the code for renderInline(parent) in to_markdown.js there appear to be a couple of issues.

Firstly, i'm not sure why the check for a code mark gets special treatment, but I think the .type == "code" checks are wrong (.type is not a string?). I think these checks should use the truthy .isCode ?

The more general problem seems to be that the stack is always traversed from k=0 to stack.length-1, even when flushing the stack /w progress(null), where as the stack should presumably be traversed in the reverse direction when flushing?

@ericandrewlewis
Copy link
Collaborator

the stack should presumably be traversed in the reverse direction when flushing

I was diagnosing this at the same time. Yep, that's the problem.

@asteadman
Copy link

Can you comment on the .type == "code" checks? I believe changing them to .type.isCode would inadvertently fix the 3rd test case, but i'm not sure why it's there at all. Is the code mark special for some reason? AFAICT, these checks currently never evaluate true, so the whole if statement and corresponding conditional block could presumably be removed.

@ericandrewlewis
Copy link
Collaborator

I believe changing them to .type.isCode would inadvertently fix the 3rd test case

#235 fixes the first and third test cases. It seems the second text case will be trickier to fix.

AFAICT, these checks currently never evaluate true

Yes, good find. Can you open up a separate issue and perhaps a pull request with the change?

@ericandrewlewis
Copy link
Collaborator

If someone knows of a Markdown-generation library (the escaping is non-trivial), I'd gladly switch to that.

I think what we're looking for is a library that supports an abstract syntax tree data type for Markdown (which we can transform our document model into), which also supports converting the AST to Markdown. This would be very desirable given the second test case originally shared on this issue.

Briefly Googled around for this today. commonmark.js already has an AST representation, and is discussing adding AST → Markdown support.

marijnh added a commit that referenced this issue Mar 3, 2016
The code still isn't great -- it hard-codes a mark name, which it
should not be doing -- but at least it sort of works now.

Issue #216
marijnh added a commit that referenced this issue Mar 3, 2016
@marijnh
Copy link
Member

marijnh commented Mar 3, 2016

Attached patches, along with b43d167, should address this issue.

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

4 participants