Skip to content

Commit

Permalink
Update the file link code to add both the basename and relative filen…
Browse files Browse the repository at this point in the history
…ame within

the document tree, and to put the target at the top of the page that actually
contains the start of the HTML file (Issue #534)
  • Loading branch information
michaelrsweet committed Nov 29, 2024
1 parent d06f586 commit f6fb9e4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Fixed a regression that caused spaces to disappear between some words
(Issue #533)
- Fixed broken links to HTML files in the document (Issue #534)


# Changes in HTMLDOC v1.9.19
Expand Down
34 changes: 24 additions & 10 deletions htmldoc/ps-pdf.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4126,23 +4126,37 @@ parse_doc(tree_t *t, /* I - Tree to parse */
}
else if (t->markup == MARKUP_FILE)
{
/*
* Add a file link...
*/
// Add file links, stripping any trailing HTTP GET parameters...
uchar newname[256], // New filename
*sep; // "?" separator in links
int linkpage; // Link page

// Figure out what page the file will actually start on...
linkpage = *page;

if ((chapter > 0 && OutputType == OUTPUT_BOOK) ||
((linkpage > 0 || *y < *top) && OutputType == OUTPUT_WEBPAGES))
{
if (*y < *top)
linkpage ++;

uchar newname[256], /* New filename */
*sep; /* "?" separator in links */
if (PageDuplex && (linkpage & 1))
linkpage ++;
}

// Base filename link...
strlcpy((char *)newname, (char *)htmlGetVariable(t, (uchar *)"_HD_FILENAME"), sizeof(newname));
if ((sep = (uchar *)strchr((char *)newname, '?')) != NULL)
*sep = '\0';

// Strip any trailing HTTP GET data stuff...
strlcpy((char *)newname, (char *)htmlGetVariable(t, (uchar *)"_HD_FILENAME"),
sizeof(newname));
add_link(NULL, newname, linkpage, (int)*top);

// Relative filename link...
strlcpy((char *)newname, (char *)htmlGetVariable(t, (uchar *)"_HD_URL"), sizeof(newname));
if ((sep = (uchar *)strchr((char *)newname, '?')) != NULL)
*sep = '\0';

// Add the link
add_link(NULL, newname, *page, (int)*y);
add_link(NULL, newname, linkpage, (int)*top);
}

if (chapter == 0 && !title_page)
Expand Down

0 comments on commit f6fb9e4

Please sign in to comment.