diff options
author | Samy Pessé <samypesse@gmail.com> | 2017-01-06 17:15:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-06 17:15:30 +0100 |
commit | 7029c01806781f5ed74f175545ea154aa17cc6fd (patch) | |
tree | d87189690b5acc78acbd3d9688edc37b251541f3 /packages/gitbook-core/src/components | |
parent | 11893255d1167382b16871d2ca831c90a40af57d (diff) | |
download | gitbook-7029c01806781f5ed74f175545ea154aa17cc6fd.zip gitbook-7029c01806781f5ed74f175545ea154aa17cc6fd.tar.gz gitbook-7029c01806781f5ed74f175545ea154aa17cc6fd.tar.bz2 |
Switch to markup-it for parsing (#1659)
* Start new parsers in gitbook itself
* Update markup-it
* Fix eslint errors
* Adapt basic parsing for summary
* Start tests for summaryFromDocument
* Continue
* Add parsing of glossary
* Add back languages parsing
* Adapt most tests for parsing
* Adapt all tests 🙌
* Adapt travis tests
* Bootstrap lerna before running tests
* Fix lowercase in require (linux)
* Fix command gitbook init
* Fix generation of ready by init command
* Fix generation of summary
* Fix watch after serve
* Add trademark to sidebar
* Add back favicon to default theme
* Open trademark in new tab
Diffstat (limited to 'packages/gitbook-core/src/components')
-rw-r--r-- | packages/gitbook-core/src/components/Image.js | 37 | ||||
-rw-r--r-- | packages/gitbook-core/src/components/InjectedComponent.js | 2 | ||||
-rw-r--r-- | packages/gitbook-core/src/components/Link.js | 9 |
3 files changed, 47 insertions, 1 deletions
diff --git a/packages/gitbook-core/src/components/Image.js b/packages/gitbook-core/src/components/Image.js new file mode 100644 index 0000000..802d66a --- /dev/null +++ b/packages/gitbook-core/src/components/Image.js @@ -0,0 +1,37 @@ +const React = require('react'); +const ReactRedux = require('react-redux'); + +const File = require('../models/File'); +const FileShape = require('../propTypes/File'); + +/** + * Local image. Using this component instead of <img> + * avoid broken links when location changes. + * + * @type {ReactClass} + */ +const Image = React.createClass({ + propTypes: { + currentFile: FileShape, + src: React.PropTypes.oneOfType([ + React.PropTypes.string, + FileShape + ]) + }, + + render() { + let { src, currentFile, ...props } = this.props; + delete props.dispatch; + + if (File.is(src)) { + src = src.url; + } + + src = currentFile.relative(src); + return <img src={src} {...props} />; + } +}); + +module.exports = ReactRedux.connect((state) => { + return { currentFile: state.file }; +})(Image); diff --git a/packages/gitbook-core/src/components/InjectedComponent.js b/packages/gitbook-core/src/components/InjectedComponent.js index 097edaf..d237cd0 100644 --- a/packages/gitbook-core/src/components/InjectedComponent.js +++ b/packages/gitbook-core/src/components/InjectedComponent.js @@ -53,6 +53,8 @@ const InjectedComponentSet = React.createClass({ render() { const { components, props, children, ...divProps } = this.props; + delete divProps.matching; + delete divProps.dispatch; const inner = components.map((Comp, i) => <Injection key={i} component={Comp} props={props} />); diff --git a/packages/gitbook-core/src/components/Link.js b/packages/gitbook-core/src/components/Link.js index ab364bb..9827f0b 100644 --- a/packages/gitbook-core/src/components/Link.js +++ b/packages/gitbook-core/src/components/Link.js @@ -6,6 +6,12 @@ const SummaryArticle = require('../models/SummaryArticle'); const SummaryArticleShape = require('../propTypes/SummaryArticle'); const FileShape = require('../propTypes/File'); +/** + * Link to another page or file in the book. Using this component instead of <a> + * avoid broken links when location changes. + * + * @type {ReactClass} + */ const Link = React.createClass({ propTypes: { currentFile: FileShape, @@ -22,6 +28,7 @@ const Link = React.createClass({ render() { const { currentFile, to, children, ...props } = this.props; let href = to; + delete props.dispatch; if (SummaryArticle.is(to) || File.is(to)) { href = to.url; @@ -32,6 +39,6 @@ const Link = React.createClass({ } }); -module.exports = ReactRedux.connect(state => { +module.exports = ReactRedux.connect((state) => { return { currentFile: state.file }; })(Link); |