Skip to content

Nesting shortcodes or triple colon #212

Closed Answered by OskarKlintrot
OskarKlintrot asked this question in Q&A
Discussion options

You must be logged in to vote
using System.Xml.Linq;

namespace My.App;

public sealed class RecipeShortcode : SyncShortcode
{
    private const string Class = nameof(Class);

    public override ShortcodeResult Execute(KeyValuePair<string, string>[] args, string content, IDocument document, IExecutionContext context)
    {
        XElement div = new(
            "div",
            new XRaw(content),
            new XAttribute(Class, "recipe"));

        return div.ToString();
    }

    private sealed class XRaw(string text) : XText(text)
    {
        public override void WriteTo(System.Xml.XmlWriter writer) => writer.WriteRaw(Value);
    }
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@daveaglick
Comment options

Answer selected by OskarKlintrot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants