Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
tl;dr: This one-line PR allows images to create new paragraphs, by treating them like links, which are also inline elements.
Overview
This PR addresses an issue with the way that Ink currently handles images. Essentially, when an image is encountered outside of an existing paragraph fragment, Ink treats it as a fragment at the same level as
Heading
,HTML
,Blockquote
,CodeBlock
,HorizontalLine
orParagraph
.This prevents a bare image in its own paragraph from being surrounded by
<p></p>
, and probably causes some other undesirable behavior. Images should be treated the same as links, which are very similar and do have the expected behavior in Ink.Example
Same as a link, an image passed to the parser on its own should result in a surrounding paragraph:
![](img.jpg)
-><p><img src="img.jpg"/></p>
And the following Markdown should generate two paragraphs:
⚡️
However, currently Ink outputs:
Regression / Implications
Drafting this PR uncovered a different bug which I did not address. The unit tests in
ImageTests.swift
put their references on the next line, like so:Meanwhile, the
Link
tests all separate the reference by another line:Testing against other Markdown parsers, either style should work. However, currently (and also in this PR) in Ink, the reference must be separated by more than just a newline. And by making images behave more like links, those
Image
tests stopped working.So I introduced newlines in the
Image
tests to separate the references, and they are at least at parity with links now.Next steps
I made an effort to fix the reference behavior so that the following test would pass, but couldn't immediately see how to resolve it. @JohnSundell you may be able to work it out a lot faster!
Thanks again John!