Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐍 Remove .py from linkify domains #940

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});
Loading