-
Improvement
-
Resolution: Fixed
-
Minor
-
3.11.11, Future Dev
-
MOODLE_311_STABLE
-
MOODLE_500_STABLE
-
MDL-75745-main -
-
-
-
1
-
Team Alpha - Sprint 3 I4-2024, Team Alpha - Planning I1-2025, Team Alpha - Sprint 1 I1-2025
Links with anchors are not converted during import. Example:
<a href="targetPage.html#myAnchor">Jump</a>
should be converted to something like
<a href="https://example.com/mod/book/view.php?id=123&chapterid=456#myAnchor">Jump</a>
But the link remains untouched. The following change takes this into account.
Affected file: mod/book/tool/importhtml/locallib.php
Function: toolbook_importhtml_import_chapters(...)
Current source code:
$chapterpath = dirname($chapter->importsrc).'/'.$matches[2][$i];
$chapterpath = toolbook_importhtml_fix_path($chapterpath);
foreach ($allchapters as $target) {
if ($target->importsrc === $chapterpath) {
$newcontent = str_replace($match, 'href="'.new moodle_url('/mod/book/view.php',
array('id'=>$context->instanceid, 'chapterid'=>$target->id)).'"', $newcontent);
}
}
Proposed change:
$anchor = explode("#", $matches[2][$i]);
$chapterpath = dirname($chapter->importsrc).'/'. $anchor[0];
$chapterpath = toolbook_importhtml_fix_path($chapterpath);
foreach ($allchapters as $target) {
if ($target->importsrc === $chapterpath) {
$newcontent = str_replace($match, 'href="'.new moodle_url('/mod/book/view.php',
array('id'=>$context->instanceid, 'chapterid'=>$target->id), $anchor[1] ?? null).'"', $newcontent);
}
}