|
@@ -8,6 +8,7 @@ import {
|
|
|
ModalFooter,
|
|
ModalFooter,
|
|
|
} from 'reactstrap';
|
|
} from 'reactstrap';
|
|
|
|
|
|
|
|
|
|
+import path from 'path';
|
|
|
import Preview from './Preview';
|
|
import Preview from './Preview';
|
|
|
|
|
|
|
|
import AppContainer from '../../services/AppContainer';
|
|
import AppContainer from '../../services/AppContainer';
|
|
@@ -62,14 +63,20 @@ class LinkEditModal extends React.PureComponent {
|
|
|
// defaultMarkdownLink is an instance of Linker
|
|
// defaultMarkdownLink is an instance of Linker
|
|
|
show(defaultMarkdownLink = null) {
|
|
show(defaultMarkdownLink = null) {
|
|
|
// if defaultMarkdownLink is null, set default value in inputs.
|
|
// if defaultMarkdownLink is null, set default value in inputs.
|
|
|
- const { label = '', link = '' } = defaultMarkdownLink;
|
|
|
|
|
- let { type = Linker.types.markdownLink } = defaultMarkdownLink;
|
|
|
|
|
|
|
+ const { pageContainer } = this.props;
|
|
|
|
|
+ const { label = '' } = defaultMarkdownLink;
|
|
|
|
|
+ let { link = '', type = Linker.types.markdownLink } = defaultMarkdownLink;
|
|
|
|
|
|
|
|
// if type of defaultMarkdownLink is pukiwikiLink when pukiwikiLikeLinker plugin is disable, change type(not change label and link)
|
|
// if type of defaultMarkdownLink is pukiwikiLink when pukiwikiLikeLinker plugin is disable, change type(not change label and link)
|
|
|
if (type === Linker.types.pukiwikiLink && !this.isApplyPukiwikiLikeLinkerPlugin) {
|
|
if (type === Linker.types.pukiwikiLink && !this.isApplyPukiwikiLikeLinkerPlugin) {
|
|
|
type = Linker.types.markdownLink;
|
|
type = Linker.types.markdownLink;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ const isUseRelativePath = link.startsWith('.');
|
|
|
|
|
+ if (isUseRelativePath) {
|
|
|
|
|
+ link = path.resolve(pageContainer.state.path, link);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
this.setState({
|
|
this.setState({
|
|
|
show: true,
|
|
show: true,
|
|
|
labelInputValue: label,
|
|
labelInputValue: label,
|
|
@@ -77,6 +84,7 @@ class LinkEditModal extends React.PureComponent {
|
|
|
isUsePermanentLink: false,
|
|
isUsePermanentLink: false,
|
|
|
permalink: '',
|
|
permalink: '',
|
|
|
linkerType: type,
|
|
linkerType: type,
|
|
|
|
|
+ isUseRelativePath,
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -177,12 +185,15 @@ class LinkEditModal extends React.PureComponent {
|
|
|
permalink,
|
|
permalink,
|
|
|
} = this.state;
|
|
} = this.state;
|
|
|
|
|
|
|
|
|
|
+ let reshapedLink = linkInputValue;
|
|
|
|
|
+ if (isUseRelativePath && linkInputValue.match(/^\//)) {
|
|
|
|
|
+ reshapedLink = path.relative(pageContainer.state.path, linkInputValue);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return new Linker(
|
|
return new Linker(
|
|
|
linkerType,
|
|
linkerType,
|
|
|
labelInputValue,
|
|
labelInputValue,
|
|
|
- linkInputValue,
|
|
|
|
|
- isUseRelativePath,
|
|
|
|
|
- pageContainer.state.path,
|
|
|
|
|
|
|
+ reshapedLink,
|
|
|
isUsePermanentLink,
|
|
isUsePermanentLink,
|
|
|
permalink,
|
|
permalink,
|
|
|
);
|
|
);
|