continue markdown (thats primary for other projects right now)
This commit is contained in:
parent
cd485f4259
commit
edfd16d3ae
|
@ -3,34 +3,6 @@
|
||||||
*/
|
*/
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
/*
|
|
||||||
* gets a descriptive text of the domain of the link
|
|
||||||
* Example:
|
|
||||||
* https://www.youtube.com/watch?v=G8APgeFfkAk returns 'youtube'
|
|
||||||
* http://www.google.at returns 'google.at'
|
|
||||||
* (www. and .com are split)
|
|
||||||
*/
|
|
||||||
function getLinkDesc(link) {
|
|
||||||
let domainStart = link.indexOf('://') + 3;
|
|
||||||
if (domainStart < 3) {
|
|
||||||
domainStart = 0;
|
|
||||||
}
|
|
||||||
if (link.startsWith('www.', domainStart)) {
|
|
||||||
domainStart += 4;
|
|
||||||
}
|
|
||||||
let domainEnd = link.indexOf('/', domainStart);
|
|
||||||
if (domainEnd === -1) {
|
|
||||||
domainEnd = link.length;
|
|
||||||
}
|
|
||||||
if (link.endsWith('.com', domainEnd)) {
|
|
||||||
domainEnd -= 4;
|
|
||||||
}
|
|
||||||
if (domainEnd <= domainStart) {
|
|
||||||
return link;
|
|
||||||
}
|
|
||||||
return link.slice(domainStart, domainEnd);
|
|
||||||
}
|
|
||||||
|
|
||||||
const MarkdownParagraph = ({ pArray }) => pArray.map((part) => {
|
const MarkdownParagraph = ({ pArray }) => pArray.map((part) => {
|
||||||
if (!Array.isArray(part)) {
|
if (!Array.isArray(part)) {
|
||||||
return part;
|
return part;
|
||||||
|
|
61
utils/markdown-test/MdLink.jsx
Normal file
61
utils/markdown-test/MdLink.jsx
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* Renders a markdown link
|
||||||
|
* Also provides previews
|
||||||
|
* Links are assumed to start with protocol (http:// etc.)
|
||||||
|
*/
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
/*
|
||||||
|
* gets a descriptive text of the domain of the link
|
||||||
|
* Example:
|
||||||
|
* https://www.youtube.com/watch?v=G8APgeFfkAk returns 'youtube'
|
||||||
|
* http://www.google.at returns 'google.at'
|
||||||
|
* (www. and .com are split)
|
||||||
|
*/
|
||||||
|
function getLinkDesc(link) {
|
||||||
|
let domainStart = link.indexOf('://') + 3;
|
||||||
|
if (domainStart < 3) {
|
||||||
|
domainStart = 0;
|
||||||
|
}
|
||||||
|
if (link.startsWith('www.', domainStart)) {
|
||||||
|
domainStart += 4;
|
||||||
|
}
|
||||||
|
let domainEnd = link.indexOf('/', domainStart);
|
||||||
|
if (domainEnd === -1) {
|
||||||
|
domainEnd = link.length;
|
||||||
|
}
|
||||||
|
if (link.endsWith('.com', domainEnd)) {
|
||||||
|
domainEnd -= 4;
|
||||||
|
}
|
||||||
|
if (domainEnd <= domainStart) {
|
||||||
|
return link;
|
||||||
|
}
|
||||||
|
return link.slice(domainStart, domainEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* try to get extension out of link
|
||||||
|
*/
|
||||||
|
function getExt(link) {
|
||||||
|
let paramStart = link.indexOf('&');
|
||||||
|
if (paramStart === -1) {
|
||||||
|
paramStart = link.length;
|
||||||
|
}
|
||||||
|
let posDot = paramStart - 1;
|
||||||
|
for (;posDot >= 0 && link[posDot] !== '.'; posDot -= 1) {
|
||||||
|
if (link[posDot] === '/') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (paramStart - posDot > 4) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return link.slice(posDot, paramStart);
|
||||||
|
}
|
||||||
|
|
||||||
|
const MdLink = ({ href, title, type }) => {
|
||||||
|
const desc = getLinkDesc(href);
|
||||||
|
<div className="link">
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Reace.memo(MdLink);
|
Loading…
Reference in New Issue
Block a user