Support optional includes for page fragments #517
Merged
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.
What is the purpose of this pull request? (put "X" next to an item, remove the rest)
• [X] Enhancement to an existing feature
Resolves #497.
What is the rationale for this request?
Currently, we allow optional inclusion of whole documents with the
optional
tag eg.<include src="doc.md" optional />
. This PR extends this functionality to page fragments as well eg.<include src="doc.md#segment" optional />
will be included only if#segment
exists.What changes did you make? (Give an overview)
When a page fragment that is included does not exist, we check first if the
optional
tag is used. If so, we include an empty string in place, leading to an empty<div>
. If not, an error is emitted that the page fragment included does not exist.Provide some example code that this change will affect:
Is there anything you'd like reviewers to focus on?
In previous versions, inclusion of nonexistent page fragments lead to a
<div>
with the stringnull
being included instead. Since this behavior is likely to be confusing with the addition ofoptional
, I have chosen to change this so that an error is emitted when an included page fragment does not exist andoptional
was not used. I have also added tests to verify this new behavior alongside those that verify the behavior ofoptional
with page fragments.Testing instructions:
optional
eg.<include src="doc.md#exists" optional />
. The content of the page fragment should be included.optional
eg.<include src="doc.md#doesNotExist" optional />
. There should not be an error and the page should render as normal.<include src="doc.md#doesNotExist" />
. An error should be emitted.