summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-core/src
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2017-01-06 17:15:30 +0100
committerGitHub <noreply@github.com>2017-01-06 17:15:30 +0100
commit7029c01806781f5ed74f175545ea154aa17cc6fd (patch)
treed87189690b5acc78acbd3d9688edc37b251541f3 /packages/gitbook-core/src
parent11893255d1167382b16871d2ca831c90a40af57d (diff)
downloadgitbook-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')
-rw-r--r--packages/gitbook-core/src/components/Image.js37
-rw-r--r--packages/gitbook-core/src/components/InjectedComponent.js2
-rw-r--r--packages/gitbook-core/src/components/Link.js9
-rw-r--r--packages/gitbook-core/src/index.js2
-rw-r--r--packages/gitbook-core/src/lib/renderWithContext.js2
-rw-r--r--packages/gitbook-core/src/models/Page.js2
6 files changed, 51 insertions, 3 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);
diff --git a/packages/gitbook-core/src/index.js b/packages/gitbook-core/src/index.js
index 3f0120c..5b92bc3 100644
--- a/packages/gitbook-core/src/index.js
+++ b/packages/gitbook-core/src/index.js
@@ -12,6 +12,7 @@ const { InjectedComponent, InjectedComponentSet } = require('./components/Inject
const { ImportLink, ImportScript, ImportCSS } = require('./components/Import');
const HTMLContent = require('./components/HTMLContent');
const Link = require('./components/Link');
+const Image = require('./components/Image');
const Icon = require('./components/Icon');
const HotKeys = require('./components/HotKeys');
const Button = require('./components/Button');
@@ -56,6 +57,7 @@ module.exports = {
FlexLayout: Flex,
FlexBox: Box,
Link,
+ Image,
Icon,
HotKeys,
Button,
diff --git a/packages/gitbook-core/src/lib/renderWithContext.js b/packages/gitbook-core/src/lib/renderWithContext.js
index dc7e1f2..70fba5c 100644
--- a/packages/gitbook-core/src/lib/renderWithContext.js
+++ b/packages/gitbook-core/src/lib/renderWithContext.js
@@ -5,7 +5,7 @@ const PJAXWrapper = require('../components/PJAXWrapper');
const I18nProvider = require('../components/I18nProvider');
const ContextProvider = require('../components/ContextProvider');
const History = require('../actions/history');
-const contextShape = require('../propTypes/context');
+const contextShape = require('../propTypes/Context');
const GitBookApplication = React.createClass({
propTypes: {
diff --git a/packages/gitbook-core/src/models/Page.js b/packages/gitbook-core/src/models/Page.js
index e3c4a96..5c5fdd8 100644
--- a/packages/gitbook-core/src/models/Page.js
+++ b/packages/gitbook-core/src/models/Page.js
@@ -12,7 +12,7 @@ const DEFAULTS = {
};
class Page extends Record(DEFAULTS) {
- static create(state) {
+ static create(state = {}) {
return state instanceof Page ?
state : new Page({
...state,