1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-21 19:37:28 +00:00

optimize md render

This commit is contained in:
shanshuirenjia
2021-04-27 11:22:55 +08:00
parent 3cf4838f98
commit e9d1ea9ed6
2 changed files with 33 additions and 39 deletions

View File

@@ -205,7 +205,7 @@ class IndexContentViewer extends React.Component {
const textNode = linkNode.children[0]; const textNode = linkNode.children[0];
let name = textNode ? textNode.text : ''; let name = textNode ? textNode.text : '';
treeNode = new TreeNode({ name: name, href: linkNode.data.href }); treeNode = new TreeNode({ name: name, href: linkNode.data.href });
} else if (paragraphNode.children[0].object === 'text') { } else if (paragraphNode.children[0]) {
// paragraph first child node is a text node, then get node name // paragraph first child node is a text node, then get node name
const textNode = paragraphNode.children[0]; const textNode = paragraphNode.children[0];
let name = textNode.text ? textNode.text : ''; let name = textNode.text ? textNode.text : '';

View File

@@ -133,49 +133,43 @@ class WikiMarkdownViewer extends React.Component {
} }
changeInlineNode = (item) => { changeInlineNode = (item) => {
if (item.object == 'inline') { let url, imagePath;
let url, imagePath;
// change image url // change image url
if (item.type == 'image' && isPublicWiki) { if (item.type == 'image' && isPublicWiki) {
url = item.data.src; url = item.data.src;
const re = new RegExp(serviceURL + '/lib/' + repoID +'/file.*raw=1'); const re = new RegExp(serviceURL + '/lib/' + repoID +'/file.*raw=1');
// different repo // different repo
if (re.test(url)) { if (re.test(url)) {
// get image path // get image path
let index = url.indexOf('/file'); let index = url.indexOf('/file');
let index2 = url.indexOf('?'); let index2 = url.indexOf('?');
imagePath = url.substring(index + 5, index2); imagePath = url.substring(index + 5, index2);
} else if (/^\.\.\/*/.test(url) || /^\.\/*/.test(url)) { } else if (/^\.\.\/*/.test(url) || /^\.\/*/.test(url)) {
const path = this.props.path; const path = this.props.path;
const originalPath = path.slice(0, path.lastIndexOf('/')) + '/' + url; const originalPath = path.slice(0, path.lastIndexOf('/')) + '/' + url;
imagePath = Utils.pathNormalize(originalPath); imagePath = Utils.pathNormalize(originalPath);
} else { } else {
return; return;
}
item.data.src = serviceURL + '/view-image-via-public-wiki/?slug=' + slug + '&path=' + imagePath;
} }
item.data.src = serviceURL + '/view-image-via-public-wiki/?slug=' + slug + '&path=' + imagePath;
else if (item.type == 'link') { } else if (item.type == 'link') {
url = item.data.href; url = item.data.href;
// change file url console.log(Utils.isInternalFileLink(url, repoID));
if (Utils.isInternalFileLink(url, repoID)) { if (Utils.isInternalFileLink(url, repoID)) { // change file url
if (Utils.isInternalMarkdownLink(url, repoID)) { if (Utils.isInternalMarkdownLink(url, repoID)) {
let path = Utils.getPathFromInternalMarkdownLink(url, repoID); let path = Utils.getPathFromInternalMarkdownLink(url, repoID);
// replace url
item.data.href = serviceURL + '/published/' + slug + path;
} else {
item.data.href = url.replace(/(.*)lib\/([-0-9a-f]{36})\/file(.*)/g, (match, p1, p2, p3) => {
return `${p1}d/${sharedToken}/files/?p=${p3}&dl=1`;
});
}
}
// change dir url
else if (Utils.isInternalDirLink(url, repoID)) {
let path = Utils.getPathFromInternalDirLink(url, repoID);
// replace url // replace url
item.data.href = serviceURL + '/published/' + slug + path; item.data.href = serviceURL + '/published/' + slug + path;
} else {
item.data.href = url.replace(/(.*)lib\/([-0-9a-f]{36})\/file(.*)/g, (match, p1, p2, p3) => {
return `${p1}d/${sharedToken}/files/?p=${p3}&dl=1`;
});
} }
} else if (Utils.isInternalDirLink(url, repoID)) { // change dir url
let path = Utils.getPathFromInternalDirLink(url, repoID);
// replace url
item.data.href = serviceURL + '/published/' + slug + path;
} }
} }