Skip to content

Commit

Permalink
🐍 Remove .py and .md from linkify domains (#940)
Browse files Browse the repository at this point in the history
  • Loading branch information
fwkoch authored Feb 28, 2024
1 parent cff47b1 commit b289f03
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/breezy-plants-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'myst-parser': patch
---

Remove .py from linkify domains
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/myst-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"myst-directives": "^1.0.22",
"myst-roles": "^1.0.22",
"myst-spec": "^0.0.5",
"tlds": "^1.250.0",
"unified": "^10.1.1",
"unist-builder": "^3.0.0",
"unist-util-remove": "^3.1.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/myst-parser/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,6 @@ export const MARKDOWN_IT_CONFIG = {
},
},
};

// List of valid TLDs to exclude from linkify
export const EXCLUDE_TLDS = ['py', 'md'];
6 changes: 5 additions & 1 deletion packages/myst-parser/src/myst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { defaultDirectives } from 'myst-directives';
import { defaultRoles } from 'myst-roles';
import type { Plugin } from 'unified';
import { VFile } from 'vfile';
import { MARKDOWN_IT_CONFIG } from './config.js';
import tlds from 'tlds';
import { EXCLUDE_TLDS, MARKDOWN_IT_CONFIG } from './config.js';
import { tokensToMyst } from './tokensToMyst.js';
import {
mathPlugin,
Expand Down Expand Up @@ -70,6 +71,9 @@ export function createTokenizer(opts?: Options) {
} as any,
markdownit,
);
if (markdownit.linkify) {
tokenizer.linkify.tlds(tlds.filter((tld) => !EXCLUDE_TLDS.includes(tld)));
}
if (extensions.smartquotes) tokenizer.enable('smartquotes');
if (extensions.tables) tokenizer.enable('table');
if (extensions.colonFences) tokenizer.use(colonFencePlugin);
Expand Down
14 changes: 14 additions & 0 deletions packages/myst-parser/tests/linkify.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,18 @@ describe('linkify', () => {
],
});
});
it('dont linkify .py', () => {
const content = 'Link in paragraph: example.py';
const expected = {
type: 'root',
children: [
{
type: 'paragraph',
children: [{ type: 'text', value: 'Link in paragraph: example.py' }],
},
],
};
expect(stripPositions(mystParse(content))).toEqual(expected);
expect(stripPositions(mystParse(content, { markdownit: { linkify: true } }))).toEqual(expected);
});
});

0 comments on commit b289f03

Please sign in to comment.