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
This PR allows Modifiers to transform unformatted text—for example, the contents of an
h1
heading, the text of a link, or the bulk of a paragraph.Discussion
In my Publish site, I need to examine the text of my markdown files to do some dynamic transformation. For simplicity, imagine I want to provide dynamic stock prices based on ticker symbols (this is a bad example, but bear with me).
So given the markdown
Apple trades under the ticker $AAPL
, I would like to generate:Currently there doesn't seem to be a clean way to do this in Publish.
This change
This change adds a
Modifier.Target
case (.text
) which allows Modifiers to target plain text, so you could write:Implications
This is accomplished by extending
Substring
to conform toHTMLConvertible
andModifiable
. It works fine, but I admit it's a little strange at the calling site to request.html
for a plain string.Although Ink is smart enough to avoid code blocks and HTML within markdown, the user could still run into problems if they try to add HTML elements in their Modifier. For example, if the user tries to add links to plain text, they should be aware that their incoming text might itself be within another link, so you could accidentally end up with:
However, this is a danger with any Modifier, so I don't think it's unique to this PR.
Thanks for considering this! 🙏