mirror of
https://github.com/nathonius/obsidian-github-link.git
synced 2026-07-22 09:20:25 +00:00
Fix: Add more edge cases in tests and rework regexp
This commit is contained in:
parent
bf0572256a
commit
7679a149be
2 changed files with 43 additions and 1 deletions
|
|
@ -21,6 +21,11 @@ const GITHUB_URLS = [
|
|||
'https://github.com/nathonius/obsidian-github-link/pull/157/commits',
|
||||
'https://github.com/nathonius/obsidian-github-link/pull/157/commits/42d35e4c7070d2ec9f3bacf7f4a0561d9d7346bb',
|
||||
'https://github.com/nathonius/obsidian-github-link/pull/157/files',
|
||||
// MORE EDGE CASES
|
||||
'https://github.com/kwsch/pk3DS/blob/e40d3ce5548d75821f31785dc88cd465610530a6/pk3DS.Core/CTR/Images/BCLIM.cs',
|
||||
'https://github.com/kwsch/png2bclim/blob/master/png2bclim/BCLIM.cs',
|
||||
'https://github.com/kwsch/png2bclim',
|
||||
'https://github.com/ihaveamac/3DS-rom-tools/wiki/Extract-a-game-or-application-in-.3ds-or-.cci-format'
|
||||
]
|
||||
|
||||
describe('matchRegexp', () => {
|
||||
|
|
@ -50,6 +55,34 @@ describe('matchRegexp', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('matches URLs followed by punctuation', () => {
|
||||
GITHUB_URLS.forEach(url => {
|
||||
const text = `First ${url}, then some text.`;
|
||||
const match = text.match(matchRegexp);
|
||||
expect(match).not.toBeNull();
|
||||
expect(match![0]).toBe(url);
|
||||
});
|
||||
});
|
||||
|
||||
test('matches URLs ending a sentence with an interrogative', () => {
|
||||
GITHUB_URLS.forEach(url => {
|
||||
const text = `You heard about ${url}?`;
|
||||
const match = text.match(matchRegexp);
|
||||
expect(match).not.toBeNull();
|
||||
expect(match![0]).toBe(url);
|
||||
});
|
||||
});
|
||||
|
||||
test('matches URLs followed by multiple punctuation', () => {
|
||||
GITHUB_URLS.forEach(url => {
|
||||
const text = `A test for ${url}...`;
|
||||
const match = text.match(matchRegexp);
|
||||
expect(match).not.toBeNull();
|
||||
expect(match![0]).toBe(url);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test('matches URLs ending a sentence that segues to another', () => {
|
||||
GITHUB_URLS.forEach(url => {
|
||||
const text = `That's the end of the line for ${url}. But not for this variable!`;
|
||||
|
|
@ -78,4 +111,13 @@ describe('matchRegexp', () => {
|
|||
expect(match![0]).toBe(url);
|
||||
})
|
||||
});
|
||||
|
||||
test('matches URLs quoted', () => {
|
||||
GITHUB_URLS.forEach(url => {
|
||||
const text = `Obama chuckled: you mean "${url}" ?`;
|
||||
const match = text.match(matchRegexp);
|
||||
expect(match).not.toBeNull();
|
||||
expect(match![0]).toBe(url);
|
||||
})
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class InlineTagWidget extends WidgetType {
|
|||
}
|
||||
}
|
||||
|
||||
export const matchRegexp = /(?<!]\()https:\/\/github\.com\/([A-z\d\-_~+#%&=*@?/]*)(\.[^.\s]+)?/g
|
||||
export const matchRegexp = /(?<!]\()https:\/\/github\.com\/[^\s]+(?<!['\".\?,:;]+)/g
|
||||
|
||||
export function createInlineViewPlugin(_plugin: GithubLinkPlugin) {
|
||||
class InlineViewPluginValue implements PluginValue {
|
||||
|
|
|
|||
Loading…
Reference in a new issue