From c694fe8b178eb989ea9213143d248083fd7a5d57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominic=20H=C3=B6glinger?= Date: Fri, 24 Apr 2026 04:45:42 +0200 Subject: [PATCH] Add cdata manipulators Clanker: claude-sonnet_4.6 --- Transformation/ContextFunctions.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Transformation/ContextFunctions.cs b/Transformation/ContextFunctions.cs index c9a4980..b4ef284 100644 --- a/Transformation/ContextFunctions.cs +++ b/Transformation/ContextFunctions.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using Sprache; using XNeedle.Parser; using XNeedle.Parser.Elements; @@ -45,6 +46,28 @@ namespace XNeedle.Transformation return txt; } + public static string cdata(Context ctx) + { + if (ctx.Node is null) return ""; + var cdataNode = ctx.Node.Nodes().OfType().FirstOrDefault(); + return cdataNode?.Value ?? ""; + } + + public static string cdata(Context ctx, string txt) + { + if (ctx.Node is null) return ""; + var cdataNode = ctx.Node.Nodes().OfType().FirstOrDefault(); + if (cdataNode != null) + { + cdataNode.Value = txt; + } + else + { + ctx.Node.Add(new System.Xml.Linq.XCData(txt)); + } + return txt; + } + public static string attr(Context ctx, string name, string value) { if (ctx.Node is null) return "";