uniorg-parse
Advanced tools
Comparing version 0.1.7 to 0.1.9
@@ -1169,3 +1169,4 @@ "use strict"; | ||
parseLink() { | ||
var _a; | ||
// TODO: Special "file"-type link processing. Extract opening | ||
// application and search option, if any. Also normalize URI. | ||
const initialOffset = this.r.offset(); | ||
@@ -1184,5 +1185,20 @@ // TODO: Type 1: Text targeted from a radio target. | ||
} | ||
// TODO: Decode any encoding. Expand any abbreviation in it. | ||
const linkType = m.groups.link.match(/(.+?):(.*)/); | ||
return unist_builder_1.default('link', Object.assign({ format: 'bracket', linkType: (_a = linkType === null || linkType === void 0 ? void 0 : linkType[1]) !== null && _a !== void 0 ? _a : 'fuzzy', rawLink: m.groups.link, path: linkType ? linkType[2] : m.groups.link }, contents), []); | ||
// RAW-LINK is the original link. Decode any encoding. Expand | ||
// any abbreviation in it. | ||
// | ||
// Also treat any newline character and associated indentation | ||
// as a single space character. This is not compatible with RFC | ||
// 3986, which requires to ignore them altogether. However, | ||
// doing so would require users to encode spaces on the fly when | ||
// writing links (e.g., insert [[shell:ls%20*.org]] instead of | ||
// [[shell:ls *.org]], which defeats Org's focus on simplicity. | ||
const rawLink = m | ||
.groups.link.replace(/[ \t]*\n[ \t]*/m, ' ') | ||
// `org-link-unescape` | ||
.replace(/(\\+)([\[\]])/g, (p1, p2) => '\\'.repeat(p1.length / 2) + p2); | ||
// TODO: org-link-expand-abbrev | ||
const { linkType, path } = Parser.linkType(rawLink); | ||
return unist_builder_1.default('link', Object.assign({ format: 'bracket', linkType, | ||
rawLink, | ||
path }, contents), []); | ||
} | ||
@@ -1215,2 +1231,24 @@ // Type 3: Plain link, e.g., https://orgmode.org | ||
} | ||
static linkType(link) { | ||
// File type. | ||
if (link.startsWith('/') || link.match(/^\.\.?\//)) { | ||
return { linkType: 'file', path: link }; | ||
} | ||
// Explicit type (http, irc, bbdb...). | ||
const m = link.match(new RegExp(utils_1.linkTypesRe())); | ||
if (m) { | ||
return { linkType: m[1], path: link.slice(m[0].length) }; | ||
} | ||
// Code-ref type: `path` is the name of the reference. | ||
if (link.startsWith('(') && link.endsWith(')')) { | ||
return { linkType: 'coderef', path: link.slice(1, link.length - 1) }; | ||
} | ||
// Custom-id type: `path` is the name of the custom id. | ||
if (link.startsWith('#')) { | ||
return { linkType: 'custom-id', path: link.slice(1) }; | ||
} | ||
// Fuzzy type: Internal link either matches a target, a headline | ||
// name or nothing. `path` is the target or headline's name. | ||
return { linkType: 'fuzzy', path: link }; | ||
} | ||
parseTimestamp() { | ||
@@ -1217,0 +1255,0 @@ // org-ts--internal-regexp |
@@ -151,2 +151,6 @@ "use strict"; | ||
itParses('link with no text', `[[link]]`); | ||
itParses('./ as start of file link', `[[./file.org]]`); | ||
itParses('file link with spaces', `[[./file with spaces.org]]`); | ||
// note that these are actual percents in the file name, not a url-encoded "file with spaces.org" | ||
itParses('file link with percents', `[[./file%2Bwith%2Bspaces.org]]`); | ||
itParses('angle link', `<http://example.com>`); | ||
@@ -153,0 +157,0 @@ }); |
{ | ||
"name": "uniorg-parse", | ||
"version": "0.1.7", | ||
"version": "0.1.9", | ||
"description": "uniorg plugin to parse org-mode", | ||
@@ -49,3 +49,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "2e508539d6f6de5b941e76c89b566956d13bbc87" | ||
"gitHead": "00308db8127c9bd68ef6bb9550be0859153227a8" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
260377
3250