yanki 2.0.13 → 2.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/cli.js +159 -159
- package/dist/bin/open-DWLEjJQI.js +2 -0
- package/dist/lib/index.js +131 -128
- package/dist/standalone/index.d.ts +1 -1
- package/dist/standalone/index.js +151 -151
- package/dist/standalone/open-DT4JCo3f.js +2 -0
- package/package.json +22 -22
- package/readme.md +5 -5
- package/dist/bin/open-PkGTdlsi.js +0 -2
- package/dist/standalone/open-DnUwqK4E.js +0 -2
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import e from"node:process";import t from"node:fs";import n from"node:path";import{promisify as r}from"node:util";import i,{execFile as a}from"node:child_process";import{fileURLToPath as o}from"node:url";import s,{constants as c}from"node:fs/promises";import l from"node:os";import{Buffer as u}from"node:buffer";let d;function f(){try{return t.statSync(`/.dockerenv`),!0}catch{return!1}}function p(){try{return t.readFileSync(`/proc/self/cgroup`,`utf8`).includes(`docker`)}catch{return!1}}function ee(){return d===void 0&&(d=f()||p()),d}let m;const te=()=>{try{return t.statSync(`/run/.containerenv`),!0}catch{return!1}};function h(){return m===void 0&&(m=te()||ee()),m}const g=()=>{if(e.platform!==`linux`)return!1;if(l.release().toLowerCase().includes(`microsoft`))return!h();try{if(t.readFileSync(`/proc/version`,`utf8`).toLowerCase().includes(`microsoft`))return!h()}catch{}return t.existsSync(`/proc/sys/fs/binfmt_misc/WSLInterop`)||t.existsSync(`/run/WSL`)?!h():!1};var _=e.env.__IS_WSL_TEST__?g:g();const v=r(i.execFile),y=()=>`${e.env.SYSTEMROOT||e.env.windir||String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`,b=async(e,t={})=>{let{powerShellPath:n,...r}=t,i=b.encodeCommand(e);return v(n??y(),[...b.argumentsPrefix,i],{encoding:`utf8`,...r})};b.argumentsPrefix=[`-NoProfile`,`-NonInteractive`,`-ExecutionPolicy`,`Bypass`,`-EncodedCommand`],b.encodeCommand=e=>u.from(e,`utf16le`).toString(`base64`),b.escapeArgument=e=>`'${String(e).replaceAll(`'`,`''`)}'`;function ne(e){for(let t of e.split(`
|
|
2
|
+
`)){if(/^\s*#/.test(t))continue;let e=/^\s*root\s*=\s*(?<mountPoint>"[^"]*"|'[^']*'|[^#]*)/.exec(t);if(e)return e.groups.mountPoint.trim().replaceAll(/^["']|["']$/g,``)}}const re=r(i.execFile),ie=(()=>{let e=`/mnt/`,t;return async function(){if(t)return t;let n=`/etc/wsl.conf`,r=!1;try{await s.access(n,c.F_OK),r=!0}catch{}if(!r)return e;let i=ne(await s.readFile(n,{encoding:`utf8`}));return i===void 0?e:(t=i,t=t.endsWith(`/`)?t:`${t}/`,t)}})(),x=_?async()=>`${await ie()}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe`:y;let S;const C=async()=>(S??=(async()=>{try{let e=await x();return await s.access(e,c.X_OK),!0}catch{return!1}})(),S),w=async()=>{let e=await x(),t=String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`,{stdout:r}=await b(t,{powerShellPath:e,cwd:n.dirname(e)});return r.trim()},ae=e=>/^[a-z]+:\/\//i.test(e),oe=async e=>{let t=Array.isArray(e),n=t?e:[e],r=[],i=[];for(let[e,t]of n.entries())ae(t)||(r.push(e),i.push(t));let a=[...n];if(i.length>0)try{let{stdout:e}=await re(`wslpath`,[`-aw`,...i],{encoding:`utf8`}),t=e.split(/\r?\n/).filter(Boolean);for(let[e,i]of r.entries())a[i]=t[e]??n[i]}catch{}return t?a:a[0]},se=r(i.execFile),ce=()=>`${e.env.SYSTEMROOT||e.env.windir||String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`,T=[`-NoProfile`,`-NonInteractive`,`-ExecutionPolicy`,`Bypass`,`-EncodedCommand`],E=e=>u.from(e,`utf16le`).toString(`base64`),le=e=>`'${String(e).replaceAll(`'`,`''`)}'`,D=e=>[...T,E(e)],O=async(e,t={})=>{let{powerShellPath:n,...r}=t;return se(n??ce(),D(e),{encoding:`utf8`,...r})};O.argumentsPrefix=T,O.encodeCommand=E,O.escapeArgument=le,O.createArguments=D;function k(e,t,n){let r=n=>Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0});return Object.defineProperty(e,t,{configurable:!0,enumerable:!0,get(){let e=n();return r(e),e},set(e){r(e)}}),e}const A=r(a);async function j(){if(e.platform!==`darwin`)throw Error(`macOS only`);let{stdout:t}=await A(`defaults`,[`read`,`com.apple.LaunchServices/com.apple.launchservices.secure`,`LSHandlers`]),n=/LSHandlerRoleAll = "(?!-)(?<id>[^"]+?)";\s+?LSHandlerURLScheme = (?:http|https);/.exec(t)?.groups.id??`com.apple.Safari`;return n===`com.apple.safari`?`com.apple.Safari`:n}const M=r(a);async function N(t,{humanReadableOutput:n=!0,signal:r}={}){if(e.platform!==`darwin`)throw Error(`macOS only`);let i=n?[]:[`-ss`],a={};r&&(a.signal=r);let{stdout:o}=await M(`osascript`,[`-e`,t,i],a);return o.trim()}async function P(e){return N(`tell application "Finder" to set app_path to application file id "${e}" as string\ntell application "System Events" to get value of property list item "CFBundleName" of property list file (app_path & ":Contents:Info.plist")`)}const F=r(a),I={MSEdgeHTM:{name:`Edge`,id:`com.microsoft.edge`},MSEdgeBHTML:{name:`Edge Beta`,id:`com.microsoft.edge.beta`},MSEdgeDHTML:{name:`Edge Dev`,id:`com.microsoft.edge.dev`},AppXq0fevzme2pys62n3e0fbqa7peapykr8v:{name:`Edge`,id:`com.microsoft.edge.old`},ChromeHTML:{name:`Chrome`,id:`com.google.chrome`},ChromeBHTML:{name:`Chrome Beta`,id:`com.google.chrome.beta`},ChromeDHTML:{name:`Chrome Dev`,id:`com.google.chrome.dev`},ChromiumHTM:{name:`Chromium`,id:`org.chromium.Chromium`},BraveHTML:{name:`Brave`,id:`com.brave.Browser`},BraveBHTML:{name:`Brave Beta`,id:`com.brave.Browser.beta`},BraveDHTML:{name:`Brave Dev`,id:`com.brave.Browser.dev`},BraveSSHTM:{name:`Brave Nightly`,id:`com.brave.Browser.nightly`},FirefoxURL:{name:`Firefox`,id:`org.mozilla.firefox`},OperaStable:{name:`Opera`,id:`com.operasoftware.Opera`},VivaldiHTM:{name:`Vivaldi`,id:`com.vivaldi.Vivaldi`},"IE.HTTP":{name:`Internet Explorer`,id:`com.microsoft.ie`}},L=new Map(Object.entries(I));var R=class extends Error{};async function z(t=F){let{stdout:n}=await t(`${e.env.SYSTEMROOT??e.env.windir??`C:\\Windows`}\\System32\\reg.exe`,[`QUERY`,` HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice`,`/v`,`ProgId`]),r=/ProgId\s*REG_SZ\s*(?<id>\S+)/.exec(n);if(!r)throw new R(`Cannot find Windows browser in stdout: ${JSON.stringify(n)}`);let{id:i}=r.groups,a=i.lastIndexOf(`.`),o=i.lastIndexOf(`-`),s=a===-1?void 0:i.slice(0,a),c=o===-1?void 0:i.slice(0,o);return I[i]??I[s]??I[c]??{name:i,id:i}}const B=r(a),V=e=>e.toLowerCase().replaceAll(/(?:^|\s|-)\S/g,e=>e.toUpperCase());async function H(){if(e.platform===`darwin`){let e=await j();return{name:await P(e),id:e}}if(e.platform===`linux`){let{stdout:e}=await B(`xdg-mime`,[`query`,`default`,`x-scheme-handler/http`]),t=e.trim();return{name:V(t.replace(/.desktop$/,``).replace(`-`,` `)),id:t}}if(e.platform===`win32`)return z();throw Error(`Only macOS, Linux, and Windows are supported`)}const U=!!(e.env.SSH_CONNECTION||e.env.SSH_CLIENT||e.env.SSH_TTY),W=Symbol(`fallbackAttempt`),G=import.meta.url?n.dirname(o(import.meta.url)):``,K=n.join(G,`xdg-open`),{platform:q,arch:J}=e,Y=async(e,t)=>{if(e.length===0)return;let n=[];for(let r of e)try{return await t(r)}catch(e){n.push(e)}throw AggregateError(n,`Failed to open in all supported apps`)},X=async t=>{t={wait:!1,background:!1,newInstance:!1,allowNonzeroExitCode:!1,...t};let r=t[W]===!0;if(delete t[W],Array.isArray(t.app))return Y(t.app,e=>X({...t,app:e,[W]:!0}));let{name:a,arguments:o=[]}=t.app??{};if(o=[...o],Array.isArray(a))return Y(a,e=>X({...t,app:{name:e,arguments:o},[W]:!0}));if(a===`browser`||a===`browserPrivate`){let e={"com.google.chrome":`chrome`,"google-chrome.desktop":`chrome`,"com.brave.browser":`brave`,"org.mozilla.firefox":`firefox`,"firefox.desktop":`firefox`,"com.microsoft.msedge":`edge`,"com.microsoft.edge":`edge`,"com.microsoft.edgemac":`edge`,"microsoft-edge.desktop":`edge`,"com.apple.safari":`safari`},n={chrome:`--incognito`,brave:`--incognito`,firefox:`--private-window`,edge:`--inPrivate`},r;if(_){let e=await w();r=L.get(e)??{}}else r=await H();if(r.id in e){let i=e[r.id.toLowerCase()];if(a===`browserPrivate`){if(i===`safari`)throw Error(`Safari doesn't support opening in private mode via command line`);o.push(n[i])}return X({...t,app:{name:$[i],arguments:o}})}throw Error(`${r.name} is not supported as a default browser`)}let l,u=[],d={},f=!1;if(_&&!h()&&!U&&!a&&(f=await C()),q===`darwin`)l=`open`,t.wait&&u.push(`--wait-apps`),t.background&&u.push(`--background`),t.newInstance&&u.push(`--new`),a&&u.push(`-a`,a);else if(q===`win32`||f){l=await x(),u.push(...O.argumentsPrefix),_||(d.windowsVerbatimArguments=!0),_&&t.target&&(t.target=await oe(t.target));let e=[`$ProgressPreference = 'SilentlyContinue';`,`Start`];t.wait&&e.push(`-Wait`),a?(e.push(O.escapeArgument(a)),t.target&&o.push(t.target)):t.target&&e.push(O.escapeArgument(t.target)),o.length>0&&(o=o.map(e=>O.escapeArgument(e)),e.push(`-ArgumentList`,o.join(`,`))),t.target=O.encodeCommand(e.join(` `)),t.wait||(d.stdio=`ignore`),_&&(d.cwd=n.dirname(l))}else{if(a)l=a;else{let t=!G||G===`/`,n=!1;try{await s.access(K,c.X_OK),n=!0}catch{}l=e.versions.electron??(q===`android`||t||!n)?`xdg-open`:K}o.length>0&&u.push(...o),t.wait||(d.stdio=`ignore`,d.detached=!0)}q===`darwin`&&o.length>0&&u.push(`--args`,...o),t.target&&u.push(t.target);let p=i.spawn(l,u,d);return t.wait?new Promise((e,n)=>{p.once(`error`,n),p.once(`close`,r=>{if(!t.allowNonzeroExitCode&&r!==0){n(Error(`Exited with code ${r}`));return}e(p)})}):r?new Promise((e,t)=>{p.once(`error`,t),p.once(`spawn`,()=>{p.once(`close`,n=>{if(p.off(`error`,t),n!==0){t(Error(`Exited with code ${n}`));return}p.unref(),e(p)})})}):(p.unref(),new Promise((e,t)=>{p.once(`error`,t),p.once(`spawn`,()=>{p.off(`error`,t),e(p)})}))},ue=(e,t)=>{if(typeof e!=`string`&&!Array.isArray(e))throw TypeError("Expected a valid `name`");let{arguments:n=[]}=t??{};if(n!=null&&!Array.isArray(n))throw TypeError("Expected `appArguments` as Array type");return X({...t,app:{name:e,arguments:n}})};function Z(e){if(typeof e==`string`||Array.isArray(e))return e;let{[J]:t}=e;if(!t)throw Error(`${J} is not supported`);return t}function Q({[q]:e},{wsl:t}={}){if(t&&_)return Z(t);if(!e)throw Error(`${q} is not supported`);return Z(e)}const $={browser:`browser`,browserPrivate:`browserPrivate`};k($,`chrome`,()=>Q({darwin:`google chrome`,win32:`chrome`,linux:[`google-chrome`,`google-chrome-stable`,`chromium`,`chromium-browser`]},{wsl:{ia32:`/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe`,x64:[`/mnt/c/Program Files/Google/Chrome/Application/chrome.exe`,`/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe`]}})),k($,`brave`,()=>Q({darwin:`brave browser`,win32:`brave`,linux:[`brave-browser`,`brave`]},{wsl:{ia32:`/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe`,x64:[`/mnt/c/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe`,`/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe`]}})),k($,`firefox`,()=>Q({darwin:`firefox`,win32:String.raw`C:\Program Files\Mozilla Firefox\firefox.exe`,linux:`firefox`},{wsl:`/mnt/c/Program Files/Mozilla Firefox/firefox.exe`})),k($,`edge`,()=>Q({darwin:`microsoft edge`,win32:`msedge`,linux:[`microsoft-edge`,`microsoft-edge-dev`]},{wsl:`/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe`})),k($,`safari`,()=>Q({darwin:`Safari`}));export{ue as openApp};
|
package/dist/lib/index.js
CHANGED
|
@@ -91,7 +91,7 @@ function truncateOnWordBoundary(text, maxLength, truncationString = "...", wordB
|
|
|
91
91
|
return `${words.join(wordBoundary).slice(0, maxLengthSafe)}${truncationString}`;
|
|
92
92
|
}
|
|
93
93
|
function cleanClassName(className) {
|
|
94
|
-
return className.toLowerCase().replaceAll(
|
|
94
|
+
return className.toLowerCase().replaceAll(new RegExp("[^\\dA-Za-z]", "gv"), " ").trim().replaceAll(new RegExp(" +", "gv"), "-");
|
|
95
95
|
}
|
|
96
96
|
function emptyIsUndefined(text) {
|
|
97
97
|
if (text === void 0) return;
|
|
@@ -106,8 +106,8 @@ function emptyIsUndefined(text) {
|
|
|
106
106
|
function css$1(strings, ...values) {
|
|
107
107
|
return trimLeadingIndentation(strings, ...values);
|
|
108
108
|
}
|
|
109
|
-
const NEWLINE_REGEX$1 =
|
|
110
|
-
const LEADING_WHITESPACE_REGEX =
|
|
109
|
+
const NEWLINE_REGEX$1 = new RegExp("\\r?\\n", "v");
|
|
110
|
+
const LEADING_WHITESPACE_REGEX = new RegExp("^(\\s+)", "v");
|
|
111
111
|
function trimLeadingIndentation(strings, ...values) {
|
|
112
112
|
const lines = strings.reduce((result, text, i) => `${result}${text}${String(values[i] ?? "")}`, "").split(NEWLINE_REGEX$1).filter((line) => line.trim() !== "");
|
|
113
113
|
const leadingSpace = LEADING_WHITESPACE_REGEX.exec(lines[0] ?? "")?.[0] ?? "";
|
|
@@ -165,7 +165,7 @@ const NOTE_DEFAULT_EMPTY_HAST = u("element", {
|
|
|
165
165
|
properties: {},
|
|
166
166
|
tagName: "em"
|
|
167
167
|
}, [u("text", NOTE_DEFAULT_EMPTY_TEXT)])]);
|
|
168
|
-
const MEDIA_DEFAULT_HASH_MODE_FILE = "
|
|
168
|
+
const MEDIA_DEFAULT_HASH_MODE_FILE = "content";
|
|
169
169
|
const MEDIA_DEFAULT_HASH_MODE_URL = "metadata";
|
|
170
170
|
/**
|
|
171
171
|
* How to first attempt to infer the asset type behind a URL.
|
|
@@ -235,8 +235,7 @@ const MEDIA_SUPPORTED_AUDIO_VIDEO_EXTENSIONS = [
|
|
|
235
235
|
];
|
|
236
236
|
/**
|
|
237
237
|
* Anki seems happy to open PDF files and download markdown files that have been
|
|
238
|
-
* added to the assets folder...
|
|
239
|
-
* https://help.obsidian.md/Files+and+folders/Accepted+file+formats
|
|
238
|
+
* added to the assets folder... https://obsidian.md/help/file-formats
|
|
240
239
|
*/
|
|
241
240
|
const MEDIA_SUPPORTED_FILE_EXTENSIONS = ["md", "pdf"];
|
|
242
241
|
const MEDIA_SUPPORTED_EXTENSIONS = [
|
|
@@ -247,7 +246,7 @@ const MEDIA_SUPPORTED_EXTENSIONS = [
|
|
|
247
246
|
//#endregion
|
|
248
247
|
//#region src/lib/utilities/platform.ts
|
|
249
248
|
const ENVIRONMENT = typeof window === "undefined" ? typeof process === "undefined" ? "other" : "node" : "browser";
|
|
250
|
-
ENVIRONMENT === "browser" ?
|
|
249
|
+
ENVIRONMENT === "browser" ? new RegExp("windows", "iv").test(navigator.userAgent) || new RegExp("mac", "iv").test(navigator.userAgent) || new RegExp("linux", "iv").test(navigator.userAgent) || new RegExp("ubuntu", "iv").test(navigator.userAgent) : ENVIRONMENT === "node" && (process.platform === "win32" || process.platform === "darwin" || process.platform);
|
|
251
250
|
//#endregion
|
|
252
251
|
//#region src/lib/shared/types.ts
|
|
253
252
|
const defaultGlobalOptions = {
|
|
@@ -308,100 +307,103 @@ async function fileExists(absoluteFilePath, fileAdapter) {
|
|
|
308
307
|
}
|
|
309
308
|
async function getFileContentHash(absoluteFilePath, fileAdapter, mode = MEDIA_DEFAULT_HASH_MODE_FILE) {
|
|
310
309
|
switch (mode) {
|
|
311
|
-
case "content":
|
|
310
|
+
case "content": {
|
|
311
|
+
const fileContent = await fileAdapter.readFileBuffer(absoluteFilePath);
|
|
312
|
+
return (await sha256(fileContent)).slice(0, 16);
|
|
313
|
+
}
|
|
312
314
|
case "metadata": {
|
|
313
315
|
const { mtimeMs, size } = await fileAdapter.stat(absoluteFilePath);
|
|
314
|
-
const
|
|
315
|
-
if (
|
|
316
|
-
return getHash(
|
|
316
|
+
const metadataString = `${mtimeMs ?? ""}${size ?? ""}`;
|
|
317
|
+
if (metadataString === "") return getHash(absoluteFilePath, 16);
|
|
318
|
+
return getHash(`${absoluteFilePath}${metadataString}`, 16);
|
|
317
319
|
}
|
|
318
320
|
case "name": return getHash(absoluteFilePath, 16);
|
|
319
321
|
}
|
|
320
322
|
}
|
|
321
323
|
//#endregion
|
|
322
324
|
//#region src/lib/utilities/namespace.ts
|
|
323
|
-
const CONSECUTIVE_HYPHENS_REGEX =
|
|
324
|
-
const ASTERISK_REGEX =
|
|
325
|
+
const CONSECUTIVE_HYPHENS_REGEX = new RegExp("-+", "gv");
|
|
326
|
+
const ASTERISK_REGEX = new RegExp("\\*", "v");
|
|
325
327
|
const FORBIDDEN_CHARACTERS = [
|
|
326
|
-
[
|
|
327
|
-
[
|
|
328
|
-
[
|
|
329
|
-
[
|
|
330
|
-
[
|
|
331
|
-
[
|
|
332
|
-
[
|
|
333
|
-
[
|
|
334
|
-
[
|
|
335
|
-
[
|
|
336
|
-
[
|
|
337
|
-
[
|
|
338
|
-
[
|
|
339
|
-
[
|
|
340
|
-
[
|
|
341
|
-
[
|
|
342
|
-
[
|
|
343
|
-
[
|
|
344
|
-
[
|
|
345
|
-
[
|
|
346
|
-
[
|
|
347
|
-
[
|
|
348
|
-
[
|
|
349
|
-
[
|
|
350
|
-
[
|
|
351
|
-
[
|
|
352
|
-
[
|
|
353
|
-
[
|
|
354
|
-
[
|
|
355
|
-
[
|
|
356
|
-
[
|
|
357
|
-
[
|
|
358
|
-
[
|
|
359
|
-
[
|
|
360
|
-
[
|
|
361
|
-
[
|
|
362
|
-
[
|
|
363
|
-
[
|
|
364
|
-
[
|
|
365
|
-
[
|
|
366
|
-
[
|
|
367
|
-
[
|
|
368
|
-
[
|
|
369
|
-
[
|
|
370
|
-
[
|
|
371
|
-
[
|
|
372
|
-
[
|
|
373
|
-
[
|
|
374
|
-
[
|
|
375
|
-
[
|
|
376
|
-
[
|
|
377
|
-
[
|
|
378
|
-
[
|
|
379
|
-
[
|
|
380
|
-
[
|
|
381
|
-
[
|
|
382
|
-
[
|
|
383
|
-
[
|
|
384
|
-
[
|
|
385
|
-
[
|
|
386
|
-
[
|
|
387
|
-
[
|
|
388
|
-
[
|
|
389
|
-
[
|
|
390
|
-
[
|
|
391
|
-
[
|
|
392
|
-
[
|
|
393
|
-
[
|
|
394
|
-
[
|
|
395
|
-
[
|
|
396
|
-
[
|
|
397
|
-
[
|
|
398
|
-
[
|
|
399
|
-
[
|
|
400
|
-
[
|
|
401
|
-
[
|
|
402
|
-
[
|
|
403
|
-
[
|
|
404
|
-
[
|
|
328
|
+
[new RegExp(":", "v"), "Colon"],
|
|
329
|
+
[new RegExp("\\u{0000}", "v"), "Null"],
|
|
330
|
+
[new RegExp("\\u{0001}", "v"), "Start of Heading"],
|
|
331
|
+
[new RegExp("\\u{0002}", "v"), "Start of Text"],
|
|
332
|
+
[new RegExp("\\u{0003}", "v"), "End of Text"],
|
|
333
|
+
[new RegExp("\\u{0004}", "v"), "End of Transmission"],
|
|
334
|
+
[new RegExp("\\u{0005}", "v"), "Enquiry"],
|
|
335
|
+
[new RegExp("\\u{0006}", "v"), "Acknowledge"],
|
|
336
|
+
[new RegExp("\\u{0007}", "v"), "Bell"],
|
|
337
|
+
[new RegExp("\\u{0008}", "v"), "Backspace"],
|
|
338
|
+
[new RegExp("\\u{0009}", "v"), "Horizontal Tab"],
|
|
339
|
+
[new RegExp("\\u{000A}", "v"), "Line Feed"],
|
|
340
|
+
[new RegExp("\\u{000B}", "v"), "Vertical Tab"],
|
|
341
|
+
[new RegExp("\\u{000C}", "v"), "Form Feed"],
|
|
342
|
+
[new RegExp("\\u{000D}", "v"), "Carriage Return"],
|
|
343
|
+
[new RegExp("\\u{000E}", "v"), "Shift Out"],
|
|
344
|
+
[new RegExp("\\u{000F}", "v"), "Shift In"],
|
|
345
|
+
[new RegExp("\\u{0010}", "v"), "Data Link Escape"],
|
|
346
|
+
[new RegExp("\\u{0011}", "v"), "Device Control 1"],
|
|
347
|
+
[new RegExp("\\u{0012}", "v"), "Device Control 2"],
|
|
348
|
+
[new RegExp("\\u{0013}", "v"), "Device Control 3"],
|
|
349
|
+
[new RegExp("\\u{0014}", "v"), "Device Control 4"],
|
|
350
|
+
[new RegExp("\\u{0015}", "v"), "Negative Acknowledge"],
|
|
351
|
+
[new RegExp("\\u{0016}", "v"), "Synchronous Idle"],
|
|
352
|
+
[new RegExp("\\u{0017}", "v"), "End of Transmission Block"],
|
|
353
|
+
[new RegExp("\\u{0018}", "v"), "Cancel"],
|
|
354
|
+
[new RegExp("\\u{0019}", "v"), "End of Medium"],
|
|
355
|
+
[new RegExp("\\u{001A}", "v"), "Substitute"],
|
|
356
|
+
[new RegExp("\\u{001B}", "v"), "Escape"],
|
|
357
|
+
[new RegExp("\\u{001C}", "v"), "File Separator"],
|
|
358
|
+
[new RegExp("\\u{001D}", "v"), "Group Separator"],
|
|
359
|
+
[new RegExp("\\u{001E}", "v"), "Record Separator"],
|
|
360
|
+
[new RegExp("\\u{001F}", "v"), "Unit Separator"],
|
|
361
|
+
[new RegExp("\\u{007F}", "v"), "Delete"],
|
|
362
|
+
[new RegExp("\\u{0080}", "v"), "Padding Character"],
|
|
363
|
+
[new RegExp("\\u{0081}", "v"), "High Octet Preset"],
|
|
364
|
+
[new RegExp("\\u{0082}", "v"), "Break Permitted Here"],
|
|
365
|
+
[new RegExp("\\u{0083}", "v"), "No Break Here"],
|
|
366
|
+
[new RegExp("\\u{0084}", "v"), "Index"],
|
|
367
|
+
[new RegExp("\\u{0085}", "v"), "Next Line"],
|
|
368
|
+
[new RegExp("\\u{0086}", "v"), "Start of Selected Area"],
|
|
369
|
+
[new RegExp("\\u{0087}", "v"), "End of Selected Area"],
|
|
370
|
+
[new RegExp("\\u{0088}", "v"), "Character Tabulation Set"],
|
|
371
|
+
[new RegExp("\\u{0089}", "v"), "Character Tabulation with Justification"],
|
|
372
|
+
[new RegExp("\\u{008A}", "v"), "Line Tabulation Set"],
|
|
373
|
+
[new RegExp("\\u{008B}", "v"), "Partial Line Forward"],
|
|
374
|
+
[new RegExp("\\u{008C}", "v"), "Partial Line Backward"],
|
|
375
|
+
[new RegExp("\\u{008D}", "v"), "Reverse Line Feed"],
|
|
376
|
+
[new RegExp("\\u{008E}", "v"), "Single Shift Two"],
|
|
377
|
+
[new RegExp("\\u{008F}", "v"), "Single Shift Three"],
|
|
378
|
+
[new RegExp("\\u{0090}", "v"), "Device Control String"],
|
|
379
|
+
[new RegExp("\\u{0091}", "v"), "Private Use One"],
|
|
380
|
+
[new RegExp("\\u{0092}", "v"), "Private Use Two"],
|
|
381
|
+
[new RegExp("\\u{0093}", "v"), "Set Transmit State"],
|
|
382
|
+
[new RegExp("\\u{0094}", "v"), "Cancel Character"],
|
|
383
|
+
[new RegExp("\\u{0095}", "v"), "Message Waiting"],
|
|
384
|
+
[new RegExp("\\u{0096}", "v"), "Start of Protected Area"],
|
|
385
|
+
[new RegExp("\\u{0097}", "v"), "End of Protected Area"],
|
|
386
|
+
[new RegExp("\\u{0098}", "v"), "Start of String"],
|
|
387
|
+
[new RegExp("\\u{0099}", "v"), "Single Graphic Character Introducer"],
|
|
388
|
+
[new RegExp("\\u{009A}", "v"), "Single Character Introducer"],
|
|
389
|
+
[new RegExp("\\u{009B}", "v"), "Control Sequence Introducer"],
|
|
390
|
+
[new RegExp("\\u{009C}", "v"), "String Terminator"],
|
|
391
|
+
[new RegExp("\\u{009D}", "v"), "Operating System Command"],
|
|
392
|
+
[new RegExp("\\u{009E}", "v"), "Privacy Message"],
|
|
393
|
+
[new RegExp("\\u{009F}", "v"), "Application Program Command"],
|
|
394
|
+
[new RegExp("\\u{00A0}", "v"), "Non-breaking Space"],
|
|
395
|
+
[new RegExp("\\u{00AD}", "v"), "Soft Hyphen"],
|
|
396
|
+
[new RegExp("\\u{200B}", "v"), "Zero-width Space"],
|
|
397
|
+
[new RegExp("\\u{200C}", "v"), "Zero-width Non-joiner"],
|
|
398
|
+
[new RegExp("\\u{200D}", "v"), "Zero-width Joiner"],
|
|
399
|
+
[new RegExp("\\u{200E}", "v"), "Left-to-right Mark"],
|
|
400
|
+
[new RegExp("\\u{200F}", "v"), "Right-to-left Mark"],
|
|
401
|
+
[new RegExp("\\u{202A}", "v"), "Left-to-right Embedding"],
|
|
402
|
+
[new RegExp("\\u{202B}", "v"), "Right-to-left Embedding"],
|
|
403
|
+
[new RegExp("\\u{202C}", "v"), "Pop Directional Formatting"],
|
|
404
|
+
[new RegExp("\\u{202D}", "v"), "Left-to-right Override"],
|
|
405
|
+
[new RegExp("\\u{202E}", "v"), "Right-to-left Override"],
|
|
406
|
+
[new RegExp("\\u{FEFF}", "v"), "Byte Order Mark (BOM)"]
|
|
405
407
|
];
|
|
406
408
|
/**
|
|
407
409
|
* Convenience
|
|
@@ -508,8 +510,8 @@ function getFileExtensionForMimeType(mimeType) {
|
|
|
508
510
|
}
|
|
509
511
|
//#endregion
|
|
510
512
|
//#region src/lib/utilities/path.ts
|
|
511
|
-
const WINDOWS_DRIVE_LETTER_REGEX =
|
|
512
|
-
const QUERY_FRAGMENT_START_REGEX =
|
|
513
|
+
const WINDOWS_DRIVE_LETTER_REGEX = new RegExp("^[A-Z]:", "iv");
|
|
514
|
+
const QUERY_FRAGMENT_START_REGEX = new RegExp("[#^]", "v");
|
|
513
515
|
/**
|
|
514
516
|
* The browserify polyfill doesn't implement win32 absolute path detection...
|
|
515
517
|
*
|
|
@@ -520,7 +522,7 @@ const QUERY_FRAGMENT_START_REGEX = /* @__PURE__ */ new RegExp("[#^]", "v");
|
|
|
520
522
|
function isAbsolute(filePath) {
|
|
521
523
|
return isAbsolutePath.posix(filePath) || isAbsolutePath.win32(filePath);
|
|
522
524
|
}
|
|
523
|
-
const RE_WINDOWS_EXTENDED_LENGTH_PATH =
|
|
525
|
+
const RE_WINDOWS_EXTENDED_LENGTH_PATH = new RegExp("^\\\\\\\\\\?\\\\.+", "v");
|
|
524
526
|
/**
|
|
525
527
|
* Converts all paths to cross-platform 'mixed' style with forward slashes.
|
|
526
528
|
* Warns on unsupported Windows extended length paths.
|
|
@@ -607,8 +609,8 @@ function getQuery(filePath) {
|
|
|
607
609
|
}
|
|
608
610
|
//#endregion
|
|
609
611
|
//#region src/lib/utilities/url.ts
|
|
610
|
-
const DRIVE_LETTER_REGEX =
|
|
611
|
-
const FILE_PREFIX_REGEX =
|
|
612
|
+
const DRIVE_LETTER_REGEX = new RegExp("^[a-z]:", "iv");
|
|
613
|
+
const FILE_PREFIX_REGEX = new RegExp("^file:", "iv");
|
|
612
614
|
function safeDecodeURI(text) {
|
|
613
615
|
try {
|
|
614
616
|
return decodeURI(text);
|
|
@@ -724,7 +726,7 @@ async function getUrlContentHash(url, fetchAdapter, mode = MEDIA_DEFAULT_HASH_MO
|
|
|
724
726
|
"content-length"
|
|
725
727
|
]);
|
|
726
728
|
if (stringToHash === void 0) throw new Error("No headers found");
|
|
727
|
-
return getHash(stringToHash
|
|
729
|
+
return getHash(`${url}${stringToHash}`, 16);
|
|
728
730
|
} catch {}
|
|
729
731
|
return getHash(url, 16);
|
|
730
732
|
}
|
|
@@ -788,7 +790,7 @@ async function getContentHash(absolutePathOrUrl, fileAdapter, fetchAdapter) {
|
|
|
788
790
|
}
|
|
789
791
|
//#endregion
|
|
790
792
|
//#region src/lib/parse/rehype-mathjax-anki.ts
|
|
791
|
-
const CONSECUTIVE_BRACES_REGEX =
|
|
793
|
+
const CONSECUTIVE_BRACES_REGEX = new RegExp("([\\{\\}])(?=[\\{\\}])", "gv");
|
|
792
794
|
function sanitizeBraces(value) {
|
|
793
795
|
return value.replaceAll(CONSECUTIVE_BRACES_REGEX, "$1 ");
|
|
794
796
|
}
|
|
@@ -842,7 +844,7 @@ const plugin$2 = function() {
|
|
|
842
844
|
};
|
|
843
845
|
//#endregion
|
|
844
846
|
//#region src/lib/parse/rehype-utilities.ts
|
|
845
|
-
const DIMENSION_CHARS_REGEX =
|
|
847
|
+
const DIMENSION_CHARS_REGEX = new RegExp("^[\\dx]+$", "v");
|
|
846
848
|
const highlighter = createHighlighterCoreSync({
|
|
847
849
|
engine: createJavaScriptRegexEngine(),
|
|
848
850
|
langs: [
|
|
@@ -918,9 +920,7 @@ async function mdastToHtml(mdast, options) {
|
|
|
918
920
|
case "localFileUrl":
|
|
919
921
|
absolutePathOrUrl = node.properties.src;
|
|
920
922
|
break;
|
|
921
|
-
case "remoteHttpUrl":
|
|
922
|
-
absolutePathOrUrl = node.properties.src;
|
|
923
|
-
break;
|
|
923
|
+
case "remoteHttpUrl": absolutePathOrUrl = node.properties.src;
|
|
924
924
|
}
|
|
925
925
|
treeMutationPromises.push(async () => {
|
|
926
926
|
const extension = await getAnkiMediaFilenameExtension(absolutePathOrUrl, srcType === "obsidianVaultUrl" ? void 0 : fetchAdapter);
|
|
@@ -1208,17 +1208,18 @@ async function addNote(client, note, dryRun, fileAdapter) {
|
|
|
1208
1208
|
options: { allowDuplicate: true }
|
|
1209
1209
|
} }) ?? void 0;
|
|
1210
1210
|
} catch (error) {
|
|
1211
|
-
if (error instanceof Error)
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
if (
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1211
|
+
if (error instanceof Error) {
|
|
1212
|
+
if (error.message === `model was not found: ${note.modelName}`) {
|
|
1213
|
+
const model = yankiModels.find((model) => model.modelName === note.modelName);
|
|
1214
|
+
if (model === void 0) throw new Error(`Model not found: ${note.modelName}`, { cause: error });
|
|
1215
|
+
await ensureModelExists(client, model);
|
|
1216
|
+
newNote = await addNote(client, note, dryRun, fileAdapter);
|
|
1217
|
+
} else if (error.message === `deck was not found: ${note.deckName}`) {
|
|
1218
|
+
if (note.deckName === "") throw new Error("Deck name is empty", { cause: error });
|
|
1219
|
+
await client.deck.createDeck({ deck: note.deckName });
|
|
1220
|
+
newNote = await addNote(client, note, dryRun, fileAdapter);
|
|
1221
|
+
} else throw error;
|
|
1222
|
+
} else throw new TypeError("Unknown error", { cause: error });
|
|
1222
1223
|
}
|
|
1223
1224
|
if (newNote === void 0) throw new Error("Note creation failed");
|
|
1224
1225
|
await uploadMediaForNote(client, note, dryRun, fileAdapter);
|
|
@@ -1256,13 +1257,14 @@ async function updateNote(client, localNote, remoteNote, dryRun, fileAdapter) {
|
|
|
1256
1257
|
tags: localNote.tags ?? []
|
|
1257
1258
|
} });
|
|
1258
1259
|
} catch (error) {
|
|
1259
|
-
if (error instanceof Error)
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1260
|
+
if (error instanceof Error) {
|
|
1261
|
+
if (error.message === `Model '${localNote.modelName}' not found`) {
|
|
1262
|
+
const model = yankiModels.find((model) => model.modelName === localNote.modelName);
|
|
1263
|
+
if (model === void 0) throw new Error(`Model not found: ${localNote.modelName}`, { cause: error });
|
|
1264
|
+
await ensureModelExists(client, model);
|
|
1265
|
+
await updateNote(client, localNote, remoteNote, dryRun, fileAdapter);
|
|
1266
|
+
} else throw error;
|
|
1267
|
+
} else throw new TypeError("Unknown error", { cause: error });
|
|
1266
1268
|
}
|
|
1267
1269
|
await uploadMediaForNote(client, localNote, dryRun, fileAdapter);
|
|
1268
1270
|
}
|
|
@@ -1690,8 +1692,8 @@ function formatListResult(result) {
|
|
|
1690
1692
|
}
|
|
1691
1693
|
//#endregion
|
|
1692
1694
|
//#region src/lib/utilities/filenames.ts
|
|
1693
|
-
const CLOZE_CONTENT_REGEX =
|
|
1694
|
-
const FILENAME_INCREMENT_SUFFIX_REGEX =
|
|
1695
|
+
const CLOZE_CONTENT_REGEX = new RegExp("\\{\\{\\w\\d*\\s?:{0,2}([^:\\}]+)", "v");
|
|
1696
|
+
const FILENAME_INCREMENT_SUFFIX_REGEX = new RegExp("\\s\\(\\d+\\)$", "v");
|
|
1695
1697
|
function getSafeTitleForNote(note, manageFilenames, maxLength) {
|
|
1696
1698
|
if (manageFilenames === "off") throw new Error("manageFilenames must not be off");
|
|
1697
1699
|
switch (note.modelName) {
|
|
@@ -1730,7 +1732,7 @@ function getSafeFilename(text, maxLength) {
|
|
|
1730
1732
|
let basicSafeFilename = filenamify(getFirstLineOfHtmlAsPlainText(text).trim(), {
|
|
1731
1733
|
maxLength: Number.MAX_SAFE_INTEGER,
|
|
1732
1734
|
replacement: " "
|
|
1733
|
-
}).replaceAll(
|
|
1735
|
+
}).replaceAll(new RegExp("\\s+", "gv"), " ").trim();
|
|
1734
1736
|
if (basicSafeFilename.length === 0) basicSafeFilename = MEDIA_DEFAULT_EMPTY_FILENAME;
|
|
1735
1737
|
basicSafeFilename = basicSafeFilename.normalize("NFC");
|
|
1736
1738
|
if (maxLength === void 0) return basicSafeFilename;
|
|
@@ -1773,7 +1775,7 @@ function getTemporarilyUniqueFilePath(filePath) {
|
|
|
1773
1775
|
}
|
|
1774
1776
|
//#endregion
|
|
1775
1777
|
//#region src/lib/utilities/resolve-link.ts
|
|
1776
|
-
const MD_EXTENSION_REGEX =
|
|
1778
|
+
const MD_EXTENSION_REGEX = new RegExp("\\.md$", "v");
|
|
1777
1779
|
const defaultResolveLinkOptions = {
|
|
1778
1780
|
allFilePaths: [],
|
|
1779
1781
|
basePath: void 0,
|
|
@@ -2306,7 +2308,7 @@ const plugin = function() {
|
|
|
2306
2308
|
};
|
|
2307
2309
|
//#endregion
|
|
2308
2310
|
//#region src/lib/parse/remark-utilities.ts
|
|
2309
|
-
const CLOZE_NUMBER_PREFIX_REGEX =
|
|
2311
|
+
const CLOZE_NUMBER_PREFIX_REGEX = new RegExp("^[\\(\\|]?(\\d{1,2})(?:[\\s\\).\\|]|$)(.*)$", "v");
|
|
2310
2312
|
const defaultAstFromMarkdownOptions = { ...defaultGlobalOptions };
|
|
2311
2313
|
async function getAstFromMarkdown(markdown, options) {
|
|
2312
2314
|
const { allFilePaths, basePath, cwd, obsidianVault, resolveUrls } = deepmerge(defaultAstFromMarkdownOptions, options ?? {});
|
|
@@ -2863,7 +2865,7 @@ function formatSetStyleResult(result, verbose = false) {
|
|
|
2863
2865
|
}
|
|
2864
2866
|
//#endregion
|
|
2865
2867
|
//#region src/lib/model/frontmatter.ts
|
|
2866
|
-
const NEWLINE_REGEX =
|
|
2868
|
+
const NEWLINE_REGEX = new RegExp("\\r?\\n", "v");
|
|
2867
2869
|
/**
|
|
2868
2870
|
* Update the noteId in the frontmatter of a markdown string.
|
|
2869
2871
|
*
|
|
@@ -2891,7 +2893,8 @@ async function setNoteIdInFrontmatter(markdown, noteId) {
|
|
|
2891
2893
|
...lines
|
|
2892
2894
|
].join("\n");
|
|
2893
2895
|
}
|
|
2894
|
-
const
|
|
2896
|
+
const frontmatter = lines.slice(frontmatterStart + 1, frontmatterEnd).join("\n");
|
|
2897
|
+
const parsedFrontmatter = await parse(frontmatter) ?? {};
|
|
2895
2898
|
if (noteId === void 0) {
|
|
2896
2899
|
delete parsedFrontmatter.noteId;
|
|
2897
2900
|
if (Object.keys(parsedFrontmatter).length === 0) {
|
|
@@ -805,7 +805,7 @@ Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for
|
|
|
805
805
|
*/
|
|
806
806
|
type PartialObjectDeep<ObjectType extends object, Options extends Required<PartialDeepOptions>> = { [KeyType in keyof ObjectType]?: _PartialDeep<ObjectType[KeyType], Options>; };
|
|
807
807
|
//#endregion
|
|
808
|
-
//#region node_modules/.pnpm/yanki-connect@4.0.
|
|
808
|
+
//#region node_modules/.pnpm/yanki-connect@4.0.10/node_modules/yanki-connect/dist/index.d.ts
|
|
809
809
|
//#region src/types/deck.d.ts
|
|
810
810
|
type DeckStats = {
|
|
811
811
|
deck_id: number;
|