diff --git a/src/transform/plugins/links/index.ts b/src/transform/plugins/links/index.ts index 35d0aad8..ab0803ef 100644 --- a/src/transform/plugins/links/index.ts +++ b/src/transform/plugins/links/index.ts @@ -6,7 +6,7 @@ import {PAGE_LINK_REGEXP} from './constants'; import Token from 'markdown-it/lib/token'; import {Logger} from 'src/transform/log'; import {MarkdownItPluginCb, MarkdownItPluginOpts} from '../typings'; -import path, {parse, relative, resolve} from 'path'; +import path, {isAbsolute, parse, relative, resolve} from 'path'; import {StateCore} from 'src/transform/typings'; function defaultTransformLink(href: string) { @@ -113,6 +113,10 @@ function processLink(state: StateCore, tokens: Token[], idx: number, opts: ProcO return; } + if (isAbsolute(href)) { + return; + } + if (pathname) { file = resolve(path.parse(currentPath).dir, pathname); fileExists = isFileExists(file); diff --git a/test/links.test.ts b/test/links.test.ts index 1869461c..8d4372f0 100644 --- a/test/links.test.ts +++ b/test/links.test.ts @@ -77,4 +77,20 @@ describe('Links', () => { expect(result).toEqual('

First

\n

Second

\n'); }); + + test('Should create link with the absolute path', () => { + const inputPath = resolve(__dirname, './mocks/absolute-link.md'); + const input = readFileSync(inputPath, 'utf8'); + const result = transformYfm(input, inputPath); + + expect(result).toEqual('

Absolute link

\n'); + }); + + test('Should create link with the absolute path from the included file', () => { + const result = transformYfm( + ['', '{% include [create-folder](./mocks/absolute-link.md) %}', ''].join('\n'), + ); + + expect(result).toEqual('

Absolute link

\n'); + }); }); diff --git a/test/mocks/absolute-link.md b/test/mocks/absolute-link.md new file mode 100644 index 00000000..a546b864 --- /dev/null +++ b/test/mocks/absolute-link.md @@ -0,0 +1 @@ +[Absolute link](/link/)