docsify icon indicating copy to clipboard operation
docsify copied to clipboard

Support relativePath link set linkTarget

Open bilibiliou opened this issue 4 years ago • 3 comments

Hi When I read the docs of "Set target attribute for link" https://docsify.js.org/#/helpers?id=set-target-attribute-for-link I try a relative path to jump

[demo](/docs/front_end/summery_of_experience/data_use/assets/demo/index.html ':target=_blank')

but It be compiled as

<a href="/docs/front_end/summery_of_experience/data_use/assets/demo/index.html">demo</a>

It is not my expectation.

After then, I read the source code: "src\core\render\compiler\link.js" line 22 I discover that docsifyjs didnt support relative path linkTarget custom

so I make the issue in order to discuss the problem

thx

bilibiliou avatar Feb 12 '22 17:02 bilibiliou

"src\core\render\compiler\link.js" line 22

if (
      !isAbsolutePath(href) && // If it is relative path, then cant set linkTarget
      !compilerClass._matchNotCompileLink(href) &&
      !config.ignore
    ) {
      if (href === compilerClass.config.homepage) {
        href = 'README';
      }

      href = router.toURL(href, null, router.getCurrentPath());
    } else {
      if (!isAbsolutePath(href) && href.slice(0, 2) === './') {
        href =
          document.URL.replace(/\/(?!.*\/).*/, '/').replace('#/./', '') + href;
      }
      attrs.push(href.indexOf('mailto:') === 0 ? '' : `target="${linkTarget}"`);
      attrs.push(
        href.indexOf('mailto:') === 0
          ? ''
          : linkRel !== ''
          ? ` rel="${linkRel}"`
          : ''
      );
    }

bilibiliou avatar Feb 12 '22 17:02 bilibiliou

Thx for ur report. Unfortunately, docsify doesn't support the relative target config for now. I think we may have an update on it asap. :)

Koooooo-7 avatar Feb 13 '22 07:02 Koooooo-7

Okay, thx ur reply and support I can use the absolute link instead now. hope you have a nice day :)

bilibiliou avatar Feb 13 '22 11:02 bilibiliou