Skip to content

Commit 5c444c6

Browse files
committed
chm: fix hash in links
1 parent 27fde61 commit 5c444c6

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

make_chm.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,14 @@ function buildChm( $cpp = true )
147147
if( $e->hasAttribute("title"))
148148
{
149149
$href = $e->getAttribute("href");
150-
if ( strpos( $href, "http") === false )
150+
$title = $e->getAttribute("title");
151+
$hash = false;
152+
$hashes = explode('#', $href, 2);
153+
if (count($hashes) === 2) {
154+
$href = $hashes[0];
155+
$hash = $hashes[1];
156+
}
157+
if ( strpos( $href, "http") === false)
151158
{
152159
$new_value = str_replace( "/" , "-", $e->getAttribute("title"));
153160
// fix bad titles where space is used instead of _
@@ -157,7 +164,11 @@ function buildChm( $cpp = true )
157164
$new_value = str_replace( "%" , "_", urlencode($new_value));
158165
}
159166

160-
$e->setAttribute("href", $new_value.".html" );
167+
if ($hash) { // fix hashes
168+
$e->setAttribute("href", $new_value.".html"."#".$hash );
169+
} else {
170+
$e->setAttribute("href", $new_value.".html" );
171+
}
161172

162173
// remove title from links?
163174
$e->removeAttribute("title");
@@ -166,6 +177,12 @@ function buildChm( $cpp = true )
166177
else if( $e->hasAttribute("href"))
167178
{
168179
$href = $e->getAttribute("href");
180+
$hash = false;
181+
$hashes = explode('#', $href, 2);
182+
if (count($hashes) === 2) {
183+
$href = $hashes[0];
184+
$hash = $hashes[1];
185+
}
169186
if ( strpos( $href, "http") === false )
170187
{
171188
// bad link
@@ -190,7 +207,11 @@ function buildChm( $cpp = true )
190207
}
191208

192209
$fixedhref = implode( "-", $relative_folders );
193-
$e->setAttribute("href", $fixedhref.".html" );
210+
if ($hash) { // fix hashes
211+
$e->setAttribute("href", $fixedhref.".html"."#".$hash );
212+
} else {
213+
$e->setAttribute("href", $fixedhref.".html" );
214+
}
194215
}
195216
}
196217
}

0 commit comments

Comments
 (0)