-
-
Notifications
You must be signed in to change notification settings - Fork 0
Add MarkupString.Pueblo: Pueblo's own extensions #16
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fe4f837
Add MarkupString.Mxp: MXP's own elements
HarryCordewener 3e6859a
MXP: hold elements to what the client said, and stop asking a browser…
HarryCordewener 7cf689f
Add MarkupString.Pueblo: Pueblo's own extensions
HarryCordewener 2717e4d
Name the three tag dialects as a family in the docs
HarryCordewener File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| using System.Buffers; | ||
|
|
||
| namespace MarkupString.Mxp; | ||
|
|
||
| /// <summary> | ||
| /// Writes an <see cref="MxpElement"/> as the MXP tag it is: <c><SOUND door.wav V=80></c> for one | ||
| /// that stands alone, and <c><FRAME …>body</FRAME></c> for one that wraps content. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// The carrier a standalone element rides on is dropped rather than written: the tag stands in its | ||
| /// place, and a zero-width space left behind would travel to clients that never asked for one. | ||
| /// </remarks> | ||
| public sealed class MxpElementEmitter : IMarkupEmitter | ||
| { | ||
| private readonly Func<MxpElement, bool>? _supports; | ||
|
|
||
| /// <summary>An emitter that writes every element, for a connection whose client was never asked.</summary> | ||
| public static readonly MxpElementEmitter Instance = new(null); | ||
|
|
||
| /// <summary> | ||
| /// An emitter that writes only the elements <paramref name="supports"/> accepts. MXP's | ||
| /// <c><SUPPORT></c> exchange is what answers that question, and the answer belongs to a | ||
| /// connection rather than to a registry, so the predicate is the consumer's — usually a lookup into | ||
| /// what one client replied. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// An element the predicate refuses is written the way a format without MXP writes it: nothing for one | ||
| /// that stands alone, and the content alone for one that wraps. That second half is the point of | ||
| /// asking — a <c>FRAME</c> a client cannot open would otherwise take the text that followed it with | ||
| /// it. | ||
| /// </remarks> | ||
| public MxpElementEmitter(Func<MxpElement, bool>? supports) | ||
| { | ||
| _supports = supports; | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public Type MarkupType => typeof(MxpElement); | ||
|
|
||
| /// <inheritdoc/> | ||
| public MarkupFormat Format => MarkupFormat.Mxp; | ||
|
|
||
| /// <inheritdoc/> | ||
| public void Emit(IMarkup markup, ReadOnlySpan<char> body, in EmitContext context, IBufferWriter<char> output) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(markup); | ||
| ArgumentNullException.ThrowIfNull(output); | ||
|
|
||
| var element = (MxpElement)markup; | ||
| if (_supports is not null && !_supports(element)) | ||
| { | ||
| if (element.WrapsContent) output.Write(body); | ||
| return; | ||
| } | ||
|
|
||
| output.Write(element.ToString()); | ||
|
|
||
| if (!element.WrapsContent) return; | ||
|
|
||
| output.Write(body); | ||
| output.Write("</"); | ||
| output.Write(element.Name); | ||
| output.Write(">"); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Writes an <see cref="MxpElement"/> for a format that has no MXP: the body for an element that wraps | ||
| /// content, and nothing at all for one that stands alone, carrier included. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Registered for every format this package does not translate, so the same text can go to every client: | ||
| /// a terminal is not sent a tag it would show as text, and it is not sent the zero-width space the tag | ||
| /// rode on either. | ||
| /// </remarks> | ||
| public sealed class MxpSilentEmitter(MarkupFormat format) : IMarkupEmitter | ||
| { | ||
| /// <inheritdoc/> | ||
| public Type MarkupType => typeof(MxpElement); | ||
|
|
||
| /// <inheritdoc/> | ||
| public MarkupFormat Format { get; } = format; | ||
|
|
||
| /// <inheritdoc/> | ||
| public void Emit(IMarkup markup, ReadOnlySpan<char> body, in EmitContext context, IBufferWriter<char> output) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(markup); | ||
| ArgumentNullException.ThrowIfNull(output); | ||
|
|
||
| if (((MxpElement)markup).WrapsContent) output.Write(body); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Keep the Pueblo package entry only once under
Unreleased.This PR introduces
MarkupString.Pueblo. The duplicate and backdated entries make the changelog state that the package shipped in releases before this PR.CHANGELOG.md#L40-L48: Remove the duplicate### Addedsection underUnreleased.CHANGELOG.md#L84-L92: Remove the Pueblo entry from2.1.0.CHANGELOG.md#L124-L132: Remove the Pueblo entry from2.0.0.CHANGELOG.md#L163-L171: Remove the Pueblo entry from1.1.0.CHANGELOG.md#L189-L197: Remove the Pueblo entry from1.0.0.📍 Affects 1 file
CHANGELOG.md#L40-L48(this comment)CHANGELOG.md#L84-L92CHANGELOG.md#L124-L132CHANGELOG.md#L163-L171CHANGELOG.md#L189-L197🤖 Prompt for AI Agents