Skip to content

Commit 7029c01

Browse files
authored
Switch to markup-it for parsing (GitbookIO#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
1 parent 1189325 commit 7029c01

File tree

211 files changed

+2795
-2130
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

211 files changed

+2795
-2130
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ node_js:
88
- "4.1"
99
before_install:
1010
- npm install svgexport -g
11+
before_script:
12+
- npm run bootstrap
1113
after_success:
1214
- npm run lint

package.json

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
{
22
"private": true,
33
"devDependencies": {
4-
"eslint": "3.4.0",
5-
"eslint-config-gitbook": "1.3.1",
6-
"expect": "^1.20.1",
7-
"lerna": "2.0.0-beta.31",
8-
"mocha": "^2.4.5"
4+
"eslint": "3.12.2",
5+
"eslint-config-gitbook": "1.5.0",
6+
"lerna": "2.0.0-beta.31"
97
},
108
"scripts": {
119
"lint": "eslint .",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const React = require('react');
2+
const ReactRedux = require('react-redux');
3+
4+
const File = require('../models/File');
5+
const FileShape = require('../propTypes/File');
6+
7+
/**
8+
* Local image. Using this component instead of <img>
9+
* avoid broken links when location changes.
10+
*
11+
* @type {ReactClass}
12+
*/
13+
const Image = React.createClass({
14+
propTypes: {
15+
currentFile: FileShape,
16+
src: React.PropTypes.oneOfType([
17+
React.PropTypes.string,
18+
FileShape
19+
])
20+
},
21+
22+
render() {
23+
let { src, currentFile, ...props } = this.props;
24+
delete props.dispatch;
25+
26+
if (File.is(src)) {
27+
src = src.url;
28+
}
29+
30+
src = currentFile.relative(src);
31+
return <img src={src} {...props} />;
32+
}
33+
});
34+
35+
module.exports = ReactRedux.connect((state) => {
36+
return { currentFile: state.file };
37+
})(Image);

packages/gitbook-core/src/components/InjectedComponent.js

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ const InjectedComponentSet = React.createClass({
5353

5454
render() {
5555
const { components, props, children, ...divProps } = this.props;
56+
delete divProps.matching;
57+
delete divProps.dispatch;
5658

5759
const inner = components.map((Comp, i) => <Injection key={i} component={Comp} props={props} />);
5860

packages/gitbook-core/src/components/Link.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ const SummaryArticle = require('../models/SummaryArticle');
66
const SummaryArticleShape = require('../propTypes/SummaryArticle');
77
const FileShape = require('../propTypes/File');
88

9+
/**
10+
* Link to another page or file in the book. Using this component instead of <a>
11+
* avoid broken links when location changes.
12+
*
13+
* @type {ReactClass}
14+
*/
915
const Link = React.createClass({
1016
propTypes: {
1117
currentFile: FileShape,
@@ -22,6 +28,7 @@ const Link = React.createClass({
2228
render() {
2329
const { currentFile, to, children, ...props } = this.props;
2430
let href = to;
31+
delete props.dispatch;
2532

2633
if (SummaryArticle.is(to) || File.is(to)) {
2734
href = to.url;
@@ -32,6 +39,6 @@ const Link = React.createClass({
3239
}
3340
});
3441

35-
module.exports = ReactRedux.connect(state => {
42+
module.exports = ReactRedux.connect((state) => {
3643
return { currentFile: state.file };
3744
})(Link);

packages/gitbook-core/src/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const { InjectedComponent, InjectedComponentSet } = require('./components/Inject
1212
const { ImportLink, ImportScript, ImportCSS } = require('./components/Import');
1313
const HTMLContent = require('./components/HTMLContent');
1414
const Link = require('./components/Link');
15+
const Image = require('./components/Image');
1516
const Icon = require('./components/Icon');
1617
const HotKeys = require('./components/HotKeys');
1718
const Button = require('./components/Button');
@@ -56,6 +57,7 @@ module.exports = {
5657
FlexLayout: Flex,
5758
FlexBox: Box,
5859
Link,
60+
Image,
5961
Icon,
6062
HotKeys,
6163
Button,

packages/gitbook-core/src/lib/renderWithContext.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const PJAXWrapper = require('../components/PJAXWrapper');
55
const I18nProvider = require('../components/I18nProvider');
66
const ContextProvider = require('../components/ContextProvider');
77
const History = require('../actions/history');
8-
const contextShape = require('../propTypes/context');
8+
const contextShape = require('../propTypes/Context');
99

1010
const GitBookApplication = React.createClass({
1111
propTypes: {

packages/gitbook-core/src/models/Page.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const DEFAULTS = {
1212
};
1313

1414
class Page extends Record(DEFAULTS) {
15-
static create(state) {
15+
static create(state = {}) {
1616
return state instanceof Page ?
1717
state : new Page({
1818
...state,
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
_assets
1+
_assets/**/*
2+
!_assets/website/images
Binary file not shown.
Loading

packages/gitbook-plugin-theme-default/less/Sidebar.less

+25
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,28 @@
2727
border-right: 1px solid @sidebar-border-color;
2828
overflow-y: auto;
2929
}
30+
31+
.GitBookTrademark {
32+
text-align: center;
33+
text-decoration: none;
34+
opacity: 0.1;
35+
margin-top: 80px;
36+
margin-bottom: 40px;
37+
color: #000;
38+
display: block;
39+
40+
&:hover {
41+
text-decoration: none;
42+
opacity: 0.2;
43+
}
44+
45+
span {
46+
display: block;
47+
}
48+
49+
img {
50+
max-width: 64px;
51+
filter: grayscale(100%);
52+
margin-top: 10px;
53+
}
54+
}

packages/gitbook-plugin-theme-default/src/components/Sidebar.js

+21
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,25 @@ const { React } = GitBook;
33

44
const Summary = require('./Summary');
55

6+
/**
7+
* The GitBook trademark.
8+
* @type {ReactClass}
9+
*/
10+
const GitBookTrademark = React.createClass({
11+
render() {
12+
return (
13+
<a className="GitBookTrademark" href="https://www.gitbook.com/?utm_source=gitbook&utm_medium=trademark" target="_blank">
14+
<span>Published with <b>GitBook</b></span>
15+
<GitBook.Image src="gitbook/theme-default/images/logo.svg" />
16+
</a>
17+
);
18+
}
19+
});
20+
21+
/**
22+
* Sidebar containing a serch bar, the table of contents, and the GitBook trademark.
23+
* @type {ReactClass}
24+
*/
625
const Sidebar = React.createClass({
726
propTypes: {
827
summary: GitBook.PropTypes.Summary
@@ -16,6 +35,8 @@ const Sidebar = React.createClass({
1635
<div className="Sidebar book-summary">
1736
<GitBook.InjectedComponent matching={{ role: 'search:container:input' }} />
1837
<Summary summary={summary} />
38+
39+
<GitBookTrademark />
1940
</div>
2041
</div>
2142
);

packages/gitbook-plugin-theme-default/src/components/Theme.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const LoadingBar = require('./LoadingBar');
88
const Theme = React.createClass({
99
propTypes: {
1010
// State
11+
file: GitBook.PropTypes.File,
1112
page: GitBook.PropTypes.Page,
1213
summary: GitBook.PropTypes.Summary,
1314
readme: GitBook.PropTypes.Readme,
@@ -18,14 +19,18 @@ const Theme = React.createClass({
1819
},
1920

2021
render() {
21-
const { page, summary, children, sidebar, readme, history } = this.props;
22+
const { file, page, summary, children, sidebar, readme, history } = this.props;
2223

2324
return (
2425
<GitBook.FlexLayout column className="GitBook book">
2526
<LoadingBar show={history.loading} />
2627
<GitBook.Head
2728
title={page.title}
28-
titleTemplate="%s - GitBook" />
29+
titleTemplate="%s - GitBook"
30+
link={[
31+
{rel: 'shortcut icon', href: file.relative('gitbook/theme-default/images/favicon.ico')}
32+
]}
33+
/>
2934
<GitBook.ImportCSS href="gitbook/theme-default/theme.css" />
3035

3136
<GitBook.FlexBox>
@@ -52,6 +57,6 @@ const Theme = React.createClass({
5257
}
5358
});
5459

55-
module.exports = GitBook.connect(Theme, ({page, summary, sidebar, readme, history}) => {
56-
return { page, summary, sidebar, readme, history };
60+
module.exports = GitBook.connect(Theme, ({file, page, summary, sidebar, readme, history}) => {
61+
return { file, page, summary, sidebar, readme, history };
5762
});

packages/gitbook-plugin/.babelrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["es2015", "stage-2"]
3+
}

packages/gitbook/package.json

+15-12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"main": "lib/index.js",
77
"browser": "./lib/browser.js",
88
"dependencies": {
9+
"asciidoctor.js": "^1.5.5-4",
910
"bash-color": "0.0.4",
1011
"cheerio": "0.20.0",
1112
"chokidar": "1.5.0",
@@ -21,9 +22,7 @@
2122
"extend": "^3.0.0",
2223
"fresh-require": "1.0.3",
2324
"front-matter": "^2.1.0",
24-
"gitbook-asciidoc": "1.2.2",
2525
"gitbook-core": "4.0.0",
26-
"gitbook-markdown": "1.3.2",
2726
"gitbook-plugin-copy-code": "4.0.0",
2827
"gitbook-plugin-headings": "4.0.0",
2928
"gitbook-plugin-highlight": "4.0.0",
@@ -44,6 +43,7 @@
4443
"json-schema-defaults": "0.1.1",
4544
"jsonschema": "1.1.0",
4645
"juice": "2.0.0",
46+
"markup-it": "3.3.0",
4747
"mkdirp": "0.5.1",
4848
"moment": "2.13.0",
4949
"npm": "3.10.9",
@@ -59,13 +59,24 @@
5959
"rmdir": "1.2.0",
6060
"semver": "5.1.0",
6161
"send": "0.13.2",
62+
"slate": "^0.16.8",
6263
"spawn-cmd": "0.0.2",
6364
"tiny-lr": "0.2.1",
6465
"tmp": "0.0.28",
6566
"urijs": "1.18.0"
6667
},
68+
"devDependencies": {
69+
"babel-cli": "^6.18.0",
70+
"babel-preset-es2015": "^6.18.0",
71+
"babel-preset-react": "^6.16.0",
72+
"babel-preset-stage-2": "^6.18.0",
73+
"babel-register": "^6.18.0",
74+
"expect": "^1.20.2",
75+
"mocha": "^3.2.0",
76+
"read-metadata": "^1.0.0"
77+
},
6778
"scripts": {
68-
"test": "./node_modules/.bin/mocha ./testing/setup.js \"./src/**/*/__tests__/*.js\" --bail --reporter=list --timeout=100000 --compilers js:babel-register",
79+
"test": "mocha ./testing/setup.js \"./src/**/*/__tests__/*.js\" --bail --reporter=list --timeout=100000 --compilers js:babel-register",
6980
"dist": "rm -rf lib/ && babel -d lib/ src/ --source-maps --ignore \"**/*/__tests__/*.js\"",
7081
"prepublish": "npm run dist"
7182
},
@@ -95,13 +106,5 @@
95106
"name": "Samy Pessé",
96107
"email": "[email protected]"
97108
}
98-
],
99-
"devDependencies": {
100-
"babel-cli": "^6.14.0",
101-
"babel-preset-es2015": "^6.14.0",
102-
"babel-preset-react": "^6.11.1",
103-
"babel-preset-stage-2": "^6.13.0",
104-
"babel-register": "^6.14.0",
105-
"mocha": "^3.0.2"
106-
}
109+
]
107110
}

packages/gitbook/src/__tests__/gitbook.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const gitbook = require('../gitbook');
22

3-
describe('satisfies', function() {
3+
describe('satisfies', () => {
44

5-
it('should return true for *', function() {
5+
it('should return true for *', () => {
66
expect(gitbook.satisfies('*')).toBe(true);
77
});
88

packages/gitbook/src/__tests__/init.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
const tmp = require('tmp');
22
const initBook = require('../init');
33

4-
describe('initBook', function() {
4+
describe('initBook', () => {
55

6-
it('should create a README and SUMMARY for empty book', function() {
6+
it('should create a README and SUMMARY for empty book', () => {
77
const dir = tmp.dirSync();
88

99
return initBook(dir.name)
10-
.then(function() {
10+
.then(() => {
1111
expect(dir.name).toHaveFile('README.md');
1212
expect(dir.name).toHaveFile('SUMMARY.md');
1313
});
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
describe('GitBook', function() {
3-
it('should correctly export', function() {
2+
describe('GitBook', () => {
3+
it('should correctly export', () => {
44
require('../');
55
});
66
});

0 commit comments

Comments
 (0)