From 274189f87ce6c1f69307b2c42cd9aed36cf4deb9 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Thu, 21 Nov 2024 15:09:54 -0500 Subject: [PATCH] Fix links to subfolders (Issue #525) --- CHANGES.md | 1 + htmldoc/ps-pdf.cxx | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 08e93973..4d269982 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ management and fix potential double-free bugs. - Updated configure script to look for zlib with pkg-config (Issue #519) - Updated markdown support code to mmd. +- Fixed hyperlinks to subfolders (Issue #525) - Fixed export of UTF-8 HTML (Issue #526) - Fixed handling of whitespace-only nodes (Issue #528) - Fixed handling of tabs in PRE nodes (Issue #529) diff --git a/htmldoc/ps-pdf.cxx b/htmldoc/ps-pdf.cxx index c4fdc34c..4040d7d2 100644 --- a/htmldoc/ps-pdf.cxx +++ b/htmldoc/ps-pdf.cxx @@ -9064,7 +9064,7 @@ add_link(tree_t *html, /* I - HTML node */ { uchar *filename; /* Filename */ - if ((filename = htmlGetVariable(html->parent, (uchar *)"_HD_FILENAME")) != NULL) + if ((filename = htmlGetVariable(html->parent, (uchar *)"_HD_URL")) != NULL) snprintf((char *)temp->name, sizeof(temp->name), "%s#%s", (char *)filename, (char *)name); else strlcpy((char *)temp->name, (char *)name, sizeof(temp->name)); @@ -9100,8 +9100,18 @@ find_link(uchar *name) /* I - Name to find */ name ++; strlcpy((char *)key.name, (char *)name, sizeof(key.name)); - match = (link_t *)bsearch(&key, links, num_links, sizeof(link_t), - (compare_func_t)compare_links); + match = (link_t *)bsearch(&key, links, num_links, sizeof(link_t), (compare_func_t)compare_links); + + if (!match) + { + uchar *target = (uchar *)strchr((char *)name, '#'); + + if (target) + { + strlcpy((char *)key.name, (char *)target + 1, sizeof(key.name)); + match = (link_t *)bsearch(&key, links, num_links, sizeof(link_t), (compare_func_t)compare_links); + } + } return (match); }