mirror of
https://github.com/nathonius/obsidian-github-link.git
synced 2026-07-22 09:20:25 +00:00
Compare commits
25 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a5ad979881 | ||
|
|
4366eebfb6 | ||
|
|
0f809ae0a9 | ||
|
|
2d9dba0d43 | ||
|
|
568b4d4335 | ||
|
|
37ff39dbc5 | ||
|
|
ceab053dca | ||
|
|
dd3bfaa15f | ||
|
|
1b4317c3b9 | ||
|
|
3289da5a1d | ||
|
|
69f2d2a08e | ||
|
|
a4d1cbc7bf | ||
|
|
fef1eb84a0 | ||
|
|
6e143d00ce | ||
|
|
ebb30a8940 | ||
|
|
020fcead39 | ||
|
|
088597bb8c | ||
|
|
ed4bc6961f | ||
|
|
0878512754 | ||
|
|
82f5dadf83 | ||
|
|
353b95ec34 | ||
|
|
cd7ebaf679 | ||
|
|
84eeedb9ba | ||
|
|
cae9718a6e | ||
|
|
792ca07395 |
19 changed files with 407 additions and 153 deletions
|
|
@ -35,6 +35,25 @@
|
|||
"contributions": [
|
||||
"bug"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "joshleaves",
|
||||
"name": "Arnaud 'red' Rouyer",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/1074760?v=4",
|
||||
"profile": "https://tech.dreamleaves.org",
|
||||
"contributions": [
|
||||
"code",
|
||||
"test"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "tmcw",
|
||||
"name": "Tom MacWright",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/32314?v=4",
|
||||
"profile": "https://macwright.com/",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
17
CHANGELOG.md
17
CHANGELOG.md
|
|
@ -16,6 +16,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
<!-- ## Unreleased -->
|
||||
|
||||
## [1.2.0] - 2025-03-08
|
||||
|
||||
### Changed
|
||||
|
||||
- Issue number is always shown on a tag for an issue
|
||||
|
||||
## [1.1.0] - 2025-02-26
|
||||
|
||||
### Changed
|
||||
|
||||
- Show rich metadata about filenames in links
|
||||
- A manual input for all slider settings that allows settings outside of the normal bounds
|
||||
|
||||
## [1.0.3] - 2025-01-19
|
||||
|
||||
### Fixed
|
||||
|
|
@ -141,7 +154,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
Initial release.
|
||||
|
||||
[1.0.2]: https://github.com/nathonius/obsidian-github-link/compare/1.0.2...1.0.3
|
||||
[1.2.0]: https://github.com/nathonius/obsidian-github-link/compare/1.1.0...1.2.0
|
||||
[1.1.0]: https://github.com/nathonius/obsidian-github-link/compare/1.0.3...1.1.0
|
||||
[1.0.3]: https://github.com/nathonius/obsidian-github-link/compare/1.0.2...1.0.3
|
||||
[1.0.2]: https://github.com/nathonius/obsidian-github-link/compare/1.0.0...1.0.2
|
||||
[1.0.0]: https://github.com/nathonius/obsidian-github-link/compare/0.7.2...1.0.0
|
||||
[0.7.2]: https://github.com/nathonius/obsidian-github-link/compare/0.7.1...0.7.2
|
||||
|
|
|
|||
42
LICENSE
42
LICENSE
|
|
@ -1,24 +1,26 @@
|
|||
This is free and unencumbered software released into the public domain.
|
||||
MIT NON-AI License
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
Copyright (c) 2024, Nathan Smith
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of the software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
For more information, please refer to <https://unlicense.org>
|
||||
In addition, the following restrictions apply:
|
||||
|
||||
1. The Software and any modifications made to it may not be used for the purpose of training or improving machine learning algorithms,
|
||||
including but not limited to artificial intelligence, natural language processing, or data mining. This condition applies to any derivatives,
|
||||
modifications, or updates based on the Software code. Any usage of the Software in an AI-training dataset is considered a breach of this License.
|
||||
|
||||
2. The Software may not be included in any dataset used for training or improving machine learning algorithms,
|
||||
including but not limited to artificial intelligence, natural language processing, or data mining.
|
||||
|
||||
3. Any person or organization found to be in violation of these restrictions will be subject to legal action and may be held liable
|
||||
for any damages resulting from such use.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
|
|
|||
|
|
@ -53,9 +53,11 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for info on contributing to the project.
|
|||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="center" valign="top" width="14.28%"><a href="http://nathan-smith.org"><img src="https://avatars.githubusercontent.com/u/4851889?v=4?s=100" width="100px;" alt="Nathan"/><br /><sub><b>Nathan</b></sub></a><br /><a href="https://github.com/nathonius/obsidian-github-link/commits?author=nathonius" title="Code">💻</a> <a href="https://github.com/nathonius/obsidian-github-link/commits?author=nathonius" title="Documentation">📖</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://arongriffis.com"><img src="https://avatars.githubusercontent.com/u/50637?v=4?s=100" width="100px;" alt="Aron Griffis"/><br /><sub><b>Aron Griffis</b></sub></a><br /><a href="https://github.com/nathonius/obsidian-github-link/commits?author=agriffis" title="Code">💻</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/nikclayton"><img src="https://avatars.githubusercontent.com/u/773100?v=4?s=100" width="100px;" alt="Nik Clayton"/><br /><sub><b>Nik Clayton</b></sub></a><br /><a href="https://github.com/nathonius/obsidian-github-link/issues?q=author%3Anikclayton" title="Bug reports">🐛</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="http://nathan-smith.org"><img src="https://avatars.githubusercontent.com/u/4851889?v=4?s=100" width="100px;" alt="Nathan"/><br /><sub><b>Nathan</b></sub></a><br /><a href="#code-nathonius" title="Code">💻</a> <a href="#doc-nathonius" title="Documentation">📖</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://arongriffis.com"><img src="https://avatars.githubusercontent.com/u/50637?v=4?s=100" width="100px;" alt="Aron Griffis"/><br /><sub><b>Aron Griffis</b></sub></a><br /><a href="#code-agriffis" title="Code">💻</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/nikclayton"><img src="https://avatars.githubusercontent.com/u/773100?v=4?s=100" width="100px;" alt="Nik Clayton"/><br /><sub><b>Nik Clayton</b></sub></a><br /><a href="#bug-nikclayton" title="Bug reports">🐛</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://tech.dreamleaves.org"><img src="https://avatars.githubusercontent.com/u/1074760?v=4?s=100" width="100px;" alt="Arnaud 'red' Rouyer"/><br /><sub><b>Arnaud 'red' Rouyer</b></sub></a><br /><a href="#code-joshleaves" title="Code">💻</a> <a href="#test-joshleaves" title="Tests">⚠️</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://macwright.com/"><img src="https://avatars.githubusercontent.com/u/32314?v=4?s=100" width="100px;" alt="Tom MacWright"/><br /><sub><b>Tom MacWright</b></sub></a><br /><a href="#code-tmcw" title="Code">💻</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { PluginMock } from "./obsidian/Plugin";
|
|||
import { ModalMock } from "./obsidian/Modal";
|
||||
import { PluginSettingTabMock } from "./obsidian/PluginSettingTab";
|
||||
import { NoticeMock } from "./obsidian/Notice";
|
||||
import { setIconMock } from "./obsidian/setIcon";
|
||||
|
||||
module.exports = {
|
||||
App: AppMock,
|
||||
|
|
@ -10,4 +11,5 @@ module.exports = {
|
|||
Modal: ModalMock,
|
||||
PluginSettingTab: PluginSettingTabMock,
|
||||
Notice: NoticeMock,
|
||||
setIcon: setIconMock,
|
||||
};
|
||||
|
|
|
|||
5
__mocks__/obsidian/setIcon.ts
Normal file
5
__mocks__/obsidian/setIcon.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
export function setIconMock(parent: HTMLElement, iconId: string): void {
|
||||
const icon = document.createElement("span");
|
||||
icon.innerText = iconId;
|
||||
parent.appendChild(icon);
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "github-link",
|
||||
"name": "GitHub Link",
|
||||
"version": "1.0.3",
|
||||
"version": "1.2.0",
|
||||
"minAppVersion": "0.15.0",
|
||||
"description": "Enrich your notes with issue and pull request content from GitHub",
|
||||
"author": "Nathonius",
|
||||
|
|
|
|||
4
package-lock.json
generated
4
package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "obsidian-github-link",
|
||||
"version": "1.0.3",
|
||||
"version": "1.2.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "obsidian-github-link",
|
||||
"version": "1.0.3",
|
||||
"version": "1.2.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@octokit/auth-oauth-device": "^6.0.1",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "obsidian-github-link",
|
||||
"version": "1.0.3",
|
||||
"version": "1.2.0",
|
||||
"description": "An Obsidian plugin enriching notes with issue and pull request content from GitHub",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ export interface ParsedUrl {
|
|||
code?: {
|
||||
branch?: string;
|
||||
path?: string;
|
||||
filename?: string;
|
||||
line?: string;
|
||||
};
|
||||
commit?: string;
|
||||
}
|
||||
|
|
@ -60,6 +62,8 @@ export function parseUrl(urlString: string): ParsedUrl | null {
|
|||
if (urlParts[5]) {
|
||||
const pathParts = urlParts.slice(5);
|
||||
parsedUrl.code.path = pathParts.join("/");
|
||||
parsedUrl.code.filename = pathParts.last();
|
||||
parsedUrl.code.line = url.hash.slice(1);
|
||||
}
|
||||
break;
|
||||
case "commit":
|
||||
|
|
|
|||
|
|
@ -56,6 +56,10 @@ export function setIssueIcon(icon: HTMLElement, status: IssueStatus): void {
|
|||
icon.dataset.status = status;
|
||||
}
|
||||
|
||||
export function setFileIcon(icon: HTMLElement): void {
|
||||
setIcon(icon, "file");
|
||||
}
|
||||
|
||||
export function setPRMergeableIcon(icon: HTMLElement, mergeable: boolean): void {
|
||||
if (PluginSettings.tagTooltips) {
|
||||
icon.setAttribute("aria-label", PRMergeableText[`${mergeable}`]);
|
||||
|
|
|
|||
46
src/inline/inline.spec.ts
Normal file
46
src/inline/inline.spec.ts
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import { test, describe, expect, beforeAll } from "@jest/globals";
|
||||
import { elementTestSetup } from "../../test/element";
|
||||
import { createTag } from "./inline";
|
||||
|
||||
const selectors = {
|
||||
org: ".github-link-inline-org",
|
||||
repo: ".github-link-inline-repo",
|
||||
issueTitle: ".github-link-inline-issue-title",
|
||||
prTitle: ".github-link-inline-pr-title",
|
||||
file: ".github-link-inline-file",
|
||||
};
|
||||
|
||||
describe("createTag", () => {
|
||||
beforeAll(() => {
|
||||
elementTestSetup();
|
||||
});
|
||||
test.each([
|
||||
{ url: "https://github.com/nathonius", user: "nathonius" },
|
||||
{ url: "https://github.com/nathonius/", user: "nathonius" },
|
||||
{ url: "https://github.com/sam.lake", user: "sam.lake" },
|
||||
{ url: "https://github.com/abraham_lincoln", user: "abraham_lincoln" },
|
||||
])("user only $user", ({ url, user }) => {
|
||||
const tag = createTag(url);
|
||||
expect(tag).toBeTruthy();
|
||||
const org = tag?.querySelector(selectors.org) as HTMLSpanElement;
|
||||
expect(org.innerText).toEqual(user);
|
||||
[selectors.repo, selectors.issueTitle, selectors.prTitle, selectors.file].forEach((s) => {
|
||||
expect(tag?.querySelector(s)).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
test.each([
|
||||
{ url: "https://github.com/nathonius/obsidian-github-link", user: "nathonius", repo: "obsidian-github-link" },
|
||||
{ url: "https://github.com/nathonius/obsidian.github.link", user: "nathonius", repo: "obsidian.github.link" },
|
||||
])("repo $repo", ({ url, user, repo }) => {
|
||||
const tag = createTag(url);
|
||||
expect(tag).toBeTruthy();
|
||||
const org = tag?.querySelector(selectors.org) as HTMLSpanElement;
|
||||
const repoEl = tag?.querySelector(selectors.repo) as HTMLSpanElement;
|
||||
expect(org.innerText).toEqual(user);
|
||||
expect(repoEl.innerText).toEqual(repo);
|
||||
[selectors.issueTitle, selectors.prTitle, selectors.file].forEach((s) => {
|
||||
expect(tag?.querySelector(s)).toBeFalsy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { setIcon } from "obsidian";
|
||||
import { IssueStatus, getIssueStatus, getPRStatus } from "../github/response";
|
||||
import { setIssueIcon, setPRIcon, setPRMergeableIcon } from "../icon";
|
||||
import { setFileIcon, setIssueIcon, setPRIcon, setPRMergeableIcon } from "../icon";
|
||||
|
||||
import { PluginSettings } from "../plugin";
|
||||
import type { PullResponse } from "../github/response";
|
||||
|
|
@ -20,6 +20,7 @@ export function createTag(href: string): HTMLAnchorElement | null {
|
|||
if (!parsedUrl) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const container = createEl("a", { cls: "github-link-inline", href, attr: { target: "_blank" } });
|
||||
const config: TagConfig = {
|
||||
icon: createSpan({ cls: ["github-link-status-icon", "github-link-inline-icon"] }),
|
||||
|
|
@ -30,8 +31,8 @@ export function createTag(href: string): HTMLAnchorElement | null {
|
|||
createOrgSection(config, parsedUrl);
|
||||
createRepoSection(config, parsedUrl);
|
||||
|
||||
// Add issue OR pr
|
||||
if (parsedUrl.issue !== undefined || parsedUrl.pr !== undefined) {
|
||||
// Add issue OR pr OR file
|
||||
if (parsedUrl.issue !== undefined || parsedUrl.pr !== undefined || parsedUrl.code !== undefined) {
|
||||
// Remove org
|
||||
const orgIndex = config.sections.findIndex((section) => section.classList.contains("github-link-inline-org"));
|
||||
if (orgIndex !== -1) {
|
||||
|
|
@ -42,6 +43,8 @@ export function createTag(href: string): HTMLAnchorElement | null {
|
|||
createIssueSection(config, parsedUrl, container);
|
||||
} else if (parsedUrl.pr !== undefined) {
|
||||
createPullRequestSection(config, parsedUrl, container);
|
||||
} else if (parsedUrl.code !== undefined) {
|
||||
createFileSection(config, parsedUrl, container);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -95,17 +98,18 @@ function createIssueSection(config: TagConfig, parsedUrl: ParsedUrl, container:
|
|||
}
|
||||
setIssueIcon(config.icon, IssueStatus.Open);
|
||||
const issueContainer = createSpan({
|
||||
cls: "github-link-inline-issue-title",
|
||||
text: `${parsedUrl.issue}`,
|
||||
cls: "github-link-inline-issue-title-section",
|
||||
});
|
||||
issueContainer.createSpan({ text: `#${parsedUrl.issue}`, cls: "github-link-inline-issue-number" });
|
||||
config.sections.push(issueContainer);
|
||||
if (parsedUrl.org && parsedUrl.repo) {
|
||||
getIssue(parsedUrl.org, parsedUrl.repo, parsedUrl.issue)
|
||||
.then((issue) => {
|
||||
if (issue.title) {
|
||||
const title = createSpan({ text: issue.title, cls: "github-link-inline-issue-title" });
|
||||
issueContainer.prepend(title);
|
||||
const status = getIssueStatus(issue);
|
||||
setIssueIcon(config.icon, status);
|
||||
issueContainer.setText(issue.title);
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
|
|
@ -140,6 +144,28 @@ function createPullRequestSection(config: TagConfig, parsedUrl: ParsedUrl, conta
|
|||
}
|
||||
}
|
||||
|
||||
function createFileSection(config: TagConfig, parsedUrl: ParsedUrl, _container: HTMLAnchorElement) {
|
||||
if (parsedUrl.code === undefined) {
|
||||
return;
|
||||
}
|
||||
const fileContainer = createSpan({ cls: "github-link-inline-file" });
|
||||
setFileIcon(config.icon);
|
||||
config.sections.push(fileContainer);
|
||||
if (parsedUrl.code.filename) {
|
||||
fileContainer.setText(parsedUrl.code.filename);
|
||||
} else if (parsedUrl.code.path) {
|
||||
fileContainer.setText(parsedUrl.code.path);
|
||||
}
|
||||
if (PluginSettings.tagShowFileLineNumber && parsedUrl.code.line) {
|
||||
fileContainer.appendChild(createSpan({ cls: "github-link-inline-file-line-number", text: parsedUrl.code.line }));
|
||||
}
|
||||
if (PluginSettings.tagShowFileBranchName && parsedUrl.code.branch) {
|
||||
fileContainer.appendChild(
|
||||
createSpan({ cls: "github-link-inline-file-branch", text: `(${parsedUrl.code.branch})` }),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Note that this function is called AFTER the tag has been built, so it adds itself to the dom.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,123 +1,103 @@
|
|||
import { expect, test, describe } from "@jest/globals";
|
||||
import { matchRegexp } from './view-plugin';
|
||||
import { matchRegexp } from "./view-plugin";
|
||||
|
||||
// Some potential URLs:
|
||||
const GITHUB_URLS = [
|
||||
// USER/ORG
|
||||
'https://github.com/nathonius',
|
||||
// REPO
|
||||
'https://github.com/nathonius/obsidian-github-link',
|
||||
'https://github.com/nathonius/obsidian-github-link/tree/main',
|
||||
'https://github.com/joshleaves/obsidian-github-link/tree/fix/156-linking-to-file',
|
||||
'https://github.com/nathonius/obsidian-github-link/blob/main/src/github/url-parse.ts',
|
||||
'https://github.com/nathonius/obsidian-github-link/blob/main/src/inline/view-plugin.ts#L21',
|
||||
'https://github.com/nathonius/obsidian-github-link/blob/main/src/inline/view-plugin.ts#L13-32',
|
||||
// ISSUES
|
||||
'https://github.com/nathonius/obsidian-github-link/issues',
|
||||
'https://github.com/nathonius/obsidian-github-link/issues/156',
|
||||
// PULLS
|
||||
'https://github.com/nathonius/obsidian-github-link/pulls',
|
||||
'https://github.com/nathonius/obsidian-github-link/pull/157',
|
||||
'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'
|
||||
]
|
||||
// USER/ORG
|
||||
"https://github.com/nathonius",
|
||||
// REPO
|
||||
"https://github.com/nathonius/obsidian-github-link",
|
||||
"https://github.com/nathonius/obsidian-github-link/tree/main",
|
||||
"https://github.com/joshleaves/obsidian-github-link/tree/fix/156-linking-to-file",
|
||||
"https://github.com/nathonius/obsidian-github-link/blob/main/src/github/url-parse.ts",
|
||||
"https://github.com/nathonius/obsidian-github-link/blob/main/src/inline/view-plugin.ts#L21",
|
||||
"https://github.com/nathonius/obsidian-github-link/blob/main/src/inline/view-plugin.ts#L13-32",
|
||||
"https://github.com/academicpages/academicpages.github.io",
|
||||
// ISSUES
|
||||
"https://github.com/nathonius/obsidian-github-link/issues",
|
||||
"https://github.com/nathonius/obsidian-github-link/issues/156",
|
||||
// PULLS
|
||||
"https://github.com/nathonius/obsidian-github-link/pulls",
|
||||
"https://github.com/nathonius/obsidian-github-link/pull/157",
|
||||
"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', () => {
|
||||
test('matches GitHub URLs on their own', () => {
|
||||
GITHUB_URLS.forEach(url => {
|
||||
const text = `${url}` // (...)
|
||||
const match = text.match(matchRegexp);
|
||||
expect(match).not.toBeNull();
|
||||
expect(match![0]).toBe(url);
|
||||
});
|
||||
});
|
||||
describe("url regex match", () => {
|
||||
test.each(GITHUB_URLS)("matches GitHub URLs on their own", (url) => {
|
||||
const text = `${url}`; // (...)
|
||||
const match = text.match(matchRegexp);
|
||||
expect(match).not.toBeNull();
|
||||
expect(match![0]).toBe(url);
|
||||
});
|
||||
|
||||
test('does not match URLs inside markdown links', () => {
|
||||
GITHUB_URLS.forEach(url => {
|
||||
const text = `[A link to GitHub](${url})`;
|
||||
const match = text.match(matchRegexp);
|
||||
expect(match).toBeNull();
|
||||
});
|
||||
});
|
||||
test.each(GITHUB_URLS)("does not match URLs inside markdown links", (url) => {
|
||||
const text = `[A link to GitHub](${url})`;
|
||||
const match = text.match(matchRegexp);
|
||||
expect(match).toBeNull();
|
||||
});
|
||||
|
||||
test('matches URLs ending a sentence', () => {
|
||||
GITHUB_URLS.forEach(url => {
|
||||
const text = `That's the end of the line for ${url}.`;
|
||||
const match = text.match(matchRegexp);
|
||||
expect(match).not.toBeNull();
|
||||
expect(match![0]).toBe(url);
|
||||
});
|
||||
});
|
||||
test.each(GITHUB_URLS)("matches URLs ending a sentence", (url) => {
|
||||
const text = `That's the end of the line for ${url}.`;
|
||||
const match = text.match(matchRegexp);
|
||||
expect(match).not.toBeNull();
|
||||
expect(match![0]).toBe(url);
|
||||
});
|
||||
|
||||
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.each(GITHUB_URLS)("matches URLs followed by punctuation", (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.each(GITHUB_URLS)("matches URLs ending a sentence with an interrogative", (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.each(GITHUB_URLS)("matches URLs followed by multiple punctuation", (url) => {
|
||||
const text = `A test for ${url}...`;
|
||||
const match = text.match(matchRegexp);
|
||||
expect(match).not.toBeNull();
|
||||
expect(match![0]).toBe(url);
|
||||
});
|
||||
|
||||
test.each(GITHUB_URLS)("matches URLs ending a sentence that segues to another", (url) => {
|
||||
const text = `That's the end of the line for ${url}. But not for this variable!`;
|
||||
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!`;
|
||||
const match = text.match(matchRegexp);
|
||||
expect(match).not.toBeNull();
|
||||
expect(match![0]).toBe(url);
|
||||
});
|
||||
});
|
||||
|
||||
test('matches URLs in text with multiple lines', () => {
|
||||
GITHUB_URLS.forEach(url => {
|
||||
const text = `Some text
|
||||
test.each(GITHUB_URLS)("matches URLs in text with multiple lines", (url) => {
|
||||
const text = `Some text
|
||||
${url}
|
||||
more text.`;
|
||||
const match = text.match(matchRegexp);
|
||||
expect(match).not.toBeNull();
|
||||
expect(match![0]).toBe(url);
|
||||
});
|
||||
});
|
||||
const match = text.match(matchRegexp);
|
||||
expect(match).not.toBeNull();
|
||||
expect(match![0]).toBe(url);
|
||||
});
|
||||
|
||||
test('matches URLs in text followed by another text', () => {
|
||||
GITHUB_URLS.forEach(url => {
|
||||
const text = `${url} is a cool plugin`;
|
||||
const match = text.match(matchRegexp);
|
||||
expect(match).not.toBeNull();
|
||||
expect(match![0]).toBe(url);
|
||||
})
|
||||
});
|
||||
test.each(GITHUB_URLS)("matches URLs in text followed by another text", (url) => {
|
||||
const text = `${url} is a cool plugin`;
|
||||
const match = text.match(matchRegexp);
|
||||
expect(match).not.toBeNull();
|
||||
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);
|
||||
})
|
||||
});
|
||||
test.each(GITHUB_URLS)("matches URLs quoted", (url) => {
|
||||
const text = `Obama chuckled: you mean "${url}" ?`;
|
||||
const match = text.match(matchRegexp);
|
||||
expect(match).not.toBeNull();
|
||||
expect(match![0]).toBe(url);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -83,13 +83,20 @@ export class GithubLinkPluginSettingsTab extends PluginSettingTab {
|
|||
});
|
||||
})
|
||||
.addSlider((slider) => {
|
||||
const displayValue = createSpan({ text: PluginSettings.defaultPageSize.toString() });
|
||||
slider.sliderEl.parentElement?.prepend(displayValue);
|
||||
const manualInput = createEl("input", { attr: { type: "number" }, cls: "github-link-slider-input" });
|
||||
manualInput.value = PluginSettings.defaultPageSize.toString();
|
||||
manualInput.addEventListener("change", (e) => {
|
||||
const value = parseInt((e.target as HTMLInputElement).value, 10);
|
||||
PluginSettings.defaultPageSize = value;
|
||||
slider.setValue(value);
|
||||
void this.saveSettings();
|
||||
});
|
||||
slider.sliderEl.parentElement?.prepend(manualInput);
|
||||
slider.setLimits(0, 30, 1);
|
||||
slider.setDynamicTooltip();
|
||||
slider.setValue(PluginSettings.defaultPageSize);
|
||||
slider.onChange((value) => {
|
||||
displayValue.setText(value.toString());
|
||||
manualInput.value = value.toString();
|
||||
PluginSettings.defaultPageSize = value;
|
||||
void this.saveSettings();
|
||||
});
|
||||
|
|
@ -150,6 +157,28 @@ export class GithubLinkPluginSettingsTab extends PluginSettingTab {
|
|||
});
|
||||
});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("File branch name")
|
||||
.setDesc("Append the branch name to links to an individual file inside a repo")
|
||||
.addToggle((toggle) => {
|
||||
toggle.setValue(PluginSettings.tagShowFileBranchName);
|
||||
toggle.onChange((value) => {
|
||||
PluginSettings.tagShowFileBranchName = value;
|
||||
void this.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("File line number")
|
||||
.setDesc("Append the line number (if provided) to links to an individual file inside a repo")
|
||||
.addToggle((toggle) => {
|
||||
toggle.setValue(PluginSettings.tagShowFileLineNumber);
|
||||
toggle.onChange((value) => {
|
||||
PluginSettings.tagShowFileLineNumber = value;
|
||||
void this.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
containerEl.createEl("h3", { text: "Cache settings" });
|
||||
|
||||
new Setting(containerEl)
|
||||
|
|
@ -169,14 +198,21 @@ export class GithubLinkPluginSettingsTab extends PluginSettingTab {
|
|||
});
|
||||
})
|
||||
.addSlider((slider) => {
|
||||
const displayValue = createSpan({ text: PluginSettings.cacheIntervalSeconds.toString() });
|
||||
slider.sliderEl.parentElement?.prepend(displayValue);
|
||||
const manualInput = createEl("input", { attr: { type: "number" }, cls: "github-link-slider-input" });
|
||||
manualInput.value = PluginSettings.cacheIntervalSeconds.toString();
|
||||
manualInput.addEventListener("change", (e) => {
|
||||
const value = parseInt((e.target as HTMLInputElement).value, 10);
|
||||
PluginSettings.cacheIntervalSeconds = value;
|
||||
slider.setValue(value);
|
||||
void this.saveSettings();
|
||||
});
|
||||
slider.sliderEl.parentElement?.prepend(manualInput);
|
||||
slider.setValue(PluginSettings.cacheIntervalSeconds);
|
||||
slider.setLimits(10, 1200, 10);
|
||||
slider.setDynamicTooltip();
|
||||
slider.onChange(async (value) => {
|
||||
PluginSettings.cacheIntervalSeconds = value;
|
||||
displayValue.setText(value.toString());
|
||||
manualInput.value = value.toString();
|
||||
await this.saveSettings();
|
||||
this.plugin.setCacheInterval();
|
||||
});
|
||||
|
|
@ -197,14 +233,21 @@ export class GithubLinkPluginSettingsTab extends PluginSettingTab {
|
|||
});
|
||||
})
|
||||
.addSlider((slider) => {
|
||||
const displayValue = createSpan({ text: PluginSettings.maxCacheAgeHours.toString() });
|
||||
slider.sliderEl.parentElement?.prepend(displayValue);
|
||||
const manualInput = createEl("input", { attr: { type: "number" }, cls: "github-link-slider-input" });
|
||||
manualInput.value = PluginSettings.maxCacheAgeHours.toString();
|
||||
manualInput.addEventListener("change", (e) => {
|
||||
const value = parseInt((e.target as HTMLInputElement).value, 10);
|
||||
PluginSettings.maxCacheAgeHours = value;
|
||||
slider.setValue(value);
|
||||
void this.saveSettings();
|
||||
});
|
||||
slider.sliderEl.parentElement?.prepend(manualInput);
|
||||
slider.setValue(PluginSettings.maxCacheAgeHours);
|
||||
slider.setLimits(0, 170, 10);
|
||||
slider.setDynamicTooltip();
|
||||
slider.onChange(async (value) => {
|
||||
PluginSettings.maxCacheAgeHours = value;
|
||||
displayValue.setText(value.toString());
|
||||
manualInput.value = value.toString();
|
||||
await this.saveSettings();
|
||||
});
|
||||
});
|
||||
|
|
@ -225,14 +268,21 @@ export class GithubLinkPluginSettingsTab extends PluginSettingTab {
|
|||
});
|
||||
})
|
||||
.addSlider((slider) => {
|
||||
const displayValue = createSpan({ text: PluginSettings.minRequestSeconds.toString() });
|
||||
slider.sliderEl.parentElement?.prepend(displayValue);
|
||||
const manualInput = createEl("input", { attr: { type: "number" }, cls: "github-link-slider-input" });
|
||||
manualInput.value = PluginSettings.minRequestSeconds.toString();
|
||||
manualInput.addEventListener("change", (e) => {
|
||||
const value = parseInt((e.target as HTMLInputElement).value, 10);
|
||||
PluginSettings.minRequestSeconds = value;
|
||||
slider.setValue(value);
|
||||
void this.saveSettings();
|
||||
});
|
||||
slider.sliderEl.parentElement?.prepend(manualInput);
|
||||
slider.setValue(PluginSettings.minRequestSeconds);
|
||||
slider.setLimits(10, 1200, 10);
|
||||
slider.setDynamicTooltip();
|
||||
slider.onChange(async (value) => {
|
||||
PluginSettings.minRequestSeconds = value;
|
||||
displayValue.setText(value.toString());
|
||||
manualInput.value = value.toString();
|
||||
await this.saveSettings();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ export interface GithubLinkPluginSettings {
|
|||
logLevel: LogLevel;
|
||||
tagTooltips: boolean;
|
||||
tagShowPRMergeable: boolean;
|
||||
tagShowFileBranchName: boolean;
|
||||
tagShowFileLineNumber: boolean;
|
||||
cacheIntervalSeconds: number;
|
||||
maxCacheAgeHours: number;
|
||||
minRequestSeconds: number;
|
||||
|
|
@ -41,6 +43,8 @@ export const DEFAULT_SETTINGS: GithubLinkPluginSettings = {
|
|||
logLevel: LogLevel.Error,
|
||||
tagTooltips: false,
|
||||
tagShowPRMergeable: false,
|
||||
tagShowFileBranchName: true,
|
||||
tagShowFileLineNumber: true,
|
||||
cacheIntervalSeconds: 60,
|
||||
maxCacheAgeHours: 120,
|
||||
minRequestSeconds: 60,
|
||||
|
|
|
|||
29
styles.css
29
styles.css
|
|
@ -151,6 +151,10 @@ body.theme-dark {
|
|||
padding-left: 2rem;
|
||||
}
|
||||
|
||||
.github-link-slider-input {
|
||||
width: 3rem;
|
||||
}
|
||||
|
||||
.github-link-inline {
|
||||
display: inline-flex;
|
||||
background-color: var(--gh-color-canvas-default);
|
||||
|
|
@ -176,6 +180,14 @@ body.theme-dark {
|
|||
overflow: hidden;
|
||||
}
|
||||
|
||||
.github-link-inline-section:first-child {
|
||||
border-radius: 3.5px 0 0 3.5px;
|
||||
}
|
||||
|
||||
.github-link-inline-section:last-child {
|
||||
border-radius: 0 3.5px 3.5px 0;
|
||||
}
|
||||
|
||||
.github-link-inline-icon {
|
||||
display: inline-flex;
|
||||
padding: 2px 0;
|
||||
|
|
@ -265,12 +277,27 @@ body.theme-dark {
|
|||
}
|
||||
|
||||
.github-link-inline-pr-title,
|
||||
.github-link-inline-issue-title {
|
||||
.github-link-inline-issue-title,
|
||||
.github-link-inline-issue-title-section,
|
||||
.github-link-inline-file {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
text-wrap: nowrap;
|
||||
line-height: var(--line-height-normal);
|
||||
}
|
||||
.github-link-inline-issue-number {
|
||||
color: var(--gh-color-fg-muted);
|
||||
}
|
||||
|
||||
.github-link-inline-file,
|
||||
.github-link-inline-issue-title-section {
|
||||
display: flex;
|
||||
gap: 2px;
|
||||
}
|
||||
.github-link-inline-file > .github-link-inline-file-line-number,
|
||||
.github-link-inline-file > .github-link-inline-file-branch {
|
||||
color: var(--gh-color-fg-muted);
|
||||
}
|
||||
|
||||
.github-link-table-wrapper {
|
||||
margin-block-end: var(--p-spacing);
|
||||
|
|
|
|||
66
test/element.ts
Normal file
66
test/element.ts
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/**
|
||||
* Local version of obsidian's 'createEl' function, copied from
|
||||
* https://ryotaushio.github.io/the-hobbyist-dev/obsidian/api-&-internals/createel.html
|
||||
*/
|
||||
function createEl<K extends keyof HTMLElementTagNameMap>(
|
||||
tag: K,
|
||||
options?: string | DomElementInfo,
|
||||
callback?: (el: HTMLElementTagNameMap[K]) => void,
|
||||
): HTMLElementTagNameMap[K] {
|
||||
const el = document.createElement(tag);
|
||||
if (typeof options === "string") options = { cls: options };
|
||||
options = options || {};
|
||||
|
||||
if (options.cls) Array.isArray(options.cls) ? (el.className = options.cls.join(" ")) : (el.className = options.cls);
|
||||
if (options.text) el.setText(options.text);
|
||||
if (options.attr) {
|
||||
for (const [k, v] of Object.entries(options.attr)) {
|
||||
el.setAttribute(k, String(v));
|
||||
}
|
||||
}
|
||||
if (options.title !== undefined) el.title = options.title;
|
||||
if (
|
||||
options.value !== undefined &&
|
||||
(el instanceof HTMLInputElement || el instanceof HTMLSelectElement || el instanceof HTMLOptionElement)
|
||||
) {
|
||||
el.value = options.value;
|
||||
}
|
||||
if (options.type && el instanceof HTMLInputElement) el.type = options.type;
|
||||
if (options.type && el instanceof HTMLStyleElement) el.setAttribute("type", options.type);
|
||||
if (options.placeholder && el instanceof HTMLInputElement) el.placeholder = options.placeholder;
|
||||
if (
|
||||
options.href &&
|
||||
(el instanceof HTMLAnchorElement || el instanceof HTMLLinkElement || el instanceof HTMLBaseElement)
|
||||
)
|
||||
el.href = options.href;
|
||||
callback?.(el);
|
||||
if (options.parent) {
|
||||
if (options.prepend) options.parent.insertBefore(el, options.parent.firstChild);
|
||||
else options.parent.appendChild(el);
|
||||
}
|
||||
// add event listeners (e.g. { onclick: () => {} })
|
||||
for (const key in options) {
|
||||
if (Object.prototype.hasOwnProperty.call(options, key) && key.startsWith("on")) {
|
||||
const value = options[key as keyof DomElementInfo];
|
||||
if (typeof value === "function") el.addEventListener(key.substring(2), value);
|
||||
}
|
||||
}
|
||||
return el;
|
||||
}
|
||||
|
||||
function createSpan(options?: string | DomElementInfo, callback?: (el: HTMLSpanElement) => void) {
|
||||
return createEl("span", options, callback);
|
||||
}
|
||||
|
||||
function createDiv(options?: string | DomElementInfo, callback?: (el: HTMLDivElement) => void) {
|
||||
return createEl("div", options, callback);
|
||||
}
|
||||
|
||||
export function elementTestSetup() {
|
||||
HTMLElement.prototype.setText = function (text: string) {
|
||||
this.innerText = text;
|
||||
};
|
||||
window.createEl = createEl;
|
||||
window.createSpan = createSpan;
|
||||
window.createDiv = createDiv;
|
||||
}
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
{
|
||||
"1.2.0": "0.15.0",
|
||||
"1.1.0": "0.15.0",
|
||||
"1.0.3": "0.15.0",
|
||||
"1.0.2": "0.15.0",
|
||||
"1.0.0": "0.15.0",
|
||||
|
|
|
|||
Loading…
Reference in a new issue