From: Johan Malm Date: Sun, 2 Jul 2023 20:17:26 +0000 (+0100) Subject: menu: support CDATA for element X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=49dfba15071d0a829fcf4f650fcb010c187bbf31;p=proto%2Flabwc.git menu: support CDATA for element ...in order to support obmenu-generator output such as this: References: - https://github.com/trizen/obmenu-generator - https://aur.archlinux.org/packages/obmenu-generator - https://trizenx.blogspot.com/2012/02/obmenu-generator.html Fixes: issue #972 --- diff --git a/docs/labwc-menu.5.scd b/docs/labwc-menu.5.scd index bae36021..a1219305 100644 --- a/docs/labwc-menu.5.scd +++ b/docs/labwc-menu.5.scd @@ -48,7 +48,8 @@ A menu file must be entirely enclosed within and The visible name of the menu item. *menu.item.action* - See labwc-action(5) + See labwc-action(5). Note: XML CDATA is supported for this node in + order to maintain compatibility with obmenu-generator. *menu.separator* Horizontal line. diff --git a/src/menu/menu.c b/src/menu/menu.c index 180575fd..ff7bfda8 100644 --- a/src/menu/menu.c +++ b/src/menu/menu.c @@ -14,6 +14,7 @@ #include "common/buf.h" #include "common/font.h" #include "common/list.h" +#include "common/match.h" #include "common/mem.h" #include "common/nodename.h" #include "common/scaled_font_buffer.h" @@ -300,19 +301,53 @@ item_destroy(struct menuitem *item) free(item); } +/* + * We support XML CDATA for in menu.xml in order to provide backward + * compatibility with obmenu-generator. For example: + * + * + * + * + * + * + * + * + * + * is an old, deprecated openbox variety of . We support it + * for backward compatibility with old openbox-menu generators. It has the same + * function and + * + * The match_glob() wildcard allows for nested menus giving nodenames with + * ...menu.menu... or ...menu.menu.menu... and so on. + */ +static bool +nodename_supports_cdata(char *nodename) +{ + return match_glob("command.action.item.*menu.openbox_menu", nodename) + || match_glob("execute.action.item.*menu.openbox_menu", nodename); +} + static void entry(xmlNode *node, char *nodename, char *content) { - if (!nodename || !content) { + if (!nodename) { + return; + } + xmlChar *cdata = NULL; + if (!content && nodename_supports_cdata(nodename)) { + cdata = xmlNodeGetContent(node); + } + if (!content && !cdata) { return; } string_truncate_at_pattern(nodename, ".openbox_menu"); if (getenv("LABWC_DEBUG_MENU_NODENAMES")) { - printf("%s: %s\n", nodename, content); + printf("%s: %s\n", nodename, content ? content : (char *)cdata); } if (in_item) { - fill_item(nodename, content); + fill_item(nodename, content ? content : (char *)cdata); } + xmlFree(cdata); } static void