Skip to content

Commit

Permalink
feat: add relative path resolution for links
Browse files Browse the repository at this point in the history
  • Loading branch information
makamekm committed Apr 26, 2024
1 parent ed86de4 commit 4c51890
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/transform/headings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function getHref(token: Token) {
return '#' + (token.attrGet('id') || '');
}

export = function getHeadings(tokens: Token[], needFlatListHeadings?: boolean, href: string = '') {
export = function getHeadings(tokens: Token[], needFlatListHeadings?: boolean, href = '') {
return needFlatListHeadings
? getFlatListHeadings(tokens, href)
: getFilteredHeadings(tokens, href);
Expand Down
2 changes: 1 addition & 1 deletion test/links.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const transformYfm = (text: string, path?: string, extraOpts?: OptionsType) => {

const expectObject = (a: unknown, b: unknown) => {
expect(JSON.parse(JSON.stringify(a))).toEqual(JSON.parse(JSON.stringify(b)));
}
};

describe('Links', () => {
test('Should create link with custom title', () => {
Expand Down
53 changes: 32 additions & 21 deletions test/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
PAGE_LINK_REGEXP,
getPublicPath,
defaultTransformLink,
} from '../src/transform/utils';
import {PAGE_LINK_REGEXP, defaultTransformLink, getPublicPath} from '../src/transform/utils';

const assert = require('assert');

Expand Down Expand Up @@ -52,30 +48,45 @@ describe('defaultTransformLink', function () {

describe('getPublicPath', function () {
it('make sure local path includes rootPublicPath', function () {
assert.equal(getPublicPath({
path: './ru/test.md',
root: './',
rootPublicPath: 'ru',
}), 'test.html');
assert.equal(
getPublicPath({
path: './ru/test.md',
root: './',
rootPublicPath: 'ru',
}),
'test.html',
);
});

it('make sure local path does not include rootPublicPath', function () {
assert.equal(getPublicPath({
path: './ru/test.md',
root: './',
rootPublicPath: '',
}), 'ru/test.html');
assert.equal(
getPublicPath({
path: './ru/test.md',
root: './',
rootPublicPath: '',
}),
'ru/test.html',
);
});

it('make sure local path with only path', function () {
assert.equal(getPublicPath({
path: './test.md',
}), 'test.html');
assert.equal(
getPublicPath({
path: './test.md',
}),
'test.html',
);
});

it('make sure local path with only input path', function () {
assert.equal(getPublicPath({
path: './test.md',
}, './test2.md'), 'test2.html');
assert.equal(
getPublicPath(
{
path: './test.md',
},
'./test2.md',
),
'test2.html',
);
});
});

0 comments on commit 4c51890

Please sign in to comment.