|
@@ -40,6 +40,7 @@ class LinkEditModal extends React.PureComponent {
|
|
|
this.show = this.show.bind(this);
|
|
this.show = this.show.bind(this);
|
|
|
this.hide = this.hide.bind(this);
|
|
this.hide = this.hide.bind(this);
|
|
|
this.cancel = this.cancel.bind(this);
|
|
this.cancel = this.cancel.bind(this);
|
|
|
|
|
+ this.parseMakdownLink = this.parseMakdownLink.bind(this);
|
|
|
this.handleChangeLinkInput = this.handleChangeLinkInput.bind(this);
|
|
this.handleChangeLinkInput = this.handleChangeLinkInput.bind(this);
|
|
|
this.handleChangeLabelInput = this.handleChangeLabelInput.bind(this);
|
|
this.handleChangeLabelInput = this.handleChangeLabelInput.bind(this);
|
|
|
this.handleChangeTypeahead = this.handleChangeTypeahead.bind(this);
|
|
this.handleChangeTypeahead = this.handleChangeTypeahead.bind(this);
|
|
@@ -61,31 +62,47 @@ class LinkEditModal extends React.PureComponent {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
show(defaultMarkdownLink = '') {
|
|
show(defaultMarkdownLink = '') {
|
|
|
- let labelInputValue = defaultMarkdownLink;
|
|
|
|
|
|
|
+ const { labelInputValue, linkInputValue, linkerType } = this.parseMakdownLink(defaultMarkdownLink);
|
|
|
|
|
+
|
|
|
|
|
+ this.setState({
|
|
|
|
|
+ show: true,
|
|
|
|
|
+ labelInputValue,
|
|
|
|
|
+ linkInputValue,
|
|
|
|
|
+ linkerType,
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ parseMakdownLink(MarkdownLink) {
|
|
|
|
|
+ let labelInputValue = MarkdownLink;
|
|
|
let linkInputValue = '';
|
|
let linkInputValue = '';
|
|
|
let linkerType = 'mdLink';
|
|
let linkerType = 'mdLink';
|
|
|
|
|
|
|
|
- if (defaultMarkdownLink.match(/^\[\[.*\]\]$/) && this.isApplyPukiwikiLikeLinkerPlugin) {
|
|
|
|
|
|
|
+ if (MarkdownLink.match(/^\[\[.*\]\]$/)) {
|
|
|
|
|
+ // if (MarkdownLink.match(/^\[\[.*\]\]$/) && this.isApplyPukiwikiLikeLinkerPlugin) {
|
|
|
linkerType = 'pukiwikiLink';
|
|
linkerType = 'pukiwikiLink';
|
|
|
- labelInputValue = 'pukilabel';
|
|
|
|
|
- linkInputValue = 'pukilink';
|
|
|
|
|
|
|
+ const value = MarkdownLink.slice(2, -2);
|
|
|
|
|
+ const indexOfSplit = value.lastIndexOf('>');
|
|
|
|
|
+ if (indexOfSplit < 0) {
|
|
|
|
|
+ labelInputValue = value;
|
|
|
|
|
+ linkInputValue = value;
|
|
|
|
|
+ }
|
|
|
|
|
+ labelInputValue = value.slice(0, indexOfSplit);
|
|
|
|
|
+ linkInputValue = value.slice(indexOfSplit + 1);
|
|
|
}
|
|
}
|
|
|
- else if (defaultMarkdownLink.match(/^\[\/.*\]$/)) {
|
|
|
|
|
|
|
+ else if (MarkdownLink.match(/^\[\/.*\]$/)) {
|
|
|
linkerType = 'growiLink';
|
|
linkerType = 'growiLink';
|
|
|
- labelInputValue = 'growilabel';
|
|
|
|
|
- linkInputValue = 'growilink';
|
|
|
|
|
|
|
+ const value = MarkdownLink.slice(1, -1);
|
|
|
|
|
+ labelInputValue = value;
|
|
|
|
|
+ linkInputValue = value;
|
|
|
}
|
|
}
|
|
|
- else if (defaultMarkdownLink.match(/^\[.*\]\(.*\)$/)) {
|
|
|
|
|
- labelInputValue = 'mdlabel';
|
|
|
|
|
- linkInputValue = 'mdlink';
|
|
|
|
|
|
|
+ else if (MarkdownLink.match(/^\[.*\]\(.*\)$/)) {
|
|
|
|
|
+ const value = MarkdownLink.slice(1, -1);
|
|
|
|
|
+ const indexOfSplit = value.lastIndexOf('](');
|
|
|
|
|
+ labelInputValue = value.slice(0, indexOfSplit);
|
|
|
|
|
+ linkInputValue = value.slice(indexOfSplit + 2);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- this.setState({
|
|
|
|
|
- show: true,
|
|
|
|
|
- labelInputValue,
|
|
|
|
|
- linkInputValue,
|
|
|
|
|
- linkerType,
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ return { labelInputValue, linkInputValue, linkerType };
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
cancel() {
|
|
cancel() {
|
|
@@ -138,7 +155,6 @@ class LinkEditModal extends React.PureComponent {
|
|
|
if (page != null) {
|
|
if (page != null) {
|
|
|
this.handleChangeLinkInput(page.path);
|
|
this.handleChangeLinkInput(page.path);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
handleSelecteLinkerType(linkerType) {
|
|
handleSelecteLinkerType(linkerType) {
|
|
@@ -167,8 +183,7 @@ class LinkEditModal extends React.PureComponent {
|
|
|
markdown = res.page.revision.body;
|
|
markdown = res.page.revision.body;
|
|
|
permalink = `${window.location.origin}/${res.page.id}`;
|
|
permalink = `${window.location.origin}/${res.page.id}`;
|
|
|
isEnablePermanentLink = true;
|
|
isEnablePermanentLink = true;
|
|
|
- }
|
|
|
|
|
- catch (err) {
|
|
|
|
|
|
|
+ } catch (err) {
|
|
|
markdown = `<div class="alert alert-warning" role="alert"><strong>${err.message}</strong></div>`;
|
|
markdown = `<div class="alert alert-warning" role="alert"><strong>${err.message}</strong></div>`;
|
|
|
}
|
|
}
|
|
|
this.setState({ markdown, permalink, isEnablePermanentLink });
|
|
this.setState({ markdown, permalink, isEnablePermanentLink });
|
|
@@ -176,13 +191,7 @@ class LinkEditModal extends React.PureComponent {
|
|
|
|
|
|
|
|
generateLink() {
|
|
generateLink() {
|
|
|
const { pageContainer } = this.props;
|
|
const { pageContainer } = this.props;
|
|
|
- const {
|
|
|
|
|
- linkInputValue,
|
|
|
|
|
- labelInputValue,
|
|
|
|
|
- linkerType,
|
|
|
|
|
- isUseRelativePath,
|
|
|
|
|
- isUsePermanentLink,
|
|
|
|
|
- } = this.state;
|
|
|
|
|
|
|
+ const { linkInputValue, labelInputValue, linkerType, isUseRelativePath, isUsePermanentLink } = this.state;
|
|
|
|
|
|
|
|
let reshapedLink = linkInputValue;
|
|
let reshapedLink = linkInputValue;
|
|
|
|
|
|
|
@@ -320,7 +329,6 @@ class LinkEditModal extends React.PureComponent {
|
|
|
</Modal>
|
|
</Modal>
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
LinkEditModal.propTypes = {
|
|
LinkEditModal.propTypes = {
|