Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-75745

Allow Book HTML zip import to convert anchored links

XMLWordPrintable

    • 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);
                 }
      }

            andrew.gosali@moodle.com Andrew Gosali
            softmonaut Jörg Hagemann
            Glyn (Mathew) May Glyn (Mathew) May
            Mihail Geshoski Mihail Geshoski
            Ron Carl Alfon Yu Ron Carl Alfon Yu
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 day, 3 hours, 2 minutes
                1d 3h 2m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.