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

Debug regex for ImageRule #43

Closed
wants to merge 1 commit into from

Conversation

loudmouth
Copy link
Contributor

@loudmouth loudmouth commented Jan 31, 2018

The regex for ImageRule was broken. It would take any ! as the start of an inline image even if there was no image present in the markdown text if there was a regular link later in the same string.

i.e. this was breaking and being rendered as an image: "Congratulations! Here is some text, head over to the Example site"

I've fixed the regex. You can test with the following string here

proper regex: !\[([^]]*)\]\(([^]]+)\)
proper regex with extra escapes for swift strings: !\\[([^]]*)\\]\\(([^]]+)\\)
test string:
"Congratulations! Here is some text, head over to the Example site Alt text or contact support.

Alt text

Alt text
a
"

@jvanzummeren
Copy link
Contributor

I was testing your pull request and discovered that your regex was producing different capture groups causing the converting to ImageMarkDownItem to fail (and the unit tests were also failing).
Fixed the problem in this commit: 2f5b426

I'm going to write some unit tests on monday to cover the problems you discovered. Also added a non-greedy modifier to the regex to improve the result.

Instead of today, i'll make a new Markymark version on monday.

Kind regards,

Jim

@loudmouth loudmouth deleted the bugfix/ImageRule-regex branch August 17, 2018 14:01
@loudmouth
Copy link
Contributor Author

@jimvanzummeren I've discovered a very strange bug here that I can't understand. Basically, with markymark, if there is any non-linebreak character after the closing parenthesis ) for the ImageRule (i.e. )C is an example), then the Markdown converter will omit the TextAttachement 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...i think something else may be going on.

@loudmouth
Copy link
Contributor Author

loudmouth commented Aug 17, 2018

Some more info on this: it looks like by the time the parseMarkdown(:) method returns, the relevant ImageMarkdownItem is stripped from the returned array or [MarkdownItem]

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

Successfully merging this pull request may close these issues.

None yet

2 participants