Extend markdown support for LBRY urls #2521

Merged
btzr-io merged 27 commits from smart-links into master 2019-06-26 07:23:39 +02:00
Showing only changes of commit b7c652b554 - Show all commits

View file

@ -5,41 +5,39 @@ const locateURI = (value, fromIndex) => value.indexOf(protocol, fromIndex);
const locateMention = (value, fromIndex) => value.indexOf('@', fromIndex);
// Generate a valid markdown link
const createURI = (text, uri, addProtocol = true) => ({
const createURI = (text, uri) => ({
type: 'link',
url: (addProtocol ? protocol : '') + uri,
url: (uri.startsWith(protocol) ? '' : protocol) + uri,
children: [{ type: 'text', value: text }],
});
const validateURI = (match) => {
if (match) {
try {
const text = match[0];
const uri = parseURI(text);
// Create channel link
if (uri.isChannel) {
return eat(text)(createURI(uri.claimName, text));
}
// Create uri link
return eat(text)(createURI(text, text));
} catch (err) {
// Silent errors: console.error(err)
}
}
}
// Generate a markdown link from channel name
function tokenizeMention(eat, value, silent) {
const match = /^@(\w+)/.exec(value);
if (match) {
const text = match[0];
const href = match[0];
return silent ? true : eat(text)(createURI(text, href));
}
return validateURI(match);
}
// Generate a markdown link from lbry url
function tokenizeURI(eat, value, silent) {
const match = /^(lbry:\/\/)+([A-z0-9-_#@])+/.exec(value);
if (match) {
try {
const text = match[0];
const uri = parseURI(text, true);
// Create channel link
if (uri.isChannel) {
return eat(text)(createURI(uri.claimName, uri.claimName));
}
// Create uri link
return eat(text)(createURI(text, text, false));
} catch (err) {
// Silent errors: console.error(err)
}
}
return validateURI(match);
}
// Configure tokenizer for lbry urls
neb-b commented 2019-06-12 17:31:49 +02:00 (Migrated from github.com)
Review

This should use regexValidUri and isValidUri() from lbry-redux

This should use `regexValidUri` and `isValidUri()` from `lbry-redux`
btzr-io commented 2019-06-13 07:21:13 +02:00 (Migrated from github.com)
Review

I can't find regexValidUri, did you mean regexInvalidURI ?
https://github.com/lbryio/lbry-redux/blob/master/src/lbryURI.js#L5

I can't find `regexValidUri`, did you mean `regexInvalidURI` ? https://github.com/lbryio/lbry-redux/blob/master/src/lbryURI.js#L5
btzr-io commented 2019-06-13 08:26:41 +02:00 (Migrated from github.com)
Review
this? https://github.com/lbryio/lbry-redux/blob/master/src/lbryURI.js#L32
neb-b commented 2019-06-17 18:18:52 +02:00 (Migrated from github.com)
Review

whoops. yes

whoops. yes
btzr-io commented 2019-06-20 23:29:07 +02:00 (Migrated from github.com)
Review

@seanyesmunt not sure how this is done on reach-ui tooltip 🙃

I mean the delay time to show / hide.

@seanyesmunt not sure how this is done on reach-ui tooltip :upside_down_face: I mean the delay time to show / hide.
btzr-io commented 2019-06-21 03:34:55 +02:00 (Migrated from github.com)
Review

this is are already implemented inside parseURI:
b7adc597e2/src/ui/util/remark-lbry.js (L23)

this is are already implemented inside `parseURI`: https://github.com/lbryio/lbry-desktop/blob/b7adc597e232f95dea200a6f49bf5d17c1af102c/src/ui/util/remark-lbry.js#L23