@@ -147,7 +147,14 @@ function buildChm( $cpp = true )
147
147
if ( $ e ->hasAttribute ("title " ))
148
148
{
149
149
$ 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 )
151
158
{
152
159
$ new_value = str_replace ( "/ " , "- " , $ e ->getAttribute ("title " ));
153
160
// fix bad titles where space is used instead of _
@@ -157,7 +164,11 @@ function buildChm( $cpp = true )
157
164
$ new_value = str_replace ( "% " , "_ " , urlencode ($ new_value ));
158
165
}
159
166
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
+ }
161
172
162
173
// remove title from links?
163
174
$ e ->removeAttribute ("title " );
@@ -166,6 +177,12 @@ function buildChm( $cpp = true )
166
177
else if ( $ e ->hasAttribute ("href " ))
167
178
{
168
179
$ 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
+ }
169
186
if ( strpos ( $ href , "http " ) === false )
170
187
{
171
188
// bad link
@@ -190,7 +207,11 @@ function buildChm( $cpp = true )
190
207
}
191
208
192
209
$ 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
+ }
194
215
}
195
216
}
196
217
}
0 commit comments