swiftlang / swift-markdown

A Swift package for parsing, building, editing, and analyzing Markdown documents.
https://swiftpackageindex.com/swiftlang/swift-markdown/documentation/markdown
Apache License 2.0
2.79k stars 191 forks source link

don't automatically transfer the child elements' ranges to the parent #202

Closed QuietMisdreavus closed 2 months ago

QuietMisdreavus commented 2 months ago

Bug/issue #, if applicable: rdar://136218537

Summary

The subsitutingChild(_:through:) method on RawMarkup introduced in https://github.com/swiftlang/swift-markdown/pull/196 has the option to preserve the element's original source range. However, this fell back to the new child's range if its parent had no source range. This caused an issue where the assertion in the Aside initializer was being tripped when a BlockQuote had no parsed range, but its inner Paragraph did. This PR removes the fallback and just copies in the parent's source range if the preserveRange option is set.

In a separate commit, i also added a new initializer requirement to BasicBlockContainer that adds an inheritSourceRange option, to allow the new container to inherit the source range of its children even though it's a synthetic wrapper. This method can be used in Swift-DocC when a list item is converted into an aside to propagate that source range up through the new aside.

Dependencies

None

Testing

As this is an API change, the functionality is covered by automated testing.

Checklist

Make sure you check off the following items. If they cannot be completed, provide a reason.

QuietMisdreavus commented 2 months ago

@swift-ci Please test

QuietMisdreavus commented 2 months ago

@swift-ci Please test

QuietMisdreavus commented 2 months ago

@swift-ci Please test

QuietMisdreavus commented 2 months ago

@swift-ci Please test