一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
34 行
894 B
TypeScript
34 行
894 B
TypeScript
const resourceRegex = /^(joplin:\/\/|:\/)([0-9a-zA-Z]{32})(|#[^\s]*)(|\s".*?")$/;
|
|
|
|
export const urlDecode = (string: string): string => {
|
|
return decodeURIComponent((`${string}`).replace(/\+/g, '%20'));
|
|
};
|
|
|
|
export const isResourceUrl = (url: string): boolean => {
|
|
return !!url.match(resourceRegex);
|
|
};
|
|
|
|
export interface ParsedResourceUrl {
|
|
itemId: string;
|
|
hash: string;
|
|
}
|
|
|
|
export const parseResourceUrl = (url: string): ParsedResourceUrl | null => {
|
|
if (!isResourceUrl(url)) return null;
|
|
|
|
const match = url.match(resourceRegex);
|
|
|
|
const itemId = match[2];
|
|
let hash = match[3].trim();
|
|
|
|
// In general we want the hash to be decoded so that non-alphabetical languages
|
|
// appear as-is without being encoded with %.
|
|
// Fixes https://github.com/laurent22/joplin/issues/1870
|
|
if (hash) hash = urlDecode(hash.substr(1)); // Remove the first #
|
|
|
|
return {
|
|
itemId: itemId,
|
|
hash: hash,
|
|
};
|
|
};
|