Skip to content

Commit

Permalink
feat: add linkifyTlds option
Browse files Browse the repository at this point in the history
  • Loading branch information
Postamentovich committed Nov 1, 2022
1 parent 14a090e commit 951fd7f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/transform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ interface OptionsType {
needTitle?: boolean;
allowHTML?: boolean;
linkify?: boolean;
linkifyTlds?: string | string[];
breaks?: boolean;
conditionsInCode?: boolean;
disableLiquid?: boolean;
Expand All @@ -68,6 +69,7 @@ function transform(originInput: string, opts: OptionsType = {}): OutputType {
needTitle,
allowHTML = false,
linkify = false,
linkifyTlds,
breaks = true,
conditionsInCode = false,
needToSanitizeHtml = false,
Expand Down Expand Up @@ -118,6 +120,10 @@ function transform(originInput: string, opts: OptionsType = {}): OutputType {

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

if (linkify && linkifyTlds) {
md.linkify.tlds(linkifyTlds, true);
}

try {
let title;
let tokens;
Expand Down
18 changes: 18 additions & 0 deletions test/linkify.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import transform from '../src/transform';

describe('Linkify', () => {
it('should not linkify .cloud tld without linkifyTlds option', () => {
const {
result: {html},
} = transform('yandex.cloud');

expect(html).toBe('<p>yandex.cloud</p>\n');
});
it('should linkify .cloud tld with linkifyTlds option', () => {
const {
result: {html},
} = transform('yandex.cloud', {linkifyTlds: 'cloud', linkify: true});

expect(html).toBe('<p><a href="http://yandex.cloud">yandex.cloud</a></p>\n');
});
});

0 comments on commit 951fd7f

Please sign in to comment.