Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize markdown code #5860

Merged
merged 4 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions frontend/src/components/dir-view-mode/dir-column-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Utils } from '../../utils/utils';
import { gettext, siteRoot } from '../../utils/constants';
import { seafileAPI } from '../../utils/seafile-api';
import toaster from '../toast';
import WikiMarkdownViewer from '../wiki-markdown-viewer';
import SeafileMarkdownViewer from '../seafile-markdown-viewer';

const propTypes = {
path: PropTypes.string.isRequired,
Expand Down Expand Up @@ -70,7 +70,7 @@ class DirColumnFile extends React.Component {
);
}
return (
<WikiMarkdownViewer
<SeafileMarkdownViewer
isTOCShow={false}
isFileLoading={this.props.isFileLoading}
markdownContent={this.props.content}
Expand All @@ -93,7 +93,7 @@ class DirColumnFile extends React.Component {
</div>
}
</Fragment>
</WikiMarkdownViewer>
</SeafileMarkdownViewer>
);
}
}
Expand Down
167 changes: 0 additions & 167 deletions frontend/src/components/markdown-view/history-list.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import React from 'react';
import PropTypes from 'prop-types';
import { EXTERNAL_EVENTS, EventBus, MarkdownViewer } from '@seafile/seafile-editor';
import { gettext, isPublicWiki, mediaUrl, repoID, serviceURL, sharedToken, slug } from '../utils/constants';
import Loading from './loading';
import { Utils } from '../utils/utils';
import { gettext, mediaUrl, serviceURL, sharedToken, slug } from '../../utils/constants';
import { Utils } from '../../utils/utils';
import Loading from '../loading';

import './style.css';

const propTypes = {
isWiki: PropTypes.bool,
path: PropTypes.string,
repoID: PropTypes.string,
isTOCShow: PropTypes.bool,
children: PropTypes.object,
isFileLoading: PropTypes.bool.isRequired,
containerClassName: PropTypes.string,
markdownContent: PropTypes.string.isRequired,
latestContributor: PropTypes.string.isRequired,
lastModified: PropTypes.string.isRequired,
onLinkClick: PropTypes.func.isRequired,
isWiki: PropTypes.bool,
isTOCShow: PropTypes.bool,
// for dir-column-file component(import repoID is undefined)
repoID: PropTypes.string,
path: PropTypes.string,
};

const contentClass = 'wiki-page-content';

class WikiMarkdownViewer extends React.Component {
class SeafileMarkdownViewer extends React.Component {

constructor(props) {
super(props);
Expand All @@ -32,6 +32,7 @@ class WikiMarkdownViewer extends React.Component {
const eventBus = EventBus.getInstance();
this.unsubscribeLinkClick = eventBus.subscribe(EXTERNAL_EVENTS.ON_LINK_CLICK, this.onLinkClick);
}

componentWillUnmount() {
this.unsubscribeLinkClick();
}
Expand All @@ -50,9 +51,10 @@ class WikiMarkdownViewer extends React.Component {
};

changeInlineNode = (item) => {
const { repoID } = this.props;
let url, imagePath;

if (item.type == 'image' && isPublicWiki) { // change image url
// isPublicWiki: in the old version, only public wiki need replace image url
if (item.type == 'image') { // change image url
url = item.data.src;
const re = new RegExp(serviceURL + '/lib/' + repoID +'/file.*raw=1');
// different repo
Expand Down Expand Up @@ -113,10 +115,13 @@ class WikiMarkdownViewer extends React.Component {
if (this.props.isFileLoading) {
return <Loading />;
}
// In dir-column-file repoID is one of props, width is 100%; In wiki-viewer repoID is not props, width isn't 100%
let contentClassName = `${this.props.repoID ? contentClass + ' w-100' : contentClass}`;
const { isWiki, containerClassName = '' } = this.props;
const containerClass = `wiki-page-container ${containerClassName}`;
// In dir-column-file width is 100%;
// In wiki-viewer width isn't 100%
const contentClassName = `wiki-page-content ${!isWiki ? + 'w-100' : ''}`;
return (
<div ref={this.scrollRef} className="wiki-page-container">
<div ref={this.scrollRef} className={containerClass}>
<div className={contentClassName}>
{this.props.children}
{this.renderMarkdown()}
Expand All @@ -131,7 +136,7 @@ const defaultProps = {
isWiki: false,
};

WikiMarkdownViewer.propTypes = propTypes;
MarkdownViewer.defaultProps = defaultProps;
SeafileMarkdownViewer.propTypes = propTypes;
SeafileMarkdownViewer.defaultProps = defaultProps;

export default WikiMarkdownViewer;
export default SeafileMarkdownViewer;
25 changes: 25 additions & 0 deletions frontend/src/components/seafile-markdown-viewer/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.wiki-page-container .article {
margin: 0;
padding: 0 10px;
max-width: none;
border: none;
}

.wiki-page-container .article span[data-url] {
cursor: pointer;
}

.wiki-page-container .article .ml-2 {
text-decoration: underline;
}

.wiki-page-container .article .ml-2:hover {
text-decoration: underline;
color:#eb8205;
}

#wiki-page-last-modified {
padding: 40px 10px;
font-size:12px;
color: #666;
}
2 changes: 1 addition & 1 deletion frontend/src/components/toolbar/view-file-toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const propTypes = {
fileTags: PropTypes.array.isRequired,
onFileTagChanged: PropTypes.func.isRequired,
showShareBtn: PropTypes.bool.isRequired,
dirent: PropTypes.object.isRequired,
dirent: PropTypes.object,
};

class ViewFileToolbar extends React.Component {
Expand Down
4 changes: 0 additions & 4 deletions frontend/src/css/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@
z-index: -1;
}

.cur-view-content .article {
padding: 40px;
}

.cur-view-content .hd {
padding-bottom: 0;
margin-bottom: .5em;
Expand Down
Loading
Loading