Skip to content

Commit 951fd7f

Browse files
feat: add linkifyTlds option
1 parent 14a090e commit 951fd7f

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/transform/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ interface OptionsType {
4444
needTitle?: boolean;
4545
allowHTML?: boolean;
4646
linkify?: boolean;
47+
linkifyTlds?: string | string[];
4748
breaks?: boolean;
4849
conditionsInCode?: boolean;
4950
disableLiquid?: boolean;
@@ -68,6 +69,7 @@ function transform(originInput: string, opts: OptionsType = {}): OutputType {
6869
needTitle,
6970
allowHTML = false,
7071
linkify = false,
72+
linkifyTlds,
7173
breaks = true,
7274
conditionsInCode = false,
7375
needToSanitizeHtml = false,
@@ -118,6 +120,10 @@ function transform(originInput: string, opts: OptionsType = {}): OutputType {
118120

119121
plugins.forEach((plugin) => md.use(plugin, pluginOptions));
120122

123+
if (linkify && linkifyTlds) {
124+
md.linkify.tlds(linkifyTlds, true);
125+
}
126+
121127
try {
122128
let title;
123129
let tokens;

test/linkify.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import transform from '../src/transform';
2+
3+
describe('Linkify', () => {
4+
it('should not linkify .cloud tld without linkifyTlds option', () => {
5+
const {
6+
result: {html},
7+
} = transform('yandex.cloud');
8+
9+
expect(html).toBe('<p>yandex.cloud</p>\n');
10+
});
11+
it('should linkify .cloud tld with linkifyTlds option', () => {
12+
const {
13+
result: {html},
14+
} = transform('yandex.cloud', {linkifyTlds: 'cloud', linkify: true});
15+
16+
expect(html).toBe('<p><a href="http://yandex.cloud">yandex.cloud</a></p>\n');
17+
});
18+
});

0 commit comments

Comments
 (0)