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

Image rule breaks with any non-newline characters after closing parenthesis #65

Open
loudmouth opened this issue Aug 17, 2018 · 3 comments

Comments

@loudmouth
Copy link
Contributor

loudmouth commented Aug 17, 2018

I've discovered a very strange bug here that I can't understand. Basically, with markymark, if there is any non-newline character after the closing parenthesis ) for the ImageRule (i.e. )C is an example), then the Markdown converter will omit the TextAttachment that would normally be inserted into the NSAttributedString

Any ideas what may be going on?

Stepping through with the debugger, it looks like markymark is still correctly identifying the markdown image with the regex and returning the correct [MarkDownItem] array—in this case, the relevant image item will be picked up as a nested item: the data structure looks like this after exiting the markyMark.parseMarkDown(text) method (printed from lldb):

(lldb) po markdownItems
▿ 9 elements
  - 0 : <ParagraphMarkDownItem: 0x280261320>
  - 1 : <ParagraphMarkDownItem: 0x280261800>
  - 2 : <ParagraphMarkDownItem: 0x280262430>
  - 3 : <ParagraphMarkDownItem: 0x280262760>
  - 4 : <ParagraphMarkDownItem: 0x280262a90>
  - 5 : <ParagraphMarkDownItem: 0x280262dc0>
  - 6 : <ParagraphMarkDownItem: 0x2802630f0>
  - 7 : <ParagraphMarkDownItem: 0x280263420>
  - 8 : <ParagraphMarkDownItem: 0x280263720>

(lldb) po markdownItems.first!.markDownItems
▿ Optional<Array<MarkDownItem>>
  ▿ some : 2 elements
    ▿ 0 : <ImageMarkDownItem: 0x282ff84b0>
    - 1 : <InlineTextMarkDownItem: 0x280261710>

The ImageMarkDownItem is nested as the first item of the first ParagraphMarkDownItem in the array that is returned.

I think the issue is with the MarkDownConverter.convert(markdownItems) instance method (in this case I'm converting to NSAttributedString).

Here is my code:

static func attributedText(text: String, styling: Styling = styling()) -> NSAttributedString {
    let markyMark = MarkyMark() { $0.setFlavor(ContentfulFlavor()) }
    let markdownItems = markyMark.parseMarkDown(text)
    let config = MarkDownToAttributedStringConverterConfiguration(styling: styling)

    let converter = MarkDownConverter(configuration: config)
    let attributedText = converter.convert(markdownItems)
    return attributedText
}
@jvanzummeren
Copy link
Contributor

I've looked into this briefly but couldn't find the problem, i'll try to spend some time later this week to investigate it more. Interesting bug, i'll keep you posted.

@jvanzummeren
Copy link
Contributor

Hi JP,

Hadn't had time to look into this issue before unfortunately. Just tried to reproduce your issue, but either i can't reproduce it or i failed to understand the issue.

I tried the following markdown in the markymark Example project:

![My Apple](https://images.apple.com/my/apple-events/static/apple-events/september-2013/video/poster_large.jpg)A

Also tried the same syntax with a local image, both seem to work fine in the toView and the toAttributedString parser.

Would you mind creating a branch on the markymark example project that demonstrates this issue?

@loudmouth
Copy link
Contributor Author

Hey @jvanzummeren luckily this has been very low priority on my end so no worries about the delay. I'll try to get a branch isolating the problem in test or example before the weekend :-)

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

No branches or pull requests

3 participants