Nesting shortcodes or triple colon #212
Replies: 1 comment 1 reply
-
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);
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
OskarKlintrot
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
My end goal is to get this html, roughly:
Triple colon gives me div's with classes, so that felt like a good place to start:
That almost worked but the second div ended up as a siblings to the first instead of a child:
Let's make the first triple colon a simple shortcode instead:
That works like a charm!
However, now I want to use the
Include
shortcode and then it seems as if myRecipe
shortcode escapes the inner shortcode:How can I solve this? I tried to look through the built in shortcodes for hints but I'm still stuck at this.
Update: I found this answer on SO and it works great!
Beta Was this translation helpful? Give feedback.
All reactions