Compare commits

..

1830 Commits

Author SHA1 Message Date
Eric Huss
39664985ba Merge pull request #2012 from ehuss/bump-version
Update to 0.4.26
2023-02-08 16:09:45 -08:00
Eric Huss
ab1e9694bc Update to 0.4.26 2023-02-08 15:58:51 -08:00
Eric Huss
2c710d3b7d Merge pull request #1987 from ehuss/theme-fonts
Make fonts part of the theme.
2023-02-08 15:56:40 -08:00
Eric Huss
581ab2c945 Merge pull request #2011 from ehuss/update-deps
Update some direct dependencies
2023-02-08 15:53:35 -08:00
Eric Huss
274b48c82f Update some direct dependencies
Updating anyhow v1.0.66 -> v1.0.69
Updating assert_cmd v2.0.7 -> v2.0.8
Updating handlebars v4.3.5 -> v4.3.6
Updating notify v5.0.0 -> v5.1.0
Updating once_cell v1.16.0 -> v1.17.0
Removing bstr v0.2.17
Removing lazy_static v1.4.0
Updating opener v0.5.0 -> v0.5.2
Updating regex v1.7.0 -> v1.7.1
Updating predicates v2.1.4 -> v2.1.5
Updating semver v1.0.14 -> v1.0.16
Updating serde v1.0.150 -> v1.0.152
Updating serde_derive v1.0.150 -> v1.0.152
Updating serde_json v1.0.89 -> v1.0.93
2023-02-08 15:40:48 -08:00
Eric Huss
e352e4f59c Merge pull request #1994 from Skwodo/master
fix overflow-x on mobile
2023-02-08 15:37:53 -08:00
Eric Huss
734936d819 Add some comments about overflow-x 2023-02-08 15:25:14 -08:00
Eric Huss
0e1384b4d2 Merge pull request #2009 from danieleades/deps/toml
bump 'toml' dependency
2023-02-08 14:08:21 -08:00
Daniel Eades
2160613c6a bump 'toml' dependency 2023-02-08 15:40:15 +00:00
Eric Huss
69bb5c7fba Merge pull request #2001 from iFreilicht/patch-1
Fix incorrect version command
2023-01-29 09:34:13 -08:00
Felix Uhl
f32e1a7773 Fix incorrect version command 2023-01-28 20:21:18 +01:00
Eric Huss
703c2f214b Merge pull request #1998 from dalance/remove_time
Remove dependency to time 0.1.44
2023-01-28 07:41:34 -08:00
dalance
6de831778a Remove dependency to time 0.1.44 2023-01-26 18:02:43 +09:00
Skwodo
ca46086e79 fix overflow-x on mobile 2023-01-21 22:41:01 +01:00
Eric Huss
0079184c16 Merge pull request #1961 from noritada/fix/scrollbar-in-chrome-and-safari
Use default scrollbars on webkit browsers
2023-01-18 09:25:02 -08:00
Noritada Kobayashi
dcc9efea0a Remove the WebKit-specific scrollbar styling altogether
It is preferable to remove WebKit-specific styling and use the browser
and OS default scrollbars.
Thanks to comments from @julianfortune, @arniu, and @ehuss.

Closes #1483.
2023-01-18 23:51:09 +09:00
Dylan DPC
a3b508fab9 Merge pull request #1988 from ehuss/issue-templates
Add issue templates and update contributor docs
2023-01-16 23:00:22 +05:30
Eric Huss
5359b487f2 Add issue templates and update contributor docs 2023-01-16 09:22:54 -08:00
Eric Huss
c2d973997a Make fonts part of the theme. 2023-01-15 11:42:46 -08:00
Eric Huss
41a6f0d43e Merge pull request #1968 from ehuss/ehuss-patch-1
Fix MDBOOK_BOOK environment variable example
2022-12-28 19:47:20 -08:00
Eric Huss
9764f8886b Fix MDBOOK_BOOK environment variable example 2022-12-28 19:21:38 -08:00
Noritada Kobayashi
1ba2c063e0 Thin scrollbars in Chrome and Safari to make them less assertive (#1483) 2022-12-22 15:40:03 +09:00
Eric Huss
c640294dbf Merge pull request #1960 from ehuss/bump-version
Update to 0.4.25
2022-12-17 08:19:15 -08:00
Eric Huss
dec487c62b Update to 0.4.25 2022-12-17 07:42:00 -08:00
Eric Huss
1ba74a30fc Merge pull request #1959 from ehuss/test-lib-multiple
Fix test with multiple library paths
2022-12-17 07:39:27 -08:00
Eric Huss
fcf0cebf6c Fix test with multiple library paths 2022-12-17 07:11:13 -08:00
Eric Huss
e14d38194f Merge pull request #1956 from ehuss/bump-version
Update to 0.4.24
2022-12-15 07:14:13 -08:00
Eric Huss
294aad092e Update to 0.4.24 2022-12-15 06:55:05 -08:00
Eric Huss
8767ebf835 Merge pull request #1955 from ehuss/ubuntu-20.04
Switch to older ubuntu image
2022-12-15 06:50:44 -08:00
Eric Huss
cd907f2edf Switch to older ubuntu image 2022-12-15 05:52:15 -08:00
Eric Huss
eb77083d23 Merge pull request #1953 from ehuss/bump-version
Update to 0.4.23
2022-12-14 18:46:05 -08:00
Eric Huss
219362318c Update to 0.4.23 2022-12-14 17:48:46 -08:00
Eric Huss
68a75dae48 Merge pull request #1844 from wendajiang/master
Upgrade clap
2022-12-14 17:26:07 -08:00
David
87a381e0a7 upgrade clap to 4.0 2022-12-14 17:11:08 -08:00
Eric Huss
0b2520f84a Merge pull request #1952 from ehuss/update-deps-breaking
Update dependencies with semver major changes
2022-12-14 17:08:41 -08:00
Eric Huss
21ab85cd03 Update notify
Update notify from 4.0.17 to 5.0.0
https://github.com/notify-rs/notify/blob/main/UPGRADING_V4_TO_V5.md
https://github.com/notify-rs/notify/blob/main/CHANGELOG.md#notify-500-2022-08-28
2022-12-14 14:01:27 -08:00
Eric Huss
486bf32ac7 Update topological-sort
Update topological-sort from 0.1.0 to 0.2.2
https://github.com/gifnksm/topological-sort-rs/compare/v0.1.0...v0.2.2
2022-12-14 08:06:20 -08:00
Eric Huss
4f6610716a Update select
Update select from 0.5.0 to 0.6.0
https://github.com/utkarshkukreti/select.rs/compare/0.5.0...0.6.0
2022-12-14 08:06:16 -08:00
Eric Huss
6db4ca71da Update env_logger
Update env_logger from 0.9.3 to 0.10.0

https://github.com/rust-cli/env_logger/blob/main/CHANGELOG.md#0100---2022-11-24
2022-12-14 08:06:11 -08:00
Eric Huss
d5319e2b4f Update assert_cmd
Update from 1.0.8 to 2.0.7
https://github.com/assert-rs/assert_cmd/blob/master/CHANGELOG.md#207---2022-12-02
2022-12-14 08:06:06 -08:00
Eric Huss
cda44480b7 Merge pull request #1951 from ehuss/update-deps
Update dependencies
2022-12-14 08:05:17 -08:00
Eric Huss
fb0af12433 Bump MSRV to 1.60
Needed for new feature syntax
2022-12-14 07:20:09 -08:00
Eric Huss
b5f858da4e Update dependencies
Fairly large update of semver compatible deps:

Updating aho-corasick v0.7.18 -> v0.7.20
Updating ammonia v3.1.2 -> v3.3.0
  Adding android_system_properties v0.1.5
Removing ansi_term v0.12.1
Updating anyhow v1.0.43 -> v1.0.66
Updating assert_cmd v1.0.7 -> v1.0.8
Updating autocfg v1.0.1 -> v1.1.0
Updating base64 v0.13.0 -> v0.13.1
Updating bit-set v0.5.2 -> v0.5.3
Removing block-buffer v0.7.3
Removing block-buffer v0.9.0
  Adding block-buffer v0.10.3
Removing block-padding v0.1.5
  Adding bumpalo v3.11.1
Removing byte-tools v0.3.1
Updating bytes v1.0.1 -> v1.3.0
  Adding cc v1.0.77
Updating chrono v0.4.19 -> v0.4.23
Updating clap v3.0.10 -> v3.2.23
Updating clap_complete v3.0.4 -> v3.2.5
  Adding clap_lex v0.2.4
  Adding codespan-reporting v0.11.1
  Adding core-foundation-sys v0.8.3
Updating cpufeatures v0.1.5 -> v0.2.5
  Adding crypto-common v0.1.6
Updating ctor v0.1.20 -> v0.1.26
  Adding cxx v1.0.83
  Adding cxx-build v1.0.83
  Adding cxxbridge-flags v1.0.83
  Adding cxxbridge-macro v1.0.83
Updating diff v0.1.12 -> v0.1.13
Removing digest v0.8.1
Removing digest v0.9.0
  Adding digest v0.10.6
Updating either v1.6.1 -> v1.8.0
Updating elasticlunr-rs v3.0.0 -> v3.0.1
Updating env_logger v0.9.0 -> v0.9.3
Removing fake-simd v0.1.2
  Adding fastrand v1.8.0
Updating filetime v0.2.15 -> v0.2.19
Updating form_urlencoded v1.0.1 -> v1.1.0
Updating futf v0.1.4 -> v0.1.5
Updating futures-channel v0.3.21 -> v0.3.25
Updating futures-core v0.3.21 -> v0.3.25
Updating futures-macro v0.3.16 -> v0.3.25
Updating futures-sink v0.3.21 -> v0.3.25
Updating futures-task v0.3.16 -> v0.3.25
Updating futures-util v0.3.16 -> v0.3.25
Removing generic-array v0.12.4
Removing generic-array v0.14.4
  Adding generic-array v0.14.6
Updating getrandom v0.2.3 -> v0.2.8
Updating h2 v0.3.4 -> v0.3.15
Updating handlebars v4.1.2 -> v4.3.5
Updating hashbrown v0.11.2 -> v0.12.3
Updating headers v0.3.4 -> v0.3.8
Removing html5ever v0.25.1
  Adding html5ever v0.25.2
  Adding html5ever v0.26.0
Updating http v0.2.4 -> v0.2.8
Updating http-body v0.4.3 -> v0.4.5
Updating httparse v1.5.1 -> v1.8.0
Updating httpdate v1.0.1 -> v1.0.2
Updating hyper v0.14.11 -> v0.14.23
  Adding iana-time-zone v0.1.53
  Adding iana-time-zone-haiku v0.1.1
Updating idna v0.2.3 -> v0.3.0
Updating indexmap v1.7.0 -> v1.9.2
  Adding instant v0.1.12
Updating itertools v0.10.1 -> v0.10.5
Updating itoa v0.4.8 -> v1.0.4
  Adding js-sys v0.3.60
Updating libc v0.2.100 -> v0.2.138
  Adding link-cplusplus v1.0.7
  Adding lock_api v0.4.9
Updating log v0.4.14 -> v0.4.17
  Adding markup5ever v0.11.0
Removing matches v0.1.9
Updating memchr v2.4.1 -> v2.5.0
Updating mime_guess v2.0.3 -> v2.0.4
Updating mio v0.7.13 -> v0.8.5
Removing miow v0.3.7
Updating net2 v0.2.37 -> v0.2.38
Removing ntapi v0.3.6
Updating num-integer v0.1.44 -> v0.1.45
Updating num-traits v0.2.14 -> v0.2.15
Updating num_cpus v1.13.0 -> v1.14.0
Updating once_cell v1.15.0 -> v1.16.0
Removing opaque-debug v0.2.3
Removing opaque-debug v0.3.0
Updating os_str_bytes v6.0.0 -> v6.4.1
Updating output_vt100 v0.1.2 -> v0.1.3
  Adding parking_lot v0.12.1
  Adding parking_lot_core v0.9.5
Updating percent-encoding v2.1.0 -> v2.2.0
Updating pest v2.1.3 -> v2.5.1
Updating pest_derive v2.1.0 -> v2.5.1
Updating pest_generator v2.1.3 -> v2.5.1
Updating pest_meta v2.1.3 -> v2.5.1
  Adding phf v0.10.1
  Adding phf_codegen v0.10.0
  Adding phf_generator v0.10.0
  Adding phf_shared v0.10.0
Updating pin-project v1.0.8 -> v1.0.12
Updating pin-project-internal v1.0.8 -> v1.0.12
Updating pin-project-lite v0.2.7 -> v0.2.9
Updating ppv-lite86 v0.2.10 -> v0.2.17
Updating predicates v2.0.1 -> v2.1.4
Updating predicates-core v1.0.2 -> v1.0.5
Updating predicates-tree v1.0.2 -> v1.0.7
Updating pretty_assertions v1.2.1 -> v1.3.0
Removing proc-macro-hack v0.5.19
Removing proc-macro-nested v0.1.7
Updating proc-macro2 v1.0.28 -> v1.0.47
Updating pulldown-cmark v0.9.1 -> v0.9.2
Removing quick-error v2.0.1
Updating quote v1.0.9 -> v1.0.21
Updating rand v0.8.4 -> v0.8.5
Updating rand_core v0.6.3 -> v0.6.4
Removing rand_hc v0.3.1
Updating redox_syscall v0.2.10 -> v0.2.16
Updating regex v1.5.5 -> v1.7.0
Updating regex-syntax v0.6.25 -> v0.6.28
  Adding rustls-pemfile v0.2.1
Updating ryu v1.0.5 -> v1.0.11
Updating scoped-tls v1.0.0 -> v1.0.1
  Adding scopeguard v1.1.0
  Adding scratch v1.0.2
Updating semver v1.0.4 -> v1.0.14
Updating serde v1.0.129 -> v1.0.150
Updating serde_derive v1.0.129 -> v1.0.150
Updating serde_json v1.0.66 -> v1.0.89
Updating serde_urlencoded v0.7.0 -> v0.7.1
Removing sha-1 v0.8.2
Removing sha-1 v0.9.7
  Adding sha-1 v0.10.1
  Adding sha1 v0.10.5
Updating shlex v1.0.0 -> v1.1.0
Updating siphasher v0.3.6 -> v0.3.10
Updating slab v0.4.4 -> v0.4.7
  Adding smallvec v1.10.0
Updating socket2 v0.4.1 -> v0.4.7
Updating string_cache v0.8.1 -> v0.8.4
Updating string_cache_codegen v0.5.1 -> v0.5.2
Updating syn v1.0.75 -> v1.0.105
Updating tempfile v3.2.0 -> v3.3.0
Updating tendril v0.4.2 -> v0.4.3
Updating termcolor v1.1.2 -> v1.1.3
  Adding termtree v0.4.0
Updating textwrap v0.14.2 -> v0.16.0
Updating thiserror v1.0.31 -> v1.0.37
Updating thiserror-impl v1.0.31 -> v1.0.37
Updating time v0.1.43 -> v0.1.45
Updating tinyvec v1.3.1 -> v1.6.0
Updating tokio v1.16.1 -> v1.23.0
Updating tokio-macros v1.8.0 -> v1.8.2
Updating tokio-stream v0.1.7 -> v0.1.11
Updating tokio-tungstenite v0.15.0 -> v0.17.2
Updating tokio-util v0.6.7 -> v0.7.4
Updating toml v0.5.8 -> v0.5.10
Updating tower-service v0.3.1 -> v0.3.2
Updating tracing v0.1.26 -> v0.1.37
Updating tracing-core v0.1.19 -> v0.1.30
Removing treeline v0.1.0
Updating tungstenite v0.14.0 -> v0.17.3
Updating typenum v1.13.0 -> v1.16.0
Updating ucd-trie v0.1.3 -> v0.1.5
Updating unicode-bidi v0.3.6 -> v0.3.8
  Adding unicode-ident v1.0.5
Updating unicode-normalization v0.1.19 -> v0.1.22
  Adding unicode-width v0.1.10
Removing unicode-xid v0.2.2
Updating url v2.2.2 -> v2.3.1
Updating version_check v0.9.3 -> v0.9.4
Updating warp v0.3.2 -> v0.3.3
Removing wasi v0.10.2+wasi-snapshot-preview1
  Adding wasi v0.10.0+wasi-snapshot-preview1
  Adding wasi v0.11.0+wasi-snapshot-preview1
  Adding wasm-bindgen v0.2.83
  Adding wasm-bindgen-backend v0.2.83
  Adding wasm-bindgen-macro v0.2.83
  Adding wasm-bindgen-macro-support v0.2.83
  Adding wasm-bindgen-shared v0.2.83
  Adding windows-sys v0.42.0
  Adding windows_aarch64_gnullvm v0.42.0
  Adding windows_aarch64_msvc v0.42.0
  Adding windows_i686_gnu v0.42.0
  Adding windows_i686_msvc v0.42.0
  Adding windows_x86_64_gnu v0.42.0
  Adding windows_x86_64_gnullvm v0.42.0
  Adding windows_x86_64_msvc v0.42.0
Updating xml5ever v0.16.1 -> v0.16.2
  Adding yansi v0.5.1
2022-12-14 07:03:48 -08:00
Eric Huss
59bd5db556 Merge pull request #1950 from yoyomo/issue-1949
#1949 update for hidden only on clipboard
2022-12-14 06:57:02 -08:00
armandocumate
cf1557e454 update for hidden only on clipboard 2022-12-14 06:54:45 -08:00
Dylan DPC
36e1f01091 Merge pull request #1946 from LePichu/master
fix: random `Array` ref in `src/theme/book.js`
2022-12-06 13:26:45 +05:30
LePichu
e3c484af01 fix: random ref in 2022-12-06 12:05:11 +05:30
Dylan DPC
4deb5c7cee Merge pull request #1941 from klensy/msrv
fix msrv in docs
2022-11-29 23:40:01 +05:30
klensy
21fb329d56 fix msrv in docs 2022-11-29 20:33:03 +03:00
Eric Huss
678b469835 Merge pull request #1938 from ehuss/bump-version
Update to 0.4.22
2022-11-28 10:16:18 -08:00
Eric Huss
ded48ddac7 Update to 0.4.22 2022-11-28 09:54:39 -08:00
Eric Huss
8a02fc755f Fix broken doc link 2022-11-28 09:53:47 -08:00
Dylan DPC
4844f72b96 Merge pull request #1935 from ehuss/theme-dropdown-rendering-changes
Show the currently selected theme
2022-11-22 13:32:12 +05:30
Eric Huss
f32bd6f945 Show the currently selected theme. 2022-11-21 15:27:39 -08:00
Eric Huss
f64fcbc07d Fix clipping in theme popup 2022-11-21 14:00:18 -08:00
Eric Huss
c34c3bf730 Merge pull request #1929 from Benjins/patch-2
Update docs link in Cargo.toml to HTTPS version
2022-11-18 18:05:37 -08:00
Benji Smith
de4c551363 Update docs link in Cargo.toml to HTTPS version
Currently, the documentation link is specified in Cargo.toml as:

documentation = "http://rust-lang.github.io/mdBook/index.html"

which propagates to crates.io and if users click on the docs link there they get the non-TLS version. Not likely to cause major issues, but still best practice to use the HTTPS version since it's there
2022-11-18 20:53:08 -05:00
Eric Huss
d45f02d38c Merge pull request #1924 from averms-forks/html-conformance
Better HTML5 conformance
2022-11-13 13:29:18 -08:00
Eric Huss
666975a1ef Merge pull request #1884 from willcrichton/master
Add support for watching additional directories
2022-11-13 12:53:19 -08:00
Will Crichton
144a1e4009 Add documentation for extra-watch-dirs 2022-11-12 14:28:43 -08:00
Will Crichton
8b486dfc71 Fix compilation failure 2022-11-12 14:23:05 -08:00
Aman Verma
db092a404e State canonical URL using <link> not <meta>.
The Google SEO docs describe using the link element to specify the canonical
page in a redirect. They don't mention anything about <meta>.
2022-11-12 14:54:28 -06:00
Aman Verma
edda3d1b51 Fix formatting of content attr in <meta http-equiv=refresh>
According to the HTML specification[1], there needs to be a space after the
semicolon and the URL must be unquoted.

[1]: https://html.spec.whatwg.org/multipage/semantics.html#attr-meta-http-equiv-refresh
2022-11-12 14:47:21 -06:00
Aman Verma
27a11e7b35 Don't generate obsolete charset attrs in <script>.
According to the HTML specification[1], the charset attribute is obsolete in
script elements.

[1]: https://html.spec.whatwg.org/multipage/obsolete.html#HTMLScriptElement-partial
2022-11-12 14:45:09 -06:00
Aman Verma
cfd4c93d88 Don't generate redundant <meta http-equiv=content-type>.
Quoting from the HTML specification[1]:

  A document must not contain both a meta element with an http-equiv attribute
  in the Encoding declaration state and a meta element with the charset
  attribute present.

So we remove the <meta> with the http-equiv attribute from our template.

[1]: https://html.spec.whatwg.org/multipage/semantics.html#attr-meta-http-equiv-content-type
2022-11-12 14:27:52 -06:00
Will Crichton
b1ca805d2a Fix tests 2022-11-07 14:08:31 -08:00
Will Crichton
852a882fab Improve error handling of extra-watch-dirs watching, fix not watching whitelisted files outside book root 2022-11-07 12:20:59 -08:00
Will Crichton
fb0cbc90e3 Add support for watching additional directories 2022-10-28 11:47:33 -07:00
Dylan DPC
3a24f10d7c Merge pull request #1911 from yoyomo/fix-copying-invisible-text
fix copying invisible text
2022-10-15 11:37:46 +05:30
armandocumate
3fc036e01a fi xcopying invisible text 2022-10-14 16:53:59 -07:00
Eric Huss
056a46cc97 Merge pull request #1862 from gifnksm/add-musl-binary
Deploy {x86_64,aarch64}-unknown-linux-musl binary
2022-10-13 17:17:53 -07:00
Eric Huss
f8df8ed72d Merge pull request #1906 from brettchalupa/kbd-styles-1813
Add styles for <kbd> elements
2022-10-09 13:52:52 -07:00
Brett Chalupa
79c159d123 Add styles for <kbd> elements
Allows for special styles to call them out since they're different than
normal text and different than code. They can make use of styles they
inherit for font style and weight.

Notes on changes:

- Added new CSS variables for reused elements
- The font-* rules are separate for each aspect so that they can inherit
  bold/italic/etc

Closes https://github.com/rust-lang/mdBook/issues/1813
2022-10-06 16:02:29 -04:00
Dylan DPC
a8c37ceace Merge pull request #1900 from kianmeng/fix-typos
Fix typos
2022-09-29 21:00:10 +05:30
Kian-Meng Ang
cb01f11ad1 Fix typos
Found via `codespell -S ./src/theme -L crate,nam,varius,phasis`
2022-09-29 22:41:12 +08:00
Noritada Kobayashi
7aaa84853d Add test code to show preprocessor developers what the interface data looks like (#1897)
This test code will show preprocessor developers what the input data
looks like and how to test the preprocessing results.
2022-09-24 14:32:41 -07:00
David
75857fbf73 feat: use once_cell instead of lazy_static (#1894) 2022-09-22 15:05:39 -07:00
Eric Huss
c8db0c8ec6 Merge pull request #1889 from mgeisler/simplify-and-then
Simplify the use of `Option::and_then`
2022-09-12 09:16:21 -07:00
Martin Geisler
3958260353 Simplify the use of Option::and_then
I found a few places where `Option::and_then` could be simplified (in
my opinion) with `?` or with `match`.
2022-09-11 00:46:26 +02:00
Eric Huss
8cdb8d0367 Merge pull request #1887 from mgeisler/edition-2021
Require Rust 2021 edition
2022-09-09 13:14:33 -07:00
Dylan DPC
66bf85b14f Require Rust 2021 edition
This allows us to clean up and simplify the code.
2022-09-09 16:00:35 +02:00
Dylan DPC
1a0892745e Merge pull request #1881 from GuillaumeGomez/unneeded-attribute
Remove unneeded `type` attribute for `<script>`
2022-08-30 10:53:11 +05:30
Guillaume Gomez
76b0493fb0 Remove unneeded type attribute for <script> 2022-08-29 21:07:50 +02:00
Chris Lovett
74eb4059d6 add a --chapter option to mdbook test. (#1741)
Sometimes when working on large books it is handy to be able to run mdbook on a single chapter of a book.
2022-08-25 19:13:51 -07:00
Dylan DPC
13f53eb64f Merge pull request #1876 from joepio/patch-1
Explain how to use `site-url` with asset URLs
2022-08-23 14:33:02 +05:30
Joep Meindertsma
b3941526cb Explain how to use site-url
Make sure people use the right kind of asset-urls. This issue only shows up when deploying, not using `mdbook serve`.
2022-08-23 10:33:25 +02:00
Eric Huss
fff067b2a8 Merge pull request #1836 from mgeisler/trim-trailing-whitespace
Avoid empty last line in editable code blocks
2022-08-10 19:55:06 -07:00
Martin Geisler
217546c2a0 Trim trailing whitespace in Rust code blocks
Before, a code block would always end with a final newline. The
newline was added unconditionally by `hide_lines`.

When the code block is syntax highlighted by highlight.js, this is not
a problem, no empty line is added for a final trailing `\n` character.
However, when the code block is editable and thus handled by the ACE
editor, a trailing newline _is_ significant. I believe this issue is
most closely described by https://github.com/ajaxorg/ace/issues/2083
in the upstream repository.

The effect of the way ACE handles newlines is that a code block like

    <pre>
      Some code
    </pre>

will create an editor with _two_ lines, not just one.

By trimming trailing whitespace, we ensure that we don’t accidentally
create more lines in the ACE editor than necessary.
2022-08-10 03:11:08 +02:00
Eric Huss
40c06f5e77 Merge pull request #1863 from ehuss/bump-version
Update to 0.4.21
2022-07-22 11:06:12 -07:00
Eric Huss
bb09caa9a3 Update to 0.4.21 2022-07-22 10:54:53 -07:00
gifnksm
4ebefeb43a Deploy {x86_64,aarch64}-unknown-linux-musl binary 2022-07-23 00:37:18 +09:00
Eric Huss
8f01d0234f Merge pull request #1861 from mitchmindtree/nightly-borrowcheck-err-workaround
Workaround rust nightly borrowcheck error (#1860)
2022-07-22 07:26:28 -07:00
mitchmindtree
13035baeae Workaround rust nightly borrowcheck error (#1860)
Surprisingly, this fixes the error filed at #1860!

This seems suspicious, perhaps indicative of a bug in Rust's non-lexical
lifetime handling?

The lifetimes in the `handlebars::Renderable::render` method signature
are quite complicated, and its unclear to me whether or not Rust is
catching some new safety edge-case that wasn't previously handled
correctly...

Possibly related to `drop` order, which I *think* is related to the
order of binding statements?
2022-07-22 15:15:12 +10:00
Eric Huss
92afe9bd3c Merge pull request #1857 from ehuss/bump-version
Update to 0.4.20
2022-07-14 14:26:20 -07:00
Eric Huss
4c1aca0abb Update to 0.4.20 2022-07-14 13:46:56 -07:00
Eric Huss
da166e051d Merge pull request #1855 from stevenengler/code-fmt
Fix code padding in headings
2022-07-13 18:06:49 -07:00
Steven Engler
6a4ba95926 Fixed code padding in headings 2022-07-13 19:12:33 -04:00
Eric Huss
6688bd8d7b Merge pull request #1849 from FauconFan/fix_author(s)_in_user_guide
authors -> author in user guide
2022-07-09 13:55:51 -07:00
Dylan DPC
01313a39cc Merge pull request #1851 from FauconFan/revert-1848-remove_non_exhaustive
Revert "remove __non_exhaustive members, add non_exhaustive attribute instead"
2022-07-09 21:51:04 +05:30
Joseph Priou
f92911b8aa Revert "remove __non_exhaustive members, add non_exhaustive attribute instead" 2022-07-09 17:43:17 +02:00
Dylan DPC
42d6fd5804 Merge pull request #1848 from FauconFan/remove_non_exhaustive
remove __non_exhaustive members, add non_exhaustive attribute instead
2022-07-09 19:18:25 +05:30
Fauconfan
a8a45a5fbe authors -> author in user guide 2022-07-09 15:31:00 +02:00
Fauconfan
11781f0c1b remove __non_exhaustive members, add non_exhaustive attribute instead 2022-07-09 15:05:06 +02:00
Eric Huss
53055e0345 Merge pull request #1840 from ehuss/fix-lock
Fix Cargo.lock for version bump.
2022-07-01 15:46:36 -07:00
Eric Huss
1af6d4b0ec Fix Cargo.lock for version bump. 2022-07-01 15:44:18 -07:00
Eric Huss
3e311dc975 Merge pull request #1838 from ehuss/bump-version
Update to 0.4.19
2022-07-01 15:23:01 -07:00
Eric Huss
04e31eb07b Update to 0.4.19 2022-07-01 14:55:25 -07:00
Eric Huss
eb82ddca0b Merge pull request #1837 from ehuss/serve-info
Always show the "serving on" info for `mdbook serve`.
2022-07-01 14:54:04 -07:00
Eric Huss
1d2b720ebe Always show the "serving on" info for mdbook serve. 2022-07-01 14:36:18 -07:00
Eric Huss
4c303c3b1d Merge pull request #1830 from ISSOtm/serve
Always open index page with `serve --open`
2022-07-01 13:18:47 -07:00
ISSOtm
42129c6181 Always open index page with serve --open 2022-07-01 09:01:25 +02:00
Eric Huss
a10a57e67d Merge pull request #1829 from ISSOtm/index
Fix up "index page" functionality
2022-06-29 17:55:11 -07:00
ISSOtm
fa5f32c7fd Make link to first chapter active in index page
Makes both pages more consistent, and also the previous test pass

Co-authored-by: Eric Huss <eric@huss.org>
2022-06-29 23:51:18 +02:00
ISSOtm
a91e888575 Add test for index page 2022-06-29 08:48:49 +02:00
ISSOtm
8571883923 Mark the first chapter as "index", even if not the first book item 2022-06-29 08:35:41 +02:00
Eric Huss
4cf005d4bd Merge pull request #1832 from ISSOtm/clippy
Fix Clippy lints
2022-06-27 14:28:39 -07:00
Eric Huss
b38792c166 Merge pull request #1833 from mattheww/2022-06_searchindex
Omit words longer than 80 characters from the search index
2022-06-27 14:17:40 -07:00
ISSOtm
248863addf Fix Clippy lints
Also remove `allow(clippy::*)`s where possible
2022-06-27 23:08:45 +02:00
Eric Huss
7e2752e71f Merge pull request #1834 from ehuss/update-deps
Update some dependencies
2022-06-27 13:58:40 -07:00
Eric Huss
cbf0ca027d Merge pull request #1806 from ehuss/button-overlap
Make code buttons appear on hover (or tap on mobile)
2022-06-27 13:58:17 -07:00
Eric Huss
2c2ba636a9 Update pretty_assertions from 0.6.1 to 1.2.1 2022-06-27 13:29:22 -07:00
Eric Huss
494e6722b2 Update env_logger from 0.7.1 to 0.9.0
This drops quick-error 1.2.3 from the tree
2022-06-27 13:29:22 -07:00
Eric Huss
ddf71222c5 Bump tokio from 1.10.0 to 1.16.1 2022-06-27 13:29:18 -07:00
Eric Huss
1d89127d8f Mention how to uninstall.
Closes #1822.
2022-06-27 11:10:09 -07:00
Eric Huss
5f00625c14 Merge pull request #1617 from lf-/x-overflow
Fix some x overflows
2022-06-27 11:01:48 -07:00
Matthew Woodcraft
000a93dc77 Test that long words are omitted from the search index.
Note they do appear in the 'docs' part of searchindex.json (so they will be
visible in search teasers).
2022-06-26 12:22:52 +01:00
Matthew Woodcraft
1f8c090a5f When creating the search index, omit words longer than 80 characters
This avoids creating deeply nested objects in searchindex.json
2022-06-26 12:22:52 +01:00
Eric Huss
0547868d4d Merge pull request #1825 from joshrotenberg/update-warp-version
Update warp to 0.3.2
2022-06-22 17:33:56 -07:00
Dylan DPC
1056b8361c Merge pull request #1828 from rust-lang/revert-1809-2022-05_searchindex
Revert "Omit words longer than 80 characters from the search index"
2022-06-22 13:50:01 +02:00
Dylan DPC
a5f861bf2b Revert "Omit words longer than 80 characters from the search index" 2022-06-22 13:31:16 +02:00
Dylan DPC
93aee6419e Merge pull request #1809 from mattheww/2022-05_searchindex
Omit words longer than 80 characters from the search index
2022-06-22 13:14:08 +02:00
Josh Rotenberg
4b1a7e9ae7 update warp to 0.3.2 2022-06-20 10:48:03 -07:00
Eric Huss
2f5e89f3ec Merge pull request #1810 from mattico/el-v3
Update to elasticlunr-rs 3.0.0
2022-06-02 15:02:19 -07:00
Eric Huss
2b903ad057 Make code block icons appear on hover. 2022-06-01 18:48:34 -07:00
Matt Ickstadt
fb397e6fa0 Update to elasticlunr-rs 3.0.0 2022-06-01 20:20:14 -05:00
Matthew Woodcraft
00a55b35a8 Test that long words are omitted from the search index.
Note they do appear in the 'docs' part of searchindex.json (so they will be
visible in search teasers).
2022-05-22 14:02:54 +01:00
Matthew Woodcraft
d65ce55453 When creating the search index, omit words longer than 80 characters
This avoids creating deeply nested objects in searchindex.json
2022-05-22 14:00:20 +01:00
Eric Huss
37d756ae75 Adjust overlap of code buttons with code blocks. 2022-05-16 19:27:46 -07:00
Eric Huss
f8782666ba Merge pull request #1714 from joshrotenberg/draft-no-index
Check for the index.html file before trying to opener::open it
2022-05-16 08:04:38 -07:00
josh rotenberg
c74c682939 call find_chapter when opening browser 2022-05-11 13:14:38 -07:00
josh rotenberg
8b49600673 call first_chapter 2022-05-10 11:19:23 -07:00
josh rotenberg
29c729fd23 call first_chapter 2022-05-10 11:17:20 -07:00
josh rotenberg
5d65967448 add first_chapter function 2022-05-10 11:16:22 -07:00
Eric Huss
bf258eeb9b Merge pull request #1801 from klensy/static-regex
init regexes via lazy_static
2022-05-06 12:05:10 -07:00
klensy
af6237015a init regexes via lazy_static, don't recompute it 2022-05-06 10:05:52 +03:00
Eric Huss
a462fb63c3 Merge pull request #1798 from klensy/serde_derive
Use serde's `derive` feature instead of directly importing serde_derive
2022-05-05 12:55:01 -07:00
klensy
f3332fb0da Use serde's derive feature instead of directly importing serde_derive 2022-05-05 09:33:51 +03:00
Eric Huss
5bea83114b Merge pull request #1791 from clarkfw/master
bail! in render() if specified theme directory does not exist
2022-05-02 11:08:57 -07:00
Clark
fe8bb38ec1 add a test: Ensure building fails if [output.html].theme points to a non-existent directory 2022-04-28 13:13:58 +08:00
Clark
a60571321a bail! in render() if specified theme directory does not exist 2022-04-26 20:20:44 +08:00
Eric Huss
e1c2e1a753 Merge pull request #1788 from max-sixty/patch-1
Fix typo in changelog
2022-04-15 12:26:42 -07:00
Maximilian Roos
800dbf2929 Fix typo in changelog 2022-04-15 12:09:31 -07:00
Eric Huss
1880447dce Merge pull request #1787 from ehuss/bump-version
Update to 0.4.18
2022-04-15 11:33:56 -07:00
Eric Huss
268dbb099f Update to 0.4.18 2022-04-15 11:24:45 -07:00
Eric Huss
ae275ad1b1 Merge pull request #1785 from ehuss/summary-escape
Don't try to render summary links as markdown.
2022-04-15 11:20:17 -07:00
Eric Huss
ceff050bb4 Don't try to render summary links as markdown. 2022-04-14 20:35:39 -07:00
josh rotenberg
8357811d96 Merge branch 'draft-no-index' of https://github.com/joshrotenberg/mdBook into draft-no-index 2022-04-04 18:59:47 -07:00
josh rotenberg
860a17d85a Merge branch 'rust-lang:master' into draft-no-index 2022-04-04 18:59:39 -07:00
Eric Huss
ba324cddb6 Merge pull request #1778 from sgoudham/fix-typo
User Guide: Fix typo 'mbdook' to 'mdbook'
2022-04-01 14:36:51 -07:00
Eric Huss
a5dcd78393 Merge pull request #1777 from trofi/ignore-RUST_LOG
tests/cli: ignore user's RUST_LOG= environment variable in tests
2022-04-01 14:00:44 -07:00
sgoudham
8e1195322a Fix typo 'mbdook' to 'mdbook' 2022-04-01 13:13:58 +01:00
Sergei Trofimovich
2a2b51c8ab tests/cli: ignore user's RUST_LOG= environment variable in tests
nixpkgs build system sets `RUST_LOG=` (empty value) by default.
This switches `mdBook` into warnings+ mode (instead of info+).

This causes the following tests to fail:

    $ RUST_LOG= cargo test --test cli_tests
    ...
    cli::test::mdbook_cli_can_correctly_test_a_passing_book
    cli::test::mdbook_cli_detects_book_with_failing_tests
    cli::build::mdbook_cli_dummy_book_generates_index_html

The change drops RUST_LOG= entry.
2022-04-01 08:15:18 +01:00
Eric Huss
eb5ec2a314 Merge pull request #1776 from ehuss/bump-version
Update to 0.4.17
2022-03-30 10:22:28 -07:00
Eric Huss
445529a68f Update to 0.4.17 2022-03-30 09:33:56 -07:00
Eric Huss
981b79b3b3 Merge pull request #1775 from ehuss/fix-print-config
Fix html print config default.
2022-03-30 09:31:16 -07:00
Eric Huss
78bcda02cb Fix html print config default. 2022-03-30 07:58:27 -07:00
Eric Huss
cdfa5ad990 Add missing entries for 0.4.16 2022-03-29 17:50:08 -07:00
Eric Huss
720f502e9d Merge pull request #1773 from ehuss/bump-version
Update to 0.4.16
2022-03-29 17:45:05 -07:00
Eric Huss
adf6129769 Update to 0.4.16 2022-03-29 17:33:01 -07:00
Eric Huss
a5fddfa468 Merge pull request #1749 from tommilligan/unique-search-anchors
search: fix anchor ids for duplicate headers
2022-03-28 12:44:20 -07:00
Eric Huss
7c37dd5e85 Merge pull request #1731 from epage/clap3
Port mdBook to clap3
2022-03-28 12:34:17 -07:00
Ed Page
857ca19fe4 refactor: Move from deprecated arg_from_usage 2022-03-28 13:06:50 -05:00
Ed Page
a19d91ef37 refactor: Move from deprecated multiple 2022-03-28 13:06:50 -05:00
Ed Page
ac8526688a refactor: Move from deprecated empty_values 2022-03-28 13:06:50 -05:00
Ed Page
1e1c99bbdb refactor: Move from deprecated GlobalVersion 2022-03-28 13:06:50 -05:00
Ed Page
0c89293029 refactor: Move from deprecated ColoredHelp 2022-03-28 13:06:50 -05:00
Ed Page
39eb78c88b refactor: Move from deprecated SubCommand 2022-03-28 13:06:50 -05:00
Ed Page
372842aac6 refactor: Move from deprecated Arg::with_name 2022-03-28 13:06:50 -05:00
Ed Page
7934e06668 chore: Upgrade to clap3 2022-03-28 13:06:50 -05:00
Ed Page
44f982f8e5 chore: Upgrade MSRV 2022-03-28 13:06:44 -05:00
Eric Huss
1f04a62648 Merge pull request #1693 from rsapkf/404-title
Add proper title to 404 page
2022-03-27 17:26:45 -07:00
Eric Huss
675c8c3f4e Add book title to 404 page title. 2022-03-27 17:17:20 -07:00
rsapkf
97cb77bbdd Add proper title to 404 page 2022-03-27 17:01:11 -07:00
Eric Huss
46345b8e49 Fix comment typo 2022-03-27 16:39:12 -07:00
Eric Huss
566451e9a7 Merge pull request #1771 from FWYongxing/master
livereload uses host, port and HTTP(S) protocol of current page
2022-03-27 16:33:32 -07:00
Eric Huss
15626294b0 Merge pull request #1744 from ilslv/1743-fix-title-consuming-events
Fix `SummaryParser::parse_title()` consuming events (#1743)
2022-03-27 14:38:00 -07:00
Eric Huss
6cab04554e Merge pull request #1546 from pineapplehunter/master
Config to toggle the run button on codeblocks
2022-03-27 12:32:35 -07:00
Shogo Takata
2ae7f007cc add doc in mdbook.md 2022-03-27 17:28:42 +09:00
Shogo Takata
89e37a7751 add docs 2022-03-26 16:11:41 +09:00
Shogo Takata
0dca4d9b9f add tests 2022-03-26 15:34:07 +09:00
Shogo Takata
b85c3035fe Config to toggle the run button on codeblocks 2022-03-26 14:50:47 +09:00
Clark
6899d94027 livereload uses host&port of current page; livereload works with a HTTPS site 2022-03-19 04:38:16 +08:00
Eric Huss
fa0f9df497 Merge pull request #1763 from Dylan-DPC/fix/regex-dep
update regex
2022-03-09 09:10:20 -08:00
Dylan DPC
917df6e97d update regex 2022-03-09 08:04:50 +01:00
Eric Huss
5921f59817 Merge pull request #1754 from PiDelport/patch-1
style: add missing word
2022-02-22 09:12:26 -08:00
Pi Delport
50bad7f983 style: add missing word 2022-02-22 18:00:41 +02:00
Tom Milligan
972c61fa76 search: fix anchor ids for duplicate headers 2022-02-18 16:20:05 +00:00
ilslv
b73d02fb8c Remove colon to satisfy msrv 2022-02-11 12:50:22 +03:00
ilslv
6c4974b5c6 Fmt 2022-02-11 12:42:54 +03:00
ilslv
81d661c4f1 Fix no initial title consuming events. 2022-02-11 12:33:22 +03:00
Eric Huss
2213312938 Merge pull request #1728 from dmorawetz/master
Make page-break configurable
2022-01-30 14:25:02 -08:00
Jade Lovelace
4ae7ab5e87 switch to break-word as suggested 2022-01-27 18:42:39 -08:00
Jade
59569984e2 Address review: use overflow-wrap everywhere 2022-01-27 18:41:31 -08:00
Jade
89b580ab52 Add a test for the table div-wrapping 2022-01-27 18:41:31 -08:00
Jade
85df785cd3 Wrap tables in an overflow-x wrapper div 2022-01-27 18:41:30 -08:00
Jade
fde88c22a8 Fix an x overflow with long inline code
Spotted on
https://rust-lang.github.io/rfcs/2603-rust-symbol-name-mangling-v0.html
2022-01-27 18:39:09 -08:00
Eric Huss
0ec4b692f4 Merge pull request #1732 from dtolnay-contrib/semver
Update semver dev-dependency in nop-preprocessor example to 1.0
2022-01-24 05:59:31 -08:00
David Tolnay
c5c8f1a6d3 Update semver dev-dependency in nop-preprocessor example to 1.0 2022-01-23 00:01:10 -08:00
Eric Huss
336640633b Merge pull request #1729 from GuillaumeGomez/update-pulldown
Update pulldown-cmark version
2022-01-18 09:08:46 -08:00
Guillaume Gomez
4206739492 Update pulldown-cmark version 2022-01-18 16:01:23 +01:00
Daniel Morawetz
9e6217871e add page-break option to docs 2022-01-17 18:07:22 +01:00
Daniel Morawetz
7b1241d0f2 Revert "Make page-break not configurable"
This reverts commit 0eb23efd44.
2022-01-17 18:03:52 +01:00
Eric Huss
9acc0debec Merge pull request #1727 from calebcartwright/cargo-fmt-check
use new cargo fmt option
2022-01-13 16:06:29 -08:00
Caleb Cartwright
a226de38b6 ci: use new cargo fmt option 2022-01-13 18:01:42 -06:00
josh rotenberg
f5b0b1934a Merge remote-tracking branch 'upstream/master' into draft-no-index 2022-01-11 09:53:43 -08:00
Eric Huss
64838ce07d Merge pull request #1723 from klensy/pc
don't use additional features for pulldown-cmark
2022-01-07 10:57:01 -08:00
klensy
526a0394b0 don't use additional features for pulldown-cmark 2022-01-06 20:35:13 +03:00
Eric Huss
6ed570940d Merge pull request #1721 from ehuss/bump-version
Update to 0.4.15
2022-01-04 10:38:19 -08:00
Eric Huss
b0511f408d Update to 0.4.15 2022-01-04 10:18:39 -08:00
Eric Huss
68a5c09fdf Merge pull request #1712 from GuillaumeGomez/pulldown-cmark
Update pulldown-cmark version
2021-12-29 19:53:08 -08:00
Eric Huss
97b6a35afc Merge pull request #1710 from ehuss/update-guide
Update documentation
2021-12-29 19:26:16 -08:00
josh rotenberg
1cacef025d check for the index.html file first 2021-12-28 21:00:06 -08:00
Guillaume Gomez
ddb0d2396f Update pulldown-cmark version 2021-12-25 13:46:27 +01:00
Eric Huss
f2fba30786 Update documentation 2021-12-19 20:26:37 -08:00
Eric Huss
f3e5fce6bf Merge pull request #1709 from joshrotenberg/markdown-page
Markdown page
2021-12-19 13:26:41 -08:00
josh rotenberg
2d36cd9263 more markdown 2021-12-18 16:00:46 -08:00
josh rotenberg
09087097b5 add more sections here 2021-12-18 15:50:51 -08:00
josh rotenberg
18b9f42fba add the markdown page 2021-12-17 19:08:58 -08:00
josh rotenberg
b38949a408 add a markdown page 2021-12-17 19:08:21 -08:00
josh rotenberg
c32869cf10 moving this to the markdown page 2021-12-17 19:08:03 -08:00
Eric Huss
e3e170715e Merge pull request #1706 from vaporup/patch-1
Fix Typo in summary.md
2021-12-16 13:53:22 -08:00
Eric Huss
a387f482d8 Merge pull request #1705 from acoglio/patch-1
Fix typo.
2021-12-16 13:53:01 -08:00
Sven Wick
4e03818f3e Update summary.md 2021-12-16 18:29:47 +01:00
Alessandro Coglio
3f268cb0df Fix typo. 2021-12-15 20:53:01 -08:00
Eric Huss
25829926e5 Merge pull request #1702 from ehuss/update-readme
Update some outdated info in the readme.
2021-12-09 17:39:24 -08:00
Eric Huss
c828002b70 Update some outdated info in the readme. 2021-12-09 17:29:40 -08:00
Eric Huss
cdbfb4a5b9 Merge pull request #1699 from joshrotenberg/patch-1
Fix typo
2021-12-06 08:31:27 -08:00
josh rotenberg
191dccab10 fix typo 2021-12-06 08:06:07 -08:00
Eric Huss
5eb7d46a99 Merge pull request #1696 from ehuss/bump-version
Update to 0.4.14
2021-11-27 10:34:17 -08:00
Eric Huss
dffcedf031 Update to 0.4.14 2021-11-27 10:10:51 -08:00
Eric Huss
c9b6be8660 Merge pull request #1675 from ehuss/deprecate-ga
Deprecate google-analytics
2021-11-27 09:53:44 -08:00
Eric Huss
23af80c506 Merge pull request #1685 from igxactly/fix-ios-text-size-landscape
Prevent iOS Safari from enlarging text in landscape orientation
2021-11-20 10:01:41 -08:00
Eric Huss
857acb9759 Merge pull request #1683 from abdnh/strip-html-from-anchor-ids
Strip HTML tags from anchor IDs
2021-11-20 09:47:18 -08:00
Eric Huss
2ddcb43899 Merge pull request #1668 from joshrotenberg/update-pulldown-cmark
Update pulldown-cmark to 0.8.0 and use Smart Punctuation feature
2021-11-20 08:33:45 -08:00
josh rotenberg
1c0983b811 use pulldown cmarks curly quotes 2021-11-19 17:26:30 -08:00
josh rotenberg
1be69af553 need to actually enable it 2021-11-19 15:14:22 -08:00
josh rotenberg
c63000f365 Merge remote-tracking branch 'upstream/master' into update-pulldown-cmark 2021-11-19 15:01:04 -08:00
Ingu Kang
bbaa0ea1fa Prevent iOS Safari from enlarging text in landscape orientation
referernces:
  - https://developer.mozilla.org/en-US/docs/Web/CSS/text-size-adjust#basic_disabling_usage
  - https://trac.webkit.org/changeset/261940/webkit
2021-11-13 15:37:20 +09:00
Abdo
58bc92d380 Strip HTML tags from anchor IDs 2021-11-10 00:41:44 +03:00
Eric Huss
17d1ed3716 Merge pull request #1676 from YJDoc2/add_triagebot
Add minimal traigebot config
2021-10-27 09:31:40 -07:00
Yashodhan Joshi
8df8ce063d Add minimal traigebot config 2021-10-27 19:31:08 +05:30
Eric Huss
c3ff4a5129 Deprecate google-analytics. 2021-10-24 11:43:37 -07:00
Eric Huss
4d20fa578b Merge pull request #1642 from ehuss/stabilize-2021
Stabilize 2021 flag.
2021-10-24 10:30:55 -07:00
Eric Huss
9e47498458 Merge pull request #1662 from YJDoc2/test-book
Add a Test Book to verify style changes against
2021-10-24 10:01:22 -07:00
josh rotenberg
903469a45f update pulldown-cmark to 0.8.0 2021-10-13 20:27:00 -07:00
Yashodhan Joshi
b8ef89db62 Add rust specific codeblock examples 2021-10-05 12:11:29 +05:30
Yashodhan Joshi
c283211a37 Add Languages examples for syntax highlighting 2021-10-05 12:02:33 +05:30
Yashodhan Joshi
d5af051d0e Add individual tag examples in test_book 2021-10-04 16:17:52 +05:30
Yashodhan Joshi
68f9afe64b Setup basic structure for test book 2021-10-04 13:14:49 +05:30
Eric Huss
ffa8284743 Merge pull request #1661 from ehuss/bump-version
Update to 0.4.13
2021-10-03 15:39:23 -07:00
Eric Huss
3e91f9cd5d Update to 0.4.13 2021-10-03 15:15:21 -07:00
Eric Huss
f55028b61a Merge pull request #1657 from lclc/gitlabPages
Documentation: CI: GitLab Pages Example
2021-10-03 14:51:08 -07:00
Eric Huss
0d887505af Merge pull request #1607 from ISSOtm/preproc-order
Allow specifying preprocessor order
2021-10-03 14:22:15 -07:00
Eric Huss
6c20736a55 Merge pull request #1658 from pickfire/patch-1
Remove extra semicolon in variables.css
2021-10-03 12:24:11 -07:00
Ivan Tham
e4a46c9477 Remove extra semicolon in variables.css 2021-10-03 22:23:09 +08:00
Ivan Tham
6ae5c686d9 Remove extra semicolon in variables.css 2021-10-03 22:19:51 +08:00
Lucas Betschart
b862080006 Documentation: CI: GitLab Pages Example
Replace 'only' with 'rules'.
'only' is not actively developed anymore with GitLab (see https://docs.gitlab.com/ee/ci/yaml/#only--except)
2021-09-29 12:42:15 +02:00
ISSOtm
6b790b83ec Warn when preproc order references unknown preprocs 2021-09-28 09:25:17 +02:00
ISSOtm
d8ad68c947 Produce an error if before or after field is not a table 2021-09-27 21:28:21 +02:00
ISSOtm
6b784be616 Stabilize ties in preproc order through name sort 2021-09-27 21:28:01 +02:00
Eric Huss
f5598b2eee Merge pull request #1656 from johannst/switch-to-opener-crate
switch from open to opener
2021-09-26 12:33:23 -07:00
Johannes Stoelp
ff4b8e7a8d switch from open to opener
By default, `opener` launches the subprocess without waiting for its
completion, compared to `open` which waits for its completion.

This is helpful in case the `watch` feature is enabled and one of the
following commands `watch | serve --open` is used. If this command would
open the browser, listening for changes would be blocked by the browser.
2021-09-26 12:33:09 -07:00
ISSOtm
9c34e602bd Allow specifying preprocessor order
Fixes #1172
2021-09-26 20:55:02 +02:00
Eric Huss
a306da3ad7 Merge pull request #1604 from notriddle/notriddle/test-cli
Add CLI tests
2021-09-26 11:37:09 -07:00
Michael Howell
9bede85efa Move cli tests to their own subdir 2021-09-26 11:29:36 -07:00
Michael Howell
11b1e86187 Fix path dumps under windows 2021-09-26 11:29:36 -07:00
Michael Howell
10d30a2dc0 Add CLI tests
Part of #1568
2021-09-26 11:29:35 -07:00
Eric Huss
601ebc5499 Merge pull request #1651 from notriddle/notriddle/theme-switcher-js
Only switch to themes on buttons that have the `theme` class
2021-09-16 17:32:01 -07:00
Michael Howell
4251d7a838 Only switch to themes on buttons that have the theme class
Fixes #1649
2021-09-14 10:05:35 -07:00
Eric Huss
93008cf20b Merge pull request #1643 from apogeeoak/update-open
Update open crate to latest version.
2021-09-07 10:20:24 -07:00
apogeeoak
3f9f681b9e Update open crate to latest version. 2021-09-06 15:52:43 -04:00
Eric Huss
63680d0786 Merge pull request #1480 from pauliyobo/preprocessor_docs
Improving documentation on implementation of preprocessors.
2021-09-05 18:46:09 -07:00
Eric Huss
656a1825cc Minor fixes for preprocessor docs. 2021-09-05 18:45:37 -07:00
pauliyobo
1a2fa29209 introduced proposed suggestions related to the documentation 2021-09-04 23:44:27 +02:00
Eric Huss
6be81214b1 Stabilize 2021 flag. 2021-09-03 11:00:27 -07:00
Eric Huss
d22299d998 Merge pull request #1631 from benarmstead/master
Format better, remove unnecessary borrows, and update depends
2021-09-03 10:15:16 -07:00
Eric Huss
0af417085f Merge pull request #1634 from vv9k/master
Add information about a new backend `mdbook-man`
2021-09-03 10:11:32 -07:00
Eric Huss
9634798eb7 Merge pull request #1637 from notriddle/no-headers
Include chapters with no headers in the search index
2021-09-03 10:10:07 -07:00
Michael Howell
2a8af1c21d Include chapters with no headers in the search index 2021-08-31 12:48:21 -07:00
Wojciech Kępka
981f8695ff Add information about a new backend mdbook-man 2021-08-26 17:45:22 +02:00
Eric Huss
48b5e52f62 Merge pull request #1632 from tsoutsman/patch-1
Fix preprocessor example
2021-08-24 10:23:06 -07:00
Klim Tsoutsman
c4fec94c4c Appease Clippy 2021-08-24 23:04:32 +10:00
Ben Armstead
ab0c338c08 Update depends 2021-08-24 08:57:36 +01:00
Ben Armstead
8a82f6336a Format with cargo correctly 2021-08-24 08:48:24 +01:00
Ben Armstead
1700783594 Format better and remove unnecessary borrows 2021-08-24 08:45:06 +01:00
Eric Huss
e6629cd75b Merge pull request #1623 from ehuss/release-next
Update to 0.4.12
2021-08-02 08:40:26 -07:00
Eric Huss
5a077b9ff4 Update to 0.4.12 2021-08-02 08:19:34 -07:00
Eric Huss
8b4e488de1 Merge pull request #1621 from ehuss/revert-highlightjs11
Revert #1597 - Update to highlight.js 11.0.
2021-08-02 08:15:45 -07:00
Eric Huss
68d8ceec47 Revert #1597 - Update to highlight.js 11.0. 2021-08-02 08:02:13 -07:00
Eric Huss
db337d4a6f Merge pull request #1616 from joshrotenberg/add_cleanup_contributors
Add a couple contributors, clean up a little
2021-07-27 08:59:46 -07:00
josh rotenberg
5e277140be add a couple, clean up a little 2021-07-26 21:23:42 -07:00
Eric Huss
14add9c290 Merge pull request #1615 from ehuss/release-next
Update to 0.4.11
2021-07-26 13:47:37 -07:00
Eric Huss
87877a9dae Update to 0.4.11 2021-07-26 13:47:08 -07:00
Eric Huss
2cf00d0880 Merge pull request #1597 from ehuss/update-hightlight.js
Update to highlight.js 11.0.
2021-07-26 13:22:42 -07:00
Eric Huss
8c7af3c767 Merge pull request #1614 from joshrotenberg/code_of_conduct
Add explicit code of conduct, copying other rust-lang repos
2021-07-26 12:42:15 -07:00
Eric Huss
6dd785ea6c Update to highlight.js 11.0. 2021-07-26 12:40:28 -07:00
Eric Huss
8d131b4310 Merge pull request #1598 from ehuss/update-contributing
Some minor updates to contributing docs.
2021-07-26 12:38:06 -07:00
Eric Huss
97b38063b1 Merge pull request #1613 from FWYongxing/master
Don't highlight `inline code` blocks in headers with output.html. playpen(playgroud).editable=true
2021-07-26 12:37:39 -07:00
josh rotenberg
d23734f82e add explicit code of conduct, copying other rust-lang repos 2021-07-26 11:52:24 -07:00
Eric Huss
2ccfaadd1d Merge pull request #1609 from joshrotenberg/intro_updates
Updates to the mdbook introduction
2021-07-26 11:41:51 -07:00
Eric Huss
3d04e5c7ff Merge pull request #1612 from joshrotenberg/update_tokio_warp
Update tokio and warp to latest versions
2021-07-26 11:37:54 -07:00
FWYongxing
49ef7b6f02 Don't highlight inline code blocks in headers with output.html.playpen(playgroud).editable=true 2021-07-27 01:02:17 +08:00
josh rotenberg
da7026190c add Cargo.lock change too 2021-07-26 09:49:38 -07:00
josh rotenberg
92377013cc 1.46.0 has if, match, and loop expressions can now be used in const functions. 2021-07-25 19:33:21 -07:00
josh rotenberg
34b586ab32 tokio msrv is 1.45.2 2021-07-25 19:27:47 -07:00
josh rotenberg
a79065b0d3 update warp and tokio versions 2021-07-25 19:14:40 -07:00
josh rotenberg
b3ab93a4b3 update warp and tokio versions 2021-07-25 19:14:34 -07:00
josh rotenberg
49b75810fa fix a few typos 2021-07-24 21:17:41 -07:00
josh rotenberg
b85d5eb455 updates to the mdbook introduction 2021-07-24 18:41:53 -07:00
Eric Huss
27faa54ae8 Merge pull request #1469 from tuyen-at-work/patch-1
Support space as seperator between language and additional class in c…
2021-07-10 09:34:33 -07:00
Eric Huss
fae0759626 Split lang on tab to be consistent with rustdoc and GitHub. 2021-07-10 09:33:34 -07:00
Tuyen Pham
cc74ca2e6e Update mod.rs 2021-07-10 09:26:41 -07:00
Tuyen Pham
7cae3a058d Support space as seperator between language and additional class in code block
This PR try to resolve this issue: https://github.com/rust-lang/mdBook/issues/1384
2021-07-10 09:26:41 -07:00
Eric Huss
8fb6ac7987 Merge pull request #1599 from notriddle/notriddle/play-button-no-output
feat(playground): show "No output" on playgrounds that print nothing
2021-07-08 13:17:15 -07:00
Michael Howell
82d32ee761 feat(playground): show "No output" on playgrounds that print nothing
Fixes #1594
2021-07-07 10:44:51 -07:00
Eric Huss
fe9b534ad7 Some minor updates to contributing docs. 2021-07-06 11:42:42 -07:00
Eric Huss
56652e8fa6 Merge pull request #1559 from joshrotenberg/title_ignore_flags_init
Add --title option and --gitignore flag to mdbook init
2021-07-06 09:22:38 -07:00
Eric Huss
c3a1e41ed7 Update CLI docs for flag name change. 2021-07-06 09:22:05 -07:00
Eric Huss
3976c9d8f0 Merge pull request #1576 from kana4/master
MyPaths are not required and fail
2021-07-06 08:59:54 -07:00
Eric Huss
96b6f02834 Merge pull request #1425 from alexmaco/completions
Add ability to generate shell completions via clap
2021-07-06 08:59:06 -07:00
Eric Huss
b571511737 Merge pull request #1596 from joshrotenberg/rust_edition_2021_support
Rust Edition 2021 Support
2021-07-06 08:34:18 -07:00
josh rotenberg
ebdab38a32 remove debugging 2021-07-04 20:25:04 -07:00
josh rotenberg
c06f450e7d add edition2021 as an option 2021-07-04 16:28:52 -07:00
josh rotenberg
b87c231fc3 first pass at 2021 support 2021-07-04 14:44:23 -07:00
josh rotenberg
8024b08f93 format 2021-07-04 12:00:13 -07:00
josh rotenberg
8ec0bf6e30 ignore now takes a value 2021-07-04 11:57:46 -07:00
kana
a8926d5392 Update continuous-integration.md 2021-07-04 18:28:56 +01:00
kana
00473d8420 Add comments to edit in case of custom book path 2021-07-04 18:27:53 +01:00
josh rotenberg
86d390032b drop short flags 2021-07-04 08:15:51 -07:00
Eric Huss
b3c0b01350 Merge pull request #1586 from joshrotenberg/fix_library_path_doc
Clarify the library path documentation
2021-07-04 07:41:42 -07:00
Eric Huss
e33192753d Merge pull request #1591 from fritsstegmann/patch-1
Update renderers.md
2021-07-04 07:30:44 -07:00
Frits Stegmann
7932e13512 Update renderers.md
I was doing some work on the epub plugin repo and when trying to build an epub I came across what looked like some broken references.
2021-07-04 08:12:18 +02:00
josh rotenberg
9fd2509c0d fix link 2021-06-25 08:24:57 -07:00
josh rotenberg
5dec8508c7 clarify the library path documentation 2021-06-24 19:08:23 -07:00
Eric Huss
4d2dc6f482 Merge pull request #1581 from tuyen-at-work/patch-2
Fix inconsistent between bash version and rust version of the sample
2021-06-19 07:21:44 -07:00
Tuyen Pham
efb13d7bc1 Fix inconsistent between bash version and rust version of the sample
In the bash version, `y` have value 6, while rust version it has value 7
2021-06-19 20:08:27 +07:00
kana
27b1e05c87 MyPaths are not required and fail
Inputting paths are not necessary and will break ci, we can just leave paths out. We also changed 'master' to main since anyone reading this is probably going to be making mains
2021-06-11 20:21:28 +01:00
Eric Huss
e440094b37 Merge pull request #1573 from ehuss/release-next
Update to 0.4.10
2021-06-08 15:24:58 -07:00
Eric Huss
15cae10ca8 Update to 0.4.10 2021-06-08 15:02:48 -07:00
Eric Huss
dc2062ab36 Merge pull request #1541 from ehuss/id-chapter_begin
Remove chapter_begin id from print output.
2021-06-08 14:55:06 -07:00
Eric Huss
d9ce98d710 Merge pull request #1572 from joshrotenberg/revert-c1b2bec7d7a56909f695f103d316453dab68798e
Revert "book: use non_exhaustive attribute for struct Book"
2021-06-08 14:54:51 -07:00
josh rotenberg
b59aab56f2 Revert "book: use non_exhaustive attribute for struct Book"
This reverts commit c1b2bec7d7.
2021-06-08 12:46:27 -07:00
Eric Huss
b899c48019 Merge pull request #1566 from joshrotenberg/markdown_list_clarification
Documentation clarification on markdown list markers
2021-06-07 15:30:21 -07:00
josh rotenberg
515a253e97 doc clarification on markdown list markers
doc clarification on markdown list markers

shorten
2021-06-06 18:59:53 -07:00
Eric Huss
7ddc3df945 Merge pull request #1550 from sunng87/feature/hbs4
update handlebars to 4.0
2021-06-06 13:04:54 -07:00
Eric Huss
2f7293af5c Merge pull request #1567 from tfidfwastaken/patch-1
Fix typo in documentation
2021-06-06 12:03:36 -07:00
Atharva Raykar
fa3ae53d46 Fix typo in documentation
a very pedantic ommitted -> omitted
2021-06-05 22:50:45 +05:30
Eric Huss
6425c29893 Merge pull request #1562 from ehuss/bump-version
Update to 0.4.9
2021-06-02 09:54:43 -07:00
Eric Huss
d0bb830491 Update to 0.4.9 2021-06-01 18:50:29 -07:00
Eric Huss
d325c601bb Merge pull request #1554 from joshrotenberg/edit_url_custom_src
Use the configured book src directory for the edit url template path
2021-06-01 18:36:32 -07:00
Eric Huss
e9e889f523 Merge pull request #1560 from joshrotenberg/clippy_path_fixes
clippy: PathBuf to Path fixes.
2021-06-01 10:12:08 -07:00
josh rotenberg
e5e10c681a add init flags
add init flags

update init command in guide
2021-05-31 20:47:51 -07:00
josh rotenberg
05edc4421b clippy: PathBuf to Path 2021-05-31 20:27:52 -07:00
Eric Huss
22ea5fe335 Merge pull request #1557 from xrmx/cargo-clippy-fixes
Some clippy fixes
2021-05-31 07:10:30 -07:00
Riccardo Magliocchetti
714c5fb81e renderer: remove redundant clone in CmdRenderer
As suggested by clippy:
https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
2021-05-30 19:33:46 +02:00
Riccardo Magliocchetti
56ceb627b8 book: simplify is_draft_chapter
As suggested by clippy:
https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching
2021-05-30 19:33:46 +02:00
Riccardo Magliocchetti
c1b2bec7d7 book: use non_exhaustive attribute for struct Book
As suggested by clippy:
https://rust-lang.github.io/rust-clippy/master/index.html#manual_non_exhaustive
2021-05-30 19:33:46 +02:00
Eric Huss
8201b411ab Merge pull request #1555 from joshrotenberg/exit_serve_if_panic
Use std::panic::set_hook to exit serve thread if serving fails
2021-05-29 15:12:04 -07:00
Eric Huss
836546cf0d Merge pull request #1544 from joshrotenberg/guide_configuration_restructure
Restructure guide configuration section
2021-05-29 14:46:58 -07:00
Ning Sun
9813802b3e bump msrv to 1.45 as handlebars 4.0 requires 2021-05-28 22:59:56 +08:00
josh rotenberg
fcf8f938d2 use panic::set_hook to exit 2021-05-28 07:40:56 -07:00
josh rotenberg
60aaa7ae31 use book_config.src for edit path
use book_config.src for edit path

use book_config.src for edit path

fmt

concat the path, this is a url
2021-05-27 21:54:58 -07:00
Ning Sun
1b584d1746 update handlebars to 4.0 2021-05-26 23:11:01 +08:00
josh rotenberg
aa4cb9465f restructure guide configuration section
restructure guide configuration section

restructure guide configuration section

redirect to new config top level

fix broken links

use a relative path for redirect

Co-authored-by: Eric Huss <eric@huss.org>

remove extra heading
2021-05-25 07:43:36 -07:00
Eldred Habert
89a2e39b80 Mention missing file creation in build/watch/serve's docs (#1548)
Fixes #1246
2021-05-25 13:45:30 +02:00
Eric Huss
3c2b8cd10f Merge pull request #1539 from joshrotenberg/report_config_errors
Report book.toml parse error when invalid fields are found
2021-05-24 13:25:07 -07:00
josh rotenberg
6b0b42ebcc update build and rust config change 2021-05-24 12:01:56 -07:00
josh rotenberg
7a3513200f Update src/config.rs
Co-authored-by: Eric Huss <eric@huss.org>
2021-05-24 11:59:32 -07:00
Eric Huss
3db0c0b9a1 Merge pull request #1511 from joshrotenberg/example-semver
Use semver crate to validate version compatibility in nop-preprocessor example
2021-05-24 11:10:21 -07:00
Eric Huss
2c7aac6d7a Merge pull request #1542 from ISSOtm/patch-1
Apply max width to video as well as images
2021-05-24 10:33:23 -07:00
Eldred Habert
3ee22fb430 Apply max width to video as well as images
Since videos are essentially animated images, this same max width makes sense for both.
2021-05-23 16:10:26 +02:00
Eric Huss
16c5ec4d74 Remove chapter_begin id from print output. 2021-05-22 15:12:54 -07:00
Eric Huss
7e7e779ef7 Merge pull request #1526 from apatniv/add_log_messages
Add useful messages when command line preprocessor fails
2021-05-21 10:06:36 -07:00
Andrea Gelmini
b364e8ea2c Fix typos (#1540)
Signed-off-by: Andrea Gelmini <andrea.gelmini@gelma.net>
2021-05-21 12:56:32 +02:00
josh rotenberg
78325aaccb report book.toml parse errors
check config for book parse errors

add invalid_title_type

handle build and rust config errors
2021-05-19 09:32:24 -07:00
Eric Huss
1411ea967a Merge pull request #1534 from joshrotenberg/docs/guide-summary-updates
Guide updates: summary.md
2021-05-17 14:38:18 -07:00
josh rotenberg
d147a85006 summary.md updates 2021-05-14 22:05:24 -07:00
Eric Huss
0f0dce8d6c Merge pull request #1530 from anoadragon453/patch-1
Fix a small typo
2021-05-13 16:14:10 -07:00
Andrew Morgan
379574dc61 Fix a small typo
misssing -> missing
2021-05-13 23:55:51 +01:00
Eric Huss
6a7de13c6f Update Cargo.lock, Bump msrv to 1.42 (#1528)
* Update Cargo.lock

* Bump MSRV to 1.42.

There are a few dependencies that require this version.
2021-05-10 20:08:18 +02:00
Eric Huss
331aad1597 Merge pull request #1525 from joshrotenberg/guide/server-command-updates
Update serve documentation in the guide
2021-05-10 09:40:00 -07:00
Eric Huss
7e01cf9e18 Update to 0.4.8 (#1527) 2021-05-10 18:38:43 +02:00
josh rotenberg
c922b8aae6 backquote port 2021-05-08 09:51:30 -07:00
apatniv
b21446898a Add useful messages when command line preprocessor fails 2021-05-08 12:48:57 -04:00
josh rotenberg
f4b4a331d7 consisten note format, update gitignore language 2021-05-07 21:02:55 -07:00
josh rotenberg
aa349e0b7c update serve documentation 2021-05-07 20:29:01 -07:00
Eric Huss
b592b10633 Merge pull request #1519 from tshepang/patch-1
Update init.md
2021-05-05 08:32:52 -07:00
Eric Huss
d62cf8e883 Merge pull request #1520 from apatniv/patch-1
Add entry to contributor section
2021-05-05 08:32:23 -07:00
Vivek Bharath Akupatni
c6844dd771 Add entry to contributor section 2021-05-05 08:42:43 -04:00
Tshepang Lekhonkhobe
009247be01 Update init.md
make sentence more simple
2021-05-05 12:06:56 +02:00
Eric Huss
84b3b7218e Merge pull request #1437 from rust-lang-ja/summary-with-html-comments
Skip HTML nodes in SUMMARY.md
2021-05-04 07:26:03 -07:00
Eric Huss
71ba6c9eb8 Merge pull request #1514 from c-cube/patch-1
more detailed example in summary.md
2021-05-03 17:46:56 -07:00
Simon Cruanes
9d4ee689db Update guide/src/format/summary.md
Co-authored-by: Eric Huss <eric@huss.org>
2021-05-03 20:16:11 -04:00
Simon Cruanes
ffe88d7e29 Update guide/src/format/summary.md
Co-authored-by: Eric Huss <eric@huss.org>
2021-05-03 20:16:05 -04:00
Simon Cruanes
9f930706bb Update guide/src/format/summary.md
Co-authored-by: josh rotenberg <joshrotenberg@users.noreply.github.com>
2021-05-02 21:21:41 -04:00
Simon Cruanes
24fa615149 more detailed example in summary.md
this shows a richer structure of numbered chapters to better illustrate that it uses nested markdown lists.
2021-05-02 11:27:28 -04:00
Eric Huss
a72d6002b7 Merge pull request #1506 from flavio/feature/suggest-an-edit-link
Feature/suggest an edit link
2021-04-26 11:03:50 -07:00
josh rotenberg
5b7abf4714 add semver v0.11.0 for example 2021-04-26 08:08:53 -07:00
josh rotenberg
d0ef70e574 use semver to validate version 2021-04-26 08:08:24 -07:00
Flavio Castelli
7525b35383 Rename git-repository-edit-url-template
Change the name of the git-repository-edit-url-template to be more
generic: `edit-url-template`

Signed-off-by: Flavio Castelli <fcastelli@suse.com>
2021-04-26 09:59:08 +02:00
Eric Huss
b54e73e3b6 Merge pull request #1509 from GuillaumeGomez/duplicate-name
Remove duplicate "name" attribute on input
2021-04-25 20:08:55 -07:00
josh rotenberg
59c76fa665 Reword incomplete sentence in Preprocessors section in the guide (#1510)
* fix and reword incomplete sentence

* remove unused reference
2021-04-26 01:18:57 +02:00
Guillaume Gomez
c1d982d92b Remove duplicate "name" attribute on input 2021-04-24 17:27:49 +02:00
syntezoid
3db275d68a Change in gitlab CI (#1507) 2021-04-23 11:51:42 +02:00
Flavio Castelli
94e797fba0 mdbook book: show edit link
Add "edit" links to the pages of mdbook own book
2021-04-19 19:08:15 +02:00
Flavio Castelli
c3beecc96a Update docs to include example of edit links feature
Add a working example of the edit links feature to the examples
2021-04-19 19:07:37 +02:00
Flavio Castelli
7aff98a859 Fix generation of edit links
The `IndexPreprocessor` rewrites the path for files
named `README.md` to be `index.md`. This breaks the edit link
in some circumstances.

To address this issues, the `Chapter` struct has now a new attribute
called `source_path`. This is initialized with the same value as
`path`, but is never ever changed.

Finally, the edit link is built by using the `source_path` rather
than the `path`.
2021-04-19 18:58:15 +02:00
Jonas Berlin
bbf54d7459 [ReviewFix] Replace edit baseurl with template and make visibility independent of git_repository_url. 2021-04-19 16:16:08 +02:00
Jonas Berlin
dcc642e66d [ReviewFix] cargo fmt 2021-04-19 14:51:16 +02:00
Jonas Berlin
2b738d4425 [ReviewFix] Fix variable naming 2021-04-19 14:51:16 +02:00
Jonas Berlin
b3670ece0e Add "Suggest an edit" link next to "Git repository"
Includes new configuration option `git-repository-edit-baseurl` for
supporting non-GitHub repository layouts.
2021-04-19 14:51:14 +02:00
Tatsuya Kawano
30ce7e79ac Skip HTML comments in the summary
- Revert changes in parse_numbered(). They were unnecessary.
2021-04-05 18:31:11 +08:00
David Tolnay
94f7578576 Add page title override: {{#title My Title}} (#1381)
* Add page title override: {{#title My Title}}

* Document {{#title}} in guide
2021-03-24 02:36:45 +01:00
Eric Huss
e6568a70eb Merge pull request #1485 from Evian-Zhang/add-pagebreak
Add page-break
2021-03-17 09:45:30 -07:00
Evian-Zhang
0eb23efd44 Make page-break not configurable 2021-03-16 09:33:19 +08:00
Evian-Zhang
e78a8471c7 Add page-break option 2021-03-12 14:00:29 +08:00
Paul
dcccd3289d Apply suggestions from code review
improved readability and cleared sections which could have caused more confusion

Co-authored-by: Eric Huss <eric@huss.org>
2021-03-08 20:39:39 +01:00
pauliyobo
5637a66459 hopefully made the documentation more clearer on what concerns preprocessor implementation with non rust languages 2021-03-05 21:11:29 +01:00
Eric Huss
536873ca26 Merge pull request #1478 from camelid/patch-1
docs: Use inline code for regex
2021-03-01 08:15:20 -08:00
Camelid
d6ea4e3f7a docs: Use inline code for regex
And fix a typo.
2021-02-27 20:17:36 -08:00
mbartlett21
fcceee4761 Update examples with hidden lines (#1476)
* Update example.rs to have correct indent

The three hidden lines in example.rs now have four spaces indent for the hidden lines.

* Update mdbook.md
2021-02-27 02:40:14 +01:00
Eric Huss
3f39ba82f9 Merge pull request #1474 from ehuss/bump-version
Update to 0.4.7
2021-02-22 15:44:42 -08:00
Eric Huss
7da38715c1 Update to 0.4.7 2021-02-22 14:56:44 -08:00
Eric Huss
c83bbd6319 Merge pull request #1463 from ehuss/fix-header-scroll
Fix some issues with fragment scrolling and linking.
2021-02-22 14:50:17 -08:00
Eric Huss
fad3c663f4 Merge pull request #1461 from ehuss/guide-repo-link
Add git repository url link to user guide.
2021-02-22 14:50:05 -08:00
Eric Huss
f8b9054265 Merge pull request #1470 from tim-seoss/light_theme_contrast_enhancement
Enhance text contrast of `light` theme to improve accessibility.
2021-02-22 14:49:07 -08:00
Fenhl
f26116a491 Upgrade to shlex 1 (#1471) 2021-02-22 00:15:16 +01:00
Tim Small
7f59fdd9bd Enhance text contrast of light theme to improve accessibility.
The existing light theme has relatively low contrast between the text
(and other UI elements) and background (especially within code blocks).
This presents difficulties for people with reduced visual contrast
perception (common in older adults).

This patch makes changes to the default `light` theme to meet the
minimum contrast requirement of the v2.1 W3C WCAG (Web Content
Accessibility Guidelines)
https://www.w3.org/WAI/WCAG21/quickref/#contrast-minimum

The small size, and slender font used for the title text makes it hard
to read, even with the increased contrast colour scheme, so this patch
also increases the size of the title text font by 20%.

Closes #1442
2021-02-21 14:35:10 +00:00
Eric Huss
45d41eac5f Fix some issues with fragment scrolling and linking. 2021-02-12 16:37:07 -08:00
Eric Huss
2b5890e2ed Add git repository url link to user guide. 2021-02-12 07:34:20 -08:00
Eric Huss
0b9570b160 Merge pull request #1456 from danieleades/typo
fix small typos on 'syntax-highlighting' page
2021-01-30 09:09:37 -08:00
Daniel Eades
90396c5b76 fix small typos on 'syntax-highlighting' page 2021-01-30 08:11:45 +00:00
Eric Huss
24b76dd879 Fix sentence on installation page. 2021-01-15 07:50:06 -08:00
Eric Huss
9a9eb0124a Merge pull request #1447 from ehuss/bump-version
Update to 0.4.6.
2021-01-14 17:36:08 -08:00
Eric Huss
257374d76b Update to 0.4.6. 2021-01-14 17:27:54 -08:00
Eric Huss
1a0c296532 Merge pull request #1426 from ehuss/search-mark-words
Fix search highlighting with multiple words.
2021-01-14 17:01:52 -08:00
Eric Huss
9b4ab72a80 Merge pull request #1418 from ehuss/relative-renderer-command
Fix relative paths for renderer commands.
2021-01-14 17:01:41 -08:00
Eric Huss
b1c2e466e7 Merge pull request #1438 from pierwill/edit-docs
Add intra-docs links to docs
2021-01-13 14:26:44 -08:00
Eric Huss
cdea0f6b61 Add missing parenthesis in doc comment. 2021-01-13 14:26:14 -08:00
pierwill
e9b0be7090 Add intra-docs links to docs
Also fixes some punctuation and changes some wording.
2021-01-10 14:51:30 -08:00
Tatsuya Kawano
d402a12e88 Skip HTML comments in the summary 2021-01-08 18:16:03 +08:00
Tatsuya Kawano
218e200117 Fix a wrong version 0.4.4 in Cargo.toml (Should be 0.4.5) (#1435) 2021-01-07 14:56:21 +01:00
Eric Huss
3d55375f61 Update theme CSS docs. (#1431) 2021-01-07 01:56:20 +01:00
Eric Huss
77e7cfd22b Change init --theme to place theme in root. (#1432) 2021-01-07 01:29:38 +01:00
Eric Huss
76cd39e5e2 Merge pull request #1390 from sburris0/gitlabci
Guide: Add instructions for publishing via GitLab Pages
2021-01-06 13:11:58 -08:00
Eric Huss
09e7bb76dc Remove mark from URL on escape. (#1427) 2021-01-05 19:31:16 +01:00
Eric Huss
28387130c0 Fix search highlighting with multiple words. 2021-01-04 14:20:36 -08:00
Eric Huss
33d3d9c3ec Merge pull request #1389 from avitex/search-chapter-name
Add chapter name to search result breadcrumbs
2021-01-04 14:01:30 -08:00
Alexandru Macovei
beec17e55d Add ability to generate shell completions via clap 2021-01-04 23:51:02 +02:00
Eric Huss
e651f4d734 Merge pull request #1420 from apatniv/clippy_remove_clone
Clippy lint: Remove unnecessary clone
2021-01-04 11:33:37 -08:00
Eric Huss
87d2cd9845 Merge pull request #1421 from apatniv/clippy_use_single_char
clippy: use char instead of str
2021-01-04 11:31:06 -08:00
Pietro Albini
32abeef088 fix xss in the search page
Thanks to Kamil Vavra for responsibly disclosing the vulnerability
according to Rust's Security Policy.
2021-01-04 07:14:57 -08:00
Eric Huss
5de9b6841e Update changelog for 0.4.5 2021-01-04 07:13:30 -08:00
apatniv
95e0743bc0 clippy: use char instead of str 2020-12-31 15:37:34 -05:00
apatniv
3c97525743 Clippy lint: Remove unnecessary clone 2020-12-31 15:18:37 -05:00
Eric Huss
9a65c8ab92 Fix relative paths for renderer commands. 2020-12-30 17:46:29 -08:00
Eric Huss
a64a7b7470 Merge pull request #1405 from francis-du/master
fix: readerer get theme dir path bug
2020-12-28 09:22:11 -08:00
francis-du
fd4137a9ea fix: readerer get theme dir path bug 2020-12-28 09:20:23 -08:00
Vivek Bharath Akupatni
a3d4febe3e Provide useful feedback if user executes command in different folder (#1407)
Provides better feedback if user executes in a different folder than what is expected by mdbook

After the changes `mdbook build`
```
2020-12-19 14:27:35 [ERROR] (mdbook::utils): Error: Couldn't open SUMMARY.md in "/Users/vicky/rust/source_codes/mdbook_testing/src/src" directory
2020-12-19 14:27:35 [ERROR] (mdbook::utils):    Caused By: No such file or directory (os error 2)
```

Previously: `mdbook build`
```
2020-12-19 14:28:46 [ERROR] (mdbook::utils): Error: Couldn't open SUMMARY.md
2020-12-19 14:28:46 [ERROR] (mdbook::utils):    Caused By: No such file or directory (os error 2)
```
2020-12-27 12:45:11 -08:00
Maxime BORGES
7af4b1dfe8 [README] Add optional directory parameter for the init command (#1409)
With the current description of the command, I was expecting to get a directory named with the project name, but the files were created in the current directory.
I Think a more precise description would help first-time users.
2020-12-23 10:03:31 -08:00
Eric Huss
ba6bffac5a Merge pull request #1410 from maximeborges/patch-2
[guide/format/theme/index-hbs] `chapter_title` and `book_title` are inverted
2020-12-23 08:55:46 -08:00
Maxime BORGES
6201e577fe [guide/format/theme/index-hbs] chapter_title and book_title are inverted
Looking into the code, we can confirm that the implementation is `{{ chapter_title }} - {{ book_title }}` and not `{{ book_title }} - {{ chapter_title }}` as written in the guide:
4c951d530d/src/renderer/html_handlebars/hbs_renderer.rs (L69)
2020-12-22 22:36:58 +01:00
Eric Huss
cf2459f730 Merge pull request #1393 from apatniv/fixing_error
Missing chapters Error Reporting: Add file name
2020-12-14 08:33:36 -08:00
Eric Huss
45a481049e Merge pull request #1399 from u7693/issue-1396
Show path in the error message (#1396)
2020-12-14 08:08:05 -08:00
Kousuke Takaki
6bcabcbb6b Improve error message 2020-12-14 16:11:01 +09:00
apatniv
ef993e8cc2 Run rust formmater 2020-12-05 20:27:03 -05:00
apatniv
a3a5386da0 Add more context regarding which missing file creation failed 2020-12-05 20:17:45 -05:00
Eric Huss
3ab911afa1 Merge pull request #1392 from lzanini/master
Add Katex preprocessor to 3rd Party Plugins
2020-12-04 10:53:21 -08:00
Spencer Burris
4615ce2f8c Remove --debug from GitLab CI 2020-12-04 09:12:00 -08:00
Lucas Zanini
7cb8087469 katex preprocessor
Added the katex preprocessor to the list of 3rd Party Plugins
2020-12-03 23:54:12 +01:00
Spencer Burris
d1721667b6 Add instructions for publishing via GitLab Pages 2020-12-01 13:25:28 -08:00
avitex
1038f0b7f5 Fix search index tests 2020-11-26 09:02:11 +11:00
avitex
942cc12a74 Add chapter name to search result breadcrumbs 2020-11-25 14:46:49 +11:00
Eric Huss
59f2a9bf4e Merge pull request #1373 from avisionh/docs/ci-guide-update
Docs: CI guide update
2020-11-13 08:19:52 -08:00
A Ho
75d0f1efd4 Suggest dplyv2 changes to .travis.yml as a note
This is following @ehuss' comment to not recommend something currently in beta release.
2020-11-13 09:40:33 +00:00
Eric Huss
552e3378cf Merge pull request #1378 from daynin/serialize-build-section
allow to serialize the "build" section
2020-11-12 10:41:12 -08:00
Sergey Golovin
7c0ddff96a allow to serialize the "build" section 2020-11-12 19:32:32 +03:00
Eric Huss
07e72757d3 Merge pull request #1376 from dtolnay/html
Escape `<` and `>` in rendered toc to match handlebars' escaping in <title>
2020-11-10 14:46:24 -08:00
Eric Huss
58f66a146d Merge pull request #1375 from dtolnay/playground
Fix stray spacing after #playground code
2020-11-10 14:06:09 -08:00
Eric Huss
643d5ecc5c Merge pull request #1285 from FrankHB/patch-1
Handled UTF-8 BOM
2020-11-10 14:02:01 -08:00
David Tolnay
c712ba7aab Escape <> in rendered toc 2020-11-08 22:26:30 -08:00
David Tolnay
1450070f73 Fix stray spacing after #playground code 2020-11-05 21:43:04 -08:00
A Ho
e310dfc605 Add avisionh to contributors
This is for contributing to the travis deployments chapter.
2020-11-05 22:28:54 +00:00
A Ho
cbfd75a821 Update CI section in guide for travis dpl-v2
This is so that the instructions work when deploying the book to GitHub pages via the gh-pages branch.
2020-11-05 21:43:52 +00:00
Eric Huss
eaa6914205 Merge pull request #1360 from ehuss/release-next
Release 0.4.4
2020-10-20 08:06:27 -07:00
Eric Huss
a76557a678 Release 0.4.4 2020-10-20 07:58:24 -07:00
Eric Huss
01836ba5d4 Merge pull request #1348 from ehuss/github-deprecated-action-commands
Update deprecated GitHub Actions commands.
2020-10-20 07:48:26 -07:00
Eric Huss
46ce077de6 Update deprecated GitHub Actions commands. 2020-10-08 10:00:06 -07:00
Eric Huss
f7c9180d80 Fix typo in changelog 2020-10-08 09:46:39 -07:00
FrankHB
9e9cf49c50 Added a test.
Signed-off-by: FrankHB <frankhb1989@gmail.com>
2020-10-07 22:50:25 +08:00
Camelid
4c951d530d List supported Highlight.js languages in guide (#1345)
* List supported Highlight.js languages in guide

Generated using the technique described in
https://github.com/rust-lang/mdBook/issues/1275#issuecomment-655903967.

* Improve wording in guide
2020-09-30 01:56:31 +02:00
FrankHB
780fb979a0 Avoided the redundant allocation.
Signed-off-by: FrankHB <frankhb1989@gmail.com>
2020-09-29 18:01:06 +08:00
Camelid
b77942d3c8 Rename book-example to guide (#1336)
`book-example` is a bit of a strange name given that it's not just an
example.
2020-09-23 03:16:09 +02:00
Eric Huss
d0deee90b0 Merge pull request #1335 from ehuss/fix-print
Fix print icon.
2020-09-22 13:34:15 -07:00
Eric Huss
e6ac8ecdd9 Fix print icon. 2020-09-22 13:24:13 -07:00
Eric Huss
d1f5ecc103 Merge pull request #1169 from rossmacarthur/ft/no-print
Add config option to disable print html, css, and icon
2020-09-22 11:50:22 -07:00
Ross MacArthur
e0b247e9d6 Add config option to disable print html, css, and icon 2020-09-22 11:40:02 -07:00
Eric Huss
db8a2821ea Merge pull request #1323 from iffyio/copy-symlinks
Resolve full file paths when copying files
2020-09-22 10:51:50 -07:00
Eric Huss
39d7130019 Merge pull request #1325 from camelid/patch-2
Improve README wording
2020-09-12 06:19:41 -07:00
Camelid
2eccb457d2 gitignore: Ignore Vim temporary and swap files (#1328) 2020-09-11 15:10:38 +02:00
Camelid
d1682d27fb Improve README wording 2020-09-10 13:28:24 -07:00
Eric Huss
a94a940ff7 Fix macOS CI deploy take 2. 2020-09-09 12:05:14 -07:00
Eric Huss
daf402e1dc Merge pull request #1324 from ehuss/purge
Fix macOS CI deploy.
2020-09-09 11:47:00 -07:00
Eric Huss
5ebd2c0527 Fix macOS CI deploy. 2020-09-09 10:00:48 -07:00
ifeanyi
b349e8abc9 Fix windows typo 2020-09-09 17:57:45 +02:00
ifeanyi
e225586953 Resolve full file paths when copying files
Currently, the `copy_files` function doesn't support symlink files due to
its use of `DirEntry::metadata` - To avoid this issue, this patch
resolves the file path first before checking for metadata.

Fixes #1157
2020-09-09 17:42:14 +02:00
Eric Huss
cf7663f800 Merge pull request #1317 from ehuss/release-next
Release 0.4.3
2020-09-08 08:21:17 -07:00
Eric Huss
3155c63e88 Release 0.4.3 2020-09-08 08:06:05 -07:00
Eric Huss
4df9ec90af Merge pull request #1307 from camelid/prefer-bundled-scp
Prefer bundled version of Source Code Pro
2020-09-06 10:58:23 -07:00
Camelid
73cabeb904 Remove local version from @font-face
It's unlikely that the bundled version wouldn't load, and it's
especially unlikely that the page would load but the bundled version
would not.

Also, if it doesn't load, it should fall back to another monospace font,
which is fine.
2020-09-06 10:34:11 -07:00
Eric Huss
4b773024ae Merge pull request #1309 from nerosnm/add-missing-space
Fix missing space before draft chapter titles
2020-09-06 09:40:55 -07:00
Eric Huss
33ea661350 Merge pull request #1310 from dtolnay/nojekyll
End .nojekyll file with newline
2020-09-06 09:21:59 -07:00
Eric Huss
1b18740b56 Merge pull request #1311 from dtolnay/cname
Support emitting CNAME file for publishing at a custom domain
2020-09-06 09:21:29 -07:00
Eric Huss
6fed9e52f9 Merge pull request #1313 from guswynn/master
collect all test failures before failing
2020-09-06 09:12:42 -07:00
Eric Huss
fd59dc73e5 Adjust wording 2020-09-06 09:11:53 -07:00
Eric Huss
146bea48c6 Merge pull request #1314 from camelid/patch-1
Fix grammar
2020-09-06 08:59:11 -07:00
Camelid
efb5bc285d Fix grammar
who -> which
2020-09-04 13:21:37 -07:00
Gus Wynn
5ea8e55aea collect all test failures before failing 2020-09-03 18:36:51 -07:00
David Tolnay
1acf23ff73 Support emitting CNAME file for publishing at a custom domain 2020-09-02 11:24:48 -07:00
David Tolnay
69cc1fa005 End .nojekyll file with newline
Before:

    /path/to$  cat book/.nojekyll
    This file makes sure that Github Pages doesn't process mdBook's output./path/to$  ▎

After:

    /path/to$  cat book/.nojekyll
    This file makes sure that Github Pages doesn't process mdBook's output.
    /path/to$  ▎
2020-09-02 11:06:19 -07:00
Søren Mortensen
2fb489137b Wrap draft chapter titles in a <div>
Fixes the problem of a missing space before the title of draft chapters,
due to the title not being wrapped in an `<a></a>`.
2020-08-31 10:00:03 +01:00
Camelid
4d9eb9b4b4 Prefer bundled version of Source Code Pro
This prevents an issue with Firefox 80 on macOS that prevents syntax
highlighting from working.
2020-08-29 13:22:51 -07:00
Eric Huss
f6768b816c Fix release script LTO. 2020-08-11 15:39:03 -07:00
Eric Huss
8f7e030ac3 Merge pull request #1299 from ehuss/release-next
Release 0.4.2
2020-08-11 15:28:01 -07:00
Eric Huss
9180dd1659 Release 0.4.2 2020-08-11 15:19:39 -07:00
Eric Huss
9278b838a8 Merge pull request #1298 from FabienTregan/adding_info_about_markdown_flavor
Adds information about markdown flavor in the documentation.
2020-08-10 10:46:53 -07:00
Fabien Tregan
2674347768 Adds information about markdown flavor in the documentation. 2020-08-10 10:52:22 +02:00
Eric Huss
3d44553671 Merge pull request #1293 from Evian-Zhang/master
allow space in SUMMARY.md's link destination
2020-08-08 08:19:06 -07:00
Evian-Zhang
9d5c454e47 delete '+' replacement and use cargo fmt to format 2020-08-08 15:13:22 +08:00
Eric Huss
a00e7d1769 Merge pull request #1272 from ehuss/fix-favicon-link
Fix favicon when only one is overridden.
2020-08-07 08:34:46 -07:00
Evian-Zhang
60be20a783 allow space in SUMMARY.md's link destination 2020-08-03 09:49:01 +08:00
Eric Huss
8746206060 Merge pull request #1284 from ericonr/opt
Mention that uninstalled backend isn't marked optional.
2020-07-30 20:22:55 -07:00
Eric Huss
f5ae7c4f13 Merge pull request #1291 from ericonr/fix-break
summary: turn SoftBreak events into spaces.
2020-07-30 20:05:07 -07:00
Érico Rolim
dcf9462d1e summary: turn SoftBreak events into spaces.
Summary items that had their name split into two lines ended up with the
last word of one line and the first word of the next line glued
together, since a space wasn't added.

Added test case for it.

Fixes #1218
2020-07-29 15:53:27 -03:00
Érico Rolim
78aa2a16f8 Mention that uninstalled backend isn't marked optional.
If an uninstalled backend (command not found) isn't marked optional,
warn about it, since it causes mdbook commands to error out.

Fixes #1283
2020-07-28 18:08:32 -03:00
FrankHB
65d9eb6f7e Handled UTF-8 BOM
Fixed #1155 .
2020-07-25 13:02:44 +08:00
Eric Huss
303db0ddec Merge pull request #1277 from maniyar1/patch-1
Update highlight.js
2020-07-21 14:17:03 -07:00
Eric Huss
a884c2574e Merge pull request #1281 from onelson/more-obvious-show-hidden
Change "show hidden lines" icon to "eye" instead of "expand."
2020-07-21 12:23:14 -07:00
maniyar1
60029e4e15 Add R-lang support 2020-07-20 19:03:29 -04:00
Yuki Okushi
4e16d96ed5 Mention removed features (#1282) 2020-07-19 21:32:21 +02:00
Owen Nelson
0eefd63a13 Change "show hidden lines" icon to "eye" instead of "expand."
In a recent discussion in the amethyst docs discord channel,
it was suggested that using an "eye" icon might make the show hidden
lines feature of mdbook's code sample rendering more discoverable.

I myself overlooked the arrows that are in use now.

Fixes #663 at least in part.
2020-07-16 19:27:18 -07:00
Eric Huss
89c2743cc6 Merge pull request #1280 from bikeshedder/fix-title-doc
Fix documentation for title and book_title
2020-07-16 10:04:44 -07:00
Michael P. Jung
a825427722 Fix documentation for title and book_title 2020-07-16 16:43:46 +02:00
maniyar1
c99047bbda Update highlight.js
Updates to 10.1.1, with support for new languages added to the common set.
Built with:
common languages + D, handlebars, haskell, julia, scala, x86asm, armasm, yaml
Size difference:
New highlight.js: 132KiB
Old highlight.js: 84KiB
--
New highlight.js compressed: 48KiB
Old highlight.js compressed: 36KiB
2020-07-09 14:01:51 -04:00
Eric Huss
20a0b99c3d Fix favicon when only one is overridden.
A mistake in #1266, I neglected to also update the <link> generation
to elide the link if one of the favicon images is not included.
2020-07-08 12:44:07 -07:00
Eric Huss
ec495a7823 Merge pull request #1273 from ehuss/fix-ci-rustup
Fix CI due to new rustup.
2020-07-08 10:59:14 -07:00
Eric Huss
e38fb1ecc6 Fix CI due to new rustup. 2020-07-07 14:08:51 -07:00
Eric Huss
f37ea9a4e7 Merge pull request #1269 from ehuss/update-changelog
Update changelog.
2020-07-03 09:07:21 -07:00
Eric Huss
8f74804c70 Update changelog. 2020-07-03 08:52:46 -07:00
Eric Huss
649f3555e5 Merge pull request #1266 from ehuss/favicon-no-default
Don't copy default favicon if at least one is overridden.
2020-07-03 08:47:34 -07:00
Eric Huss
8432df1e80 Merge pull request #1265 from ehuss/part-title-active
Fix sidebar scrolling with part titles.
2020-07-03 08:34:52 -07:00
Igor Matuszewski
9eba9ed93a Update select dependency to 0.5 (#1267)
This allows to prune some of the old transitive dependencies from the
dep tree. In particular, this gets rid of <1.0 syn and related crates.
2020-06-30 19:11:09 +02:00
Eric Huss
b0c6f2d7a3 Don't copy default favicon if at least one is overridden. 2020-06-27 16:30:46 -07:00
Eric Huss
6e0688afef Update changelog, add note about SVG icon. 2020-06-27 15:37:13 -07:00
Eric Huss
e9951af73e Fix sidebar scrolling with part titles. 2020-06-24 21:13:02 -07:00
Eric Huss
138dc696b7 Merge pull request #1264 from ehuss/update-changelog
Update changelog.
2020-06-23 11:45:04 -07:00
Eric Huss
91b2fb86bf Update changelog. 2020-06-23 11:44:05 -07:00
Eric Huss
d4df7e7cdd Merge pull request #1230 from ehuss/favicon-svg
Add SVG favicon.
2020-06-23 11:34:03 -07:00
Eric Huss
4699269e49 Add SVG favicon. 2020-06-23 10:58:10 -07:00
Eric Huss
c1ed6ee108 Merge pull request #1228 from ehuss/fix-dest-dir
Fix dest-dir command-line flag.
2020-06-23 10:55:38 -07:00
Eric Huss
f59cfe7e2f Fix dest-dir command-line flag. 2020-06-23 10:55:01 -07:00
Eric Huss
9268884b17 Merge pull request #1221 from manuel-woelker/fb-539-not-found-page
Generate 404.html page (#539)
2020-06-23 10:48:08 -07:00
Eric Huss
4f435c62e6 Merge pull request #1249 from ThePuzzlemaker/thepuzzlemaker-stylepatch
Fix issue where Font Awesome overrides `.hidden`'s `display: none`
2020-06-22 12:28:09 -07:00
Eric Huss
9a97f0a096 Fix init creating empty [rust] table. (#1233) 2020-06-22 16:36:37 +02:00
Eric Huss
bc23d08fa5 Rename playpen to playground. (#1241)
looks good
2020-06-22 16:34:25 +02:00
ThePuzzlemaker
84d848f292 Fix issue where Font Awesome overrides .hidden's display: none 2020-06-10 12:55:22 -05:00
Manuel Woelker
d7df832cce fix test and formatting 2020-06-10 15:33:09 +02:00
Manuel Woelker
406b325c54 fix usage of newly stablized inner_deref/as_deref 2020-06-10 13:09:18 +02:00
Manuel Woelker
6d6e5407a3 document: config 404 config parameters output.html.site-url and output.html.site-url 2020-06-10 12:46:23 +02:00
Manuel Woelker
06efa7a675 additional changes to the 404 mechanism based on feedback:
- removed config output_404
 - ensure serve overrides the site url, and hosts the correct 404 file
 - refactor 404 rendering into separate fn
 - formatting
2020-06-10 12:46:23 +02:00
Manuel Woelker
bff36e7229 Add the config parameter output.html.site-url to set base url of the 404 page, making links and relative script/css loads behave correctly even in subdirectory paths 2020-06-10 12:46:23 +02:00
Manuel Woelker
cda28bb618 Generate 404.html page (#539) 2020-06-10 12:46:23 +02:00
Eric Huss
fe1ba71d45 Merge pull request #1199 from ehuss/preferred-dark-theme
Change default preferred-dark-theme to `navy`.
2020-06-08 12:38:06 -07:00
Eric Huss
23f5ffd6d6 Change default preferred-dark-theme to navy. 2020-06-08 11:40:38 -07:00
Eric Huss
484e5c0b8f Merge pull request #1244 from brycefisher/dont-open-search-bar-when-in-text-input
fix: don't jump away from form input to search bar
2020-06-07 13:19:03 -07:00
Eric Huss
a80febd318 Merge pull request #1245 from nihaals/improve-ga-doc
Improved Google Analytics example
2020-06-07 13:14:12 -07:00
Nihaal Sangha
16010ee28b Improved Google Analytics example 2020-06-06 18:05:32 +01:00
Bryce Fisher-Fleig
fb1476d1e3 fix: don't jump away from form input to search bar
Addresses #1020 with the suggestion from prior PR #1101
2020-06-04 14:35:49 -07:00
Eric Huss
b375f4e3d5 Merge pull request #1237 from Michael-F-Bryan/redirects
Implement URL redirecting
2020-05-30 10:30:09 -07:00
Eric Huss
25ec7ace1a Fix typo for redirect TOML. 2020-05-30 10:27:38 -07:00
Michael-F-Bryan
ebc01dbb71 Updated the test to follow our docs 2020-05-30 04:15:24 +08:00
Michael-F-Bryan
7b3e945a27 Updated the test to reflect how redirect keys should be absolute 2020-05-30 04:11:11 +08:00
Michael-F-Bryan
964a10ff29 Redid the wording in the docs because it was around the wrong way 2020-05-30 04:09:43 +08:00
Michael-F-Bryan
5907caa732 I should have used a more realistic example 2020-05-27 03:19:24 +08:00
Michael-F-Bryan
da55cf273f Changed redirect mapping to HashMap<String, String> and improved error handling 2020-05-27 03:12:57 +08:00
Michael-F-Bryan
a6ab4d8402 Explained how you can configure redirects 2020-05-27 02:52:59 +08:00
Michael-F-Bryan
4c2318922f Added integration tests to make sure files are redirected as intended 2020-05-27 02:43:01 +08:00
Michael-F-Bryan
b2d50392ea Emit redirects towards the end of the rendering process 2020-05-27 02:42:56 +08:00
Michael-F-Bryan
a5086a1e58 Added a redirect map to the HTML config 2020-05-27 02:38:04 +08:00
Eric Huss
6c4c3448e3 Update dependencies. (#1211)
* Removed the itertools dependency

* Removed an unused feature flag

* Stubbed out a toml_query replacement

* Update dependencies.

* Bump env_logger.

* Use warp instead of iron for http server.

Iron does not appear to be maintained anymore. warp/hyper seems to be
reasonably maintained. Unfortunately this takes a few seconds more
to compile, but shouldn't be too bad.

One benefit is that there is no longer a need for a separate websocket
port, which makes it easier to run multiple servers at once.

* Update pulldown-cmark to 0.7

* Switch from error-chain to anyhow.

* Bump MSRV to 1.39.

* Update elasticlunr-rs.

Co-authored-by: Michael Bryan <michaelfbryan@gmail.com>
2020-05-20 23:32:00 +02:00
Eric Huss
5d5c55e619 Merge pull request #1171 from mark-i-m/master
implement support for book parts
2020-05-20 12:17:45 -07:00
Eric Huss
e2023fd72d Tweak wording of documentation for part titles. 2020-05-20 12:17:17 -07:00
Eric Huss
e677b72eb8 Merge pull request #1188 from pheki/remove-google-surveillance
Remove google fonts by serving them locally
2020-05-20 11:01:07 -07:00
Aphek
7e090ca42f Also copy font licenses when copy-fonts is enabled 2020-05-19 03:17:01 -03:00
Aphek
122c988477 Rename config from no-copy-fonts to copy-fonts 2020-05-19 03:09:25 -03:00
mark
d0fe9bd41c make part titles another SummaryItem 2020-05-18 11:18:14 -05:00
mark
b1ccb30220 update docs 2020-05-17 17:00:03 -05:00
mark
91e3aa4b55 try to satisfy msrv? 2020-05-17 16:53:06 -05:00
mark
2d63286c63 make part titles bold 2020-05-17 16:53:06 -05:00
mark
5dd2a5bff4 implement support for book parts 2020-05-17 16:53:06 -05:00
Eric Huss
1b3b10d2ae Do not allow the sidebar to be dragged outside the window. (#1229) 2020-05-17 22:05:12 +02:00
Aphek
2c26c65f4d Remove google fonts by serving them locally
Co-authored-by: Aral Balkan <aral@ind.ie>
Co-authored-by: Collyn O'Kane <47607823+okaneco@users.noreply.github.com>
2020-05-15 02:48:28 -03:00
Eric Huss
e8d4bc52e1 Merge pull request #1215 from ehuss/block-cleanup
Remove some unnecessary blocks.
2020-05-10 09:35:46 -07:00
Eric Huss
6038af292f Remove some unnecessary blocks. 2020-05-10 09:23:40 -07:00
Eric Huss
578e4da5b6 Merge pull request #1153 from azerupi/draft-chapters
Bring back draft chapters
2020-05-10 09:18:02 -07:00
Mathieu David
43008ef2ef fix issues from code review 2020-05-10 09:04:02 -07:00
Mathieu David
d605938886 Bring back draft chapters 2020-05-10 09:04:02 -07:00
Eric Huss
7e11d37e49 Merge pull request #1206 from GillesRasigade/html-head-custom
HTML head customisation with `head.hbs`
2020-05-10 08:57:23 -07:00
Eric Huss
50bcf67f2b Consistent punctuation. 2020-05-10 08:42:53 -07:00
Gilles Rasigade
c2d58158da Revert HTML auto-formatting 2020-05-10 08:42:53 -07:00
Gilles Rasigade
1731779a8d Add header.hbs template documentation 2020-05-10 08:42:53 -07:00
Gilles Rasigade
f7e349d37f Add head.hbs template documentation 2020-05-10 08:42:53 -07:00
Gilles Rasigade
61c8413138 Allow to define own HTML <head> attributes
Create a `index.hbs` template file to render additional HTML <head> attributes
2020-05-10 08:42:53 -07:00
Eric Huss
8ee950e3de Merge pull request #1214 from ehuss/fix-clippy
Fix some clippy warnings.
2020-05-10 08:39:19 -07:00
Eric Huss
c44ef1b2f0 Fix some clippy warnings. 2020-05-10 08:29:50 -07:00
Eric Huss
07dfc4b89a Merge pull request #1207 from toyboot4e/fix-mdbook_book
Enable `MDBOOK_BOOK`  to overwrite `book.toml`
2020-05-08 06:51:21 -07:00
toyboot4e
282e55122e Update src/config.rs
Co-authored-by: Eric Huss <eric@huss.org>
2020-05-08 19:56:41 +09:00
Eric Huss
17210b058f Merge pull request #1208 from uint/links-preprocessor-support-pluses
#1098 Links preprocessor: support pluses
2020-05-07 15:36:42 -07:00
Tomasz Kurcz
b1cf3f117d Links preprocessor: support pluses in file paths 2020-05-03 14:50:03 +02:00
Tomasz Kurcz
d665732056 Links preprocessor: test links with special characters 2020-05-03 14:42:22 +02:00
toyboot4e
2f59dbf1ef Fix example of MDBOOK_BOOK (again) 2020-05-03 18:58:41 +09:00
toyboot4e
3a63276727 Not to use matches! 2020-05-03 18:16:44 +09:00
toyboot4e
4c64f23089 Fix example of MDBOOK_BOOK 2020-05-03 17:54:35 +09:00
toyboot4e
683d2b2240 Fix use of MDBOOK_BOOK 2020-05-03 17:54:17 +09:00
Eric Huss
11f95f76e6 Merge pull request #1122 from segfaultsourcery/zero-exit-code-when-plugin-not-found-893
Fixed zero exit code when plugin not found
2020-04-21 15:42:52 -07:00
Eric Huss
2732c5e8f7 Update docs and tweak error messages. 2020-04-21 15:34:59 -07:00
Kim Hermansson
6b550cb4bb Make missing backends optional. 2020-04-21 15:13:14 -07:00
Eric Huss
712362f9e7 Merge pull request #1163 from kngwyu/kpp-edition2018
Make new [rust] section to config and  place edition under it
2020-04-21 13:00:15 -07:00
Eric Huss
28ce8f5ac0 Some edition cleanup and fixes. 2020-04-21 12:26:48 -07:00
kngwyu
255756cfee Make new [rust] config and move edition config under it 2020-04-21 10:24:47 -07:00
Gabriel Majeri
53d821bf6d Add edition to hbs renderer 2020-04-21 10:24:47 -07:00
Gabriel Majeri
d39d4517aa Add support for Rust edition 2020-04-21 10:24:47 -07:00
Eric Huss
bd0f434225 Merge pull request #1164 from zdenek-crha/doc_gitignore_use
Mention that .gitignore is used for watch excludes (#1160)
2020-04-21 10:21:34 -07:00
Eric Huss
3806d7b6ea Merge pull request #1197 from ehuss/release-0.4.0
Start 0.4.0 release.
2020-04-20 09:58:13 -07:00
Eric Huss
d1b484ff35 Start 0.4.0 release. 2020-04-20 09:44:18 -07:00
Eric Huss
04c04dfc88 Merge pull request #1195 from englishm/me/suppress-more-warnings-for-small-listings
Broaden scope of suppressed warnings for listings without a main fn
2020-04-18 08:33:30 -07:00
Mike English
1d265fd143 Broaden scope of suppressed warnings for listings without a main fn
At present, code listings without a main function will be wrapped in one and
annotated with an allow lint check attribute provided by the following [code][]:

```
format!(
    "\n# #![allow(unused_variables)]\n{}#fn main() {{\n{}#}}",
    attrs, code
)
```

A broader lint check attribute such as `#![allow(unused)]` seems like it might
better fit the apparent intent of this code.

Addresses: https://github.com/rust-lang/mdBook/issues/1192

[code]: 769cc0a7c1/src/renderer/html_handlebars/hbs_renderer.rs (L635-L638)
2020-04-18 01:36:11 -04:00
Eric Huss
8e673c96c2 Release 0.3.7 2020-04-03 12:55:41 -07:00
Eric Huss
99ecd4f87c Merge pull request #1170 from ehuss/fix-theme-focus
Fix theme selector focus.
2020-04-03 12:45:33 -07:00
Eric Huss
e839ef0866 Fix sidebar line-height. (#1182) 2020-04-03 21:09:23 +02:00
Eric Huss
769cc0a7c1 Merge pull request #1026 from andrewdavidmackenzie/master
Avoid a possible recursive copy when destination (build_dir) is underneath source directory
2020-04-03 11:18:58 -07:00
Andrew Mackenzie
c2686a817a Address PR review comments 2020-04-03 10:39:15 -07:00
Andrew Mackenzie
bd14d0910a Avoid a possible recursive copy when destination (build_dir) is underneath source directory. Update docs to match. 2020-04-03 10:39:15 -07:00
Eric Huss
6eb597a556 Revert "Assure copy_files_except_ext(..) won't copy directories into itself (#1135)" (#1181)
This reverts commit d7a2b29f06.
2020-04-03 19:12:43 +02:00
Zdenek Crha
5c91041dad Mention that .gitignore is used for watch excludes (#1160)
The serve and watch commands use .gitignore file in book root directory
to read exclude patterns used when watching for changed files. A
.gitignore from parent directory or user home is not used though.

Add documentation of this behaviour to both commands.
2020-03-28 19:33:20 +01:00
Dylan DPC
59568208ff Revert "Support anchors in SUMMARY (#1173)" (#1175)
This reverts commit 2baed040c2.
2020-03-24 23:52:24 +01:00
Eric Huss
21a16c9b75 Scroll sidebar to middle instead of top. (#1161)
* Fix: Scroll sidebar to current active section (#1067)

* Clean: Some code related to PR #1052

* Change `scrollIntoViewIfNeeded` with `scrollIntoView`

* Don't use onload event for sidebar scroll to reduce flickering.

Co-authored-by: 李鸿章 <poodll@163.com>
2020-03-24 21:08:53 +01:00
Eric Huss
4e8e1e1408 Don't highlight code spans in headers. (#1162) 2020-03-24 20:43:20 +01:00
Martin Carton
2baed040c2 Support anchors in SUMMARY (#1173)
* Parse anchors in `SUMMARY.md`

* Support sub-links in SUMMARY with html renderer

* Add some tests for anchors
2020-03-24 19:15:28 +01:00
Mathieu David
101063093b Change CI badge to only push events (#1174)
I noticed that the CI badge was failing and it seems to be caused by the fact that it reflects the latest build including PRs. This change filters the events to only "push events on the master branch" so the badge stays green even if a PR fails.
2020-03-23 13:22:12 +01:00
Eric Huss
f7ffffbd1e Fix theme selector focus. 2020-03-20 11:12:42 -07:00
Eric Huss
760c9b0767 Bump quote and failure.
quote 1.0.2 was yanked, update failure to stay compatible.
2020-03-19 12:48:54 -07:00
Eric Huss
6016e12b90 Release 0.3.6. 2020-03-19 12:43:22 -07:00
Eric Huss
88684d843d Merge pull request #1167 from dalance/fix_summary_comment
Fix SUMMARY's parse_numbered with comment
2020-03-17 21:39:25 -07:00
dalance
b82562fe8a Fix SUMMARY's parse_numbered with comment 2020-03-18 12:28:27 +09:00
Eric Huss
44c3213f5d Merge pull request #1130 from sunng87/feature/handlebars-3.0
Update handlebars to 3.0
2020-03-08 18:54:39 -07:00
Dylan DPC
fd56a53e76 ui: improve menu folding (#989)
* ui: improve menu folding

Fold/unfold the menu bar just by the amount of scroll, not by its
full width

* refactor: use a variable for the menu bar height

* Fix menu scroll jittering, remove hover folding smoothness

Rewrite it to use `position:` `sticky` and `relative` instead
of continuous programmatic position changes

On-hover folding-unfolding transition removal is a side-effect
2020-03-06 01:11:37 +01:00
Dylan DPC
ca4b85b815 Increases line height for p, ul & ol (#1136) 2020-03-06 01:06:19 +01:00
Sebastian Thiel
d7a2b29f06 Assure copy_files_except_ext(..) won't copy directories into itself (#1135)
This prevents recursive copy-loops when the destination directory
is contained in the source directory.

Now it bails out with a descriptive error message.
2020-02-29 19:20:55 +01:00
Eric Huss
4039c72fd3 Merge pull request #1150 from EvanCarroll/master
Support rel=next and rel=previous
2020-02-18 07:55:40 -08:00
Evan Carroll
2bd8bdf798 Support rel=next and rel=previous
This resolves GH #1149
2020-02-18 09:20:17 -06:00
Sergey Pedan
0da7ba4abe Corrects inner/outer space in sidebar <li>s (#1137) 2020-02-17 22:04:59 +01:00
Eric Huss
d6cfa21fff Merge pull request #1145 from Rosto75/master
Add a case for an empty `book_title` parameter
2020-02-15 16:11:08 -08:00
Tomasz Różański
95fba3f357 Add a case for an empty book_title parameter
Html page title for every chapter in the book is created by the following code:
```rust
let title: String;
{
	let book_title = ctx
	.data
	.get("book_title")
	.and_then(serde_json::Value::as_str)
	.unwrap_or("");

	title = ch.name.clone() + " - " + book_title;
}
```

If the `book.toml` file is missing, and `book_title` parameter is empty, there's an awkward ` - ` string hanging at the end of each chapter's title.

This PR adds a `match` case to handle that kind of situation.
2020-02-15 23:13:37 +01:00
Eric Huss
d5999849d9 Merge pull request #1140 from willkg/patch-1
Fix typo in README.md
2020-02-06 08:47:57 -08:00
Will Kahn-Greene
8b2659e0f4 Fix typo in README.md 2020-02-06 11:39:37 -05:00
Eric Huss
c4a64ab599 Merge pull request #1133 from EverlastingBugstopper/avery/fix-derive-highlighting
fix: ayu theme meta highlighting
2020-01-31 18:59:22 -08:00
Eric Huss
6b4e3584b4 Merge pull request #1131 from ehuss/fix-rustup-ci
Fix CI: Don't update rustup.
2020-01-31 08:46:01 -08:00
Avery Harnish
b8fc7a1b2d fix: ayu theme meta highlighting 2020-01-30 09:57:45 -06:00
Eric Huss
2ee083dfbe Fix CI: Don't update rustup. 2020-01-27 13:46:42 -08:00
Ning Sun
1947f8ca65 Update handlebars to 3.0 2020-01-24 11:01:44 +08:00
Eric Huss
2f59943c04 rustfmt with 1.40
Some slight changes in formatting in 1.40.
2019-12-31 16:23:25 -08:00
Eric Huss
980f943179 Merge pull request #1123 from j127/patch-1
Fix typo in init.md
2019-12-31 15:49:29 -08:00
Josh
5e998788e9 Fix typo in init.md
"where" was spelled "were"
2019-12-31 15:36:12 -08:00
Arashmidos
6a94492238 fix scroll issue (#1108)
* fix sidebar scrolling

* fix query selector
2019-12-02 11:07:24 +01:00
Aleksey Kladov
e3717ad47b Add --features to CI recipe (#1103) 2019-11-30 01:10:11 +01:00
nickelc
49b7f08164 Fix doc comment of BuildConfig::create_missing (#1104) 2019-11-29 06:22:21 +01:00
Eric Huss
7def6d70e8 Merge pull request #1099 from Michael-F-Bryan/expose-execute-build-process
Exposed the MDBook::execute_build_process() method to 3rd parties
2019-11-23 10:44:58 -08:00
Eric Huss
554f29703f Merge pull request #1097 from dylanowen/cache
Prevent scrolling to the top of the page on websocket reload
2019-11-19 11:57:43 -08:00
Michael Bryan
730d7f8410 Exposed the execute_build_process() method to 3rd parties 2019-11-17 20:59:55 +08:00
Dylan Owen
b6603468d6 Stop scrolling on socket reload 2019-11-12 18:06:11 -08:00
Eric Huss
441a10bdd7 Release 0.3.5. 2019-11-11 13:36:13 -08:00
Eric Huss
efdb83266a Merge pull request #1021 from marcusklaas/pulldown0.6
Upgrade pulldown_cmark to 0.6
2019-11-11 13:27:19 -08:00
Eric Huss
ac9c12334a Update pulldown-cmark in Cargo.toml to 0.6.1. 2019-11-11 13:26:16 -08:00
Marcus Klaas de Vries
2a3088422a Upgrade pulldown_cmark to 0.6.1 2019-11-11 20:25:38 +01:00
Dylan DPC
1f505c2b2e Revert "Add support for Rust edition 2018 in playpens (#1086)" (#1093)
This reverts commit a7b3aa0444.
2019-11-11 13:24:13 +01:00
Gabriel Majeri
a7b3aa0444 Add support for Rust edition 2018 in playpens (#1086)
* Add support for Rust edition 2018 in playpens

* Add Rust edition support to rustdoc

* Run rustfmt

* Fix enum variant reference
2019-11-11 12:42:24 +01:00
Eric Huss
a9160acd64 Merge pull request #1088 from benediktwerner/master
Fix hiding of empty boring lines
2019-11-07 07:44:47 -08:00
Benedikt Werner
4c1bca1684 Don't hide macro lines 2019-11-07 02:42:02 +01:00
Benedikt Werner
8fffb2a704 Hide lines in ignored code blocks 2019-11-07 02:20:10 +01:00
Eric Huss
ba37cc8462 Merge pull request #1089 from Kampfkarren/patch-1
Change erroneous syntax highlighting definition
2019-11-06 12:45:01 -08:00
Ricky
3ea0f9b745 Lowercase matching the theme name (#1079)
* Using .to_lowercase() on the theme matching to avoid needed exact capitolization in the book.toml

* Changed the default-dark-theme from .to_string() to .to_lowercase() to match theme
2019-11-05 13:55:08 +01:00
boyned//Kampfkarren
29d8747e01 Change erroneous syntax highlighting definition
Doing what it says results in:

```
2019-11-04 16:13:15 [WARN] (mdbook::renderer::html_handlebars::hbs_renderer): Previous versions of mdBook erroneously accepted `./src/theme` as an automatic theme directory
2019-11-04 16:13:15 [WARN] (mdbook::renderer::html_handlebars::hbs_renderer): Please move your theme files to `./theme` for them to continue being used
```
2019-11-04 16:14:38 -08:00
Benedikt Werner
f5549f2267 Hide empty lines starting with '#' in playpens 2019-11-04 14:03:25 +01:00
Benedikt Werner
e2a8600712 Remove outdated unused var in theme js code 2019-11-04 14:03:24 +01:00
Eric Huss
f2cb601c11 Release 0.3.4. 2019-10-29 09:58:11 -07:00
Steve Klabnik
6e0d0facff Merge pull request #1083 from rust-lang/move-from-nursery
rust-lang-nursery -> rust-lang
2019-10-29 08:16:54 -05:00
Steve Klabnik
f79d5d4582 rust-lang-nursery -> rust-lang
Fixes #1080
2019-10-29 08:04:16 -05:00
Rostislav
820714a560 Use only relative font sizes (#894)
This replaces the only use of px for font-sizes by setting up a base
rem size on the root element in a way that is easy to calculate (1 rem =
10px) and scaling up according to browser settings.
2019-10-27 15:51:32 +01:00
Eric Huss
d5535d1226 Release 0.3.3. 2019-10-26 12:16:23 -07:00
Eric Huss
e5f77aaaf2 Merge pull request #1077 from mattheww/2019-10_scroll-margin
Add CSS `scroll-margin-top` to headings which contain link targets.
2019-10-26 11:34:57 -07:00
Matthew Woodcraft
86a368b726 Introduce a --menu-bar-height CSS variable 2019-10-26 13:21:26 +01:00
Matthew Woodcraft
1dc482b00d Add scroll-margin-top to headings which contain link targets.
This means when the link is followed, the page scrolls in such a way as to
leave space for the fixed menu bar.

Fixes #1040
2019-10-26 12:55:12 +01:00
Eric Huss
21d8f394ae Fix "next chapter" spacer handling. (#1075) 2019-10-25 17:33:21 +02:00
Benedikt Werner
c9dae170f3 Better automatic dark mode (#1069)
* Don't save default theme to localStorage

* Auto enable dark mode on no-js

* Fix light theme with no-js
2019-10-23 12:15:59 +02:00
Eric Huss
fcf2d7a03b Merge pull request #1073 from ehuss/fix-gh-pages
Fix gh-pages deploy.
2019-10-21 13:43:35 -07:00
Eric Huss
2498887dfc Fix gh-pages deploy. 2019-10-21 13:41:06 -07:00
Eric Huss
f04d7b802d Merge pull request #1072 from ehuss/release-0.3.2
Release 0.3.2.
2019-10-21 12:37:49 -07:00
Eric Huss
bfcddf2680 Release 0.3.2. 2019-10-21 11:41:39 -07:00
Eric Huss
2b649fe94f Merge pull request #1071 from ehuss/github-actions
Switch to GitHub Actions.
2019-10-21 10:49:18 -07:00
Eric Huss
fc4236eaa7 Switch to GitHub Actions. 2019-10-21 10:43:27 -07:00
rnitta
a592da33bb fix the behavior of sticky header (#1070) 2019-10-19 10:07:41 +02:00
Weihang Lo
6af6219e5b [Feature] expandable sidebar sections (ToC collapse) (#1027)
* render(toc): render expandable toc toggle

* ui(toc): js/css logic to toggle toc

* test: update rendered output css selector

* config: add `html.fold.[enable|level]`

* renderer: fold according to configs

* doc: add `output.html.fold`

* refactor: tidy fold config

- Derive default for `Fold`.
- Use `is_empty` instead of checking the length of chapters.
2019-10-19 09:56:08 +02:00
Andrew Pritchard
e5f74b6c86 Option to display copy buttons. (#1050)
* Option to display copy buttons.

- Added field to playpen data structure
- Communicate through window.playpen_copyable
- Javascript updated to check before displaying copy buttons.

* html -> html_config

Also:
- update description of copyable in source code.
- update description of line_numbers (my last PR to this repository)
2019-10-17 12:44:54 +02:00
Benedikt Werner
84a2ab0dba Reapply: Move hiding of boring lines into static content (#846) (#1065)
* Move hiding of boring lines into static content (#846)

* Fix test for hidden code
2019-10-16 11:27:14 +02:00
David Omar Flores Chávez
d63ef8330d Add !important to code {font-family} property (#1062)
If accepted, this will fix #1061
2019-10-11 14:21:13 +02:00
rnitta
01e50303a2 add a command to playpen (#1066) 2019-10-11 14:16:06 +02:00
Dylan DPC
2b3304cb8b Revert "Move hiding of boring lines into static content (#846)" (#1064)
This reverts commit 4448f3fc4b.
2019-10-10 14:31:55 +02:00
Adrian Heine né Lang
4448f3fc4b Move hiding of boring lines into static content (#846) 2019-10-10 13:55:29 +02:00
Chris Ladd
859659f197 Fix inline code display css (#1058) 2019-10-07 09:24:35 +02:00
Eric Huss
4a93eddae2 Fix "next" navigation on index.html (take 2). (#1005) 2019-10-06 17:55:36 +02:00
Eric Huss
0173451b67 Fix error message for missing output.html. (#1056) 2019-10-06 00:33:50 +02:00
Carol (Nichols || Goulding)
ac1749ff2f Implement a rustdoc_include preprocessor (#1003)
* Allow underscores in the link type name

* Add some tests for include anchors

* Include parts of Rust files and hide the rest

Fixes #618.

* Increase min supported Rust version to 1.35

* Add a test for a behavior of rustdoc_include I want to depend on

At first I thought this was a bug, but then I looked at some use cases
we have in TRPL and decided this was a feature that I'd like to use.
2019-10-06 00:27:03 +02:00
Eric Huss
8cdeb121c5 Merge pull request #1055 from amanjeev/amanjeev/clean-command
Fix (command:clean): removes error message 'dir not found' if 'clean' is run multiple times
2019-10-05 14:03:31 -07:00
Amanjeev Sethi
74313bb701 Fix (command:clean): removes error message 'dir not found' if 'clean' is run multiple times (uses existing path variable) 2019-10-05 15:59:34 -04:00
Amanjeev Sethi
3c25dba9b4 Revert "Fix (command:clean): removes error message 'dir not found' if 'clean' is run multiple times"
This reverts commit 2387942588.
2019-10-05 15:57:10 -04:00
Amanjeev Sethi
2387942588 Fix (command:clean): removes error message 'dir not found' if 'clean' is run multiple times 2019-10-05 15:01:01 -04:00
Eric Huss
93c9ae5700 Merge pull request #1037 from Flying-Toast/prefers-color-scheme
Automatically use a dark theme according to 'prefers-color-scheme'
2019-10-05 11:33:52 -07:00
Eric Huss
9efa9fd1c4 Merge pull request #1052 from morphologue/fix-sidebar-autoscroll
Fix #1029 sidebar not auto-scrolling
2019-10-05 10:19:29 -07:00
Eric Huss
8a33407cc5 Merge pull request #1051 from segfaultsourcery/fix-small-gitignore-bug
I fixed a small gitignore bug
2019-10-05 10:11:16 -07:00
morphologue
699844a5c3 Fix #1029 sidebar not auto-scrolling 2019-10-05 16:54:09 +10:00
Flying-Toast
9bdec5e7cc preferred-dark-theme defaults to default-theme 2019-10-04 19:32:03 -04:00
Kim Hermansson
930f730361 The .gitignore file is now searched for recursively.
Removed a warning if .gitignore is missing.
2019-10-04 22:56:56 +02:00
Eric Huss
09c738468f Merge pull request #1047 from rnitta/patch-1
Fix Search::use_boolean_and documents
2019-10-04 12:39:05 -07:00
Kim Hermansson
a3d1afdd1f This fixes a small bug where the gitignore location can be misinterpreted to be in the folder "above" where it actually is. 2019-10-04 19:44:36 +02:00
Kim Hå
8e8e53ae15 Added support for gitignore files. (#1044)
* Added support for gitignore files.
The watch command will now ignore files based on gitignore. This can be useful for when your editor creates cache or swap files.

* Ran cargo fmt.

* Made the code a bit tidier based on input from other Rust programmers.
Changed the type of the closure back to use PathBuf, not &PathBuf.
Reduced nesting.
2019-10-04 14:59:17 +02:00
rnitta
5fe801a7d1 fix Search::use_boolean_and documents 2019-10-03 11:35:42 +09:00
Eric Huss
a6f317e352 Update highlight.js (#1041) 2019-09-30 00:07:54 +02:00
Eric Huss
ed95252f05 Merge pull request #1039 from ehuss/fix-html-config
Fix merge conflict.
2019-09-26 11:49:57 -07:00
Eric Huss
a058da8b74 Fix merge conflict. 2019-09-26 11:03:51 -07:00
Eric Huss
73be1292ab Merge pull request #1035 from andymac-2/line-numbers
Added line numbers to editable sections of code.
2019-09-26 10:53:32 -07:00
Eric Huss
98ecd1178b Merge pull request #1033 from TjeuKayim/log-deserialization-error-html-config
Log deserialization errors for [html.config]
2019-09-26 10:28:18 -07:00
Eric Huss
996ac382c1 Merge pull request #1038 from ehuss/rustfmt-1.38
Rustfmt for 1.38.
2019-09-26 10:13:00 -07:00
Eric Huss
b88839cc25 Rustfmt for 1.38.
A minor change in the recent stable release.
2019-09-26 09:54:12 -07:00
Flying-Toast
1ef94c2a7e add preferred-dark-theme to book.toml example 2019-09-26 12:13:25 -04:00
Flying-Toast
f0ac13e3e2 Document preferred-dark-theme config option 2019-09-26 12:09:30 -04:00
Flying-Toast
b0ae14a2c7 Automatically use a dark theme according to 'prefers-color-scheme' 2019-09-25 19:11:28 -04:00
Andrew Pritchard
81ab2eb7db Added line numbers to editable sections of code.
- Added line numbers to config struct
- Added playpen_line_numbers field to hbs renderer.
- Added section to set `window.playpen_line_numbers = true` in page template
- Use line number global variable to show line numbers when required.
2019-09-24 21:27:02 +08:00
Tjeu Kayim
213171591a De-duplicate calling Config::html_config() 2019-09-22 21:48:49 +02:00
Tjeu Kayim
db13d8e561 Log HtmlConfig deserialization errors 2019-09-22 21:48:03 +02:00
Eric Huss
b4bb44292d Merge pull request #1030 from lzutao/rustup
Rustup
2019-09-21 09:03:34 -07:00
Lzu Tao
bb7a863d3e Bump compatible deps 2019-09-21 09:23:30 +00:00
Lzu Tao
e62a9dba87 Bump ws 2019-09-21 09:23:30 +00:00
Lzu Tao
4a94b656cd Bump ammonia 2019-09-21 09:23:30 +00:00
Carol (Nichols || Goulding)
a873d46871 Implement a markdown renderer (#1018)
Use case: when trying to `mdbook test` a file that has many `include`
directives, and a test fails, the line numbers in the `rustdoc` output
don't match the line numbers in the original markdown file.

Turning on the markdown renderer implemented here lets you see what is
being passed to `rustdoc` by saving the markdown after the preprocessors
have run.

This renderer could be helpful for debugging many preprocessors, but
it's probably not useful in the general case, so it's turned off by
default.
2019-08-30 12:20:53 +02:00
Carol (Nichols || Goulding)
ce0c5f1d07 Another refactoring in links.rs (#1001)
* Extract the concept of a link having a range or anchor specified

So that other kinds of links can use this concept too.

* Extract a function for parsing range or anchor
2019-08-13 11:19:42 +02:00
Eric Huss
33d7e86fb6 Merge pull request #999 from integer32llc/small-test-improvement
When this test fails, print out why to assist in debugging
2019-08-12 09:02:04 -07:00
Carol (Nichols || Goulding)
f9f9785839 When this test fails, print out why to assist in debugging 2019-08-12 09:50:54 -04:00
Eric Huss
0c37b912ba Merge pull request #824 from sdruskat/patch-1
Fix #823: Apply default padding to table headers
2019-08-09 09:49:56 -07:00
Stephan Druskat
e880fb6339 Fix #823: Apply default padding to table headers
This PR fixes #823 by applying the default padding for table cells (`padding: 3px 20px;`) to header cells.
2019-08-09 09:48:56 -07:00
Eric Huss
a8d6337ac6 Merge pull request #994 from WofWca/nav-chapters-style
ui: Improve next/prev chapter links' style
2019-08-07 11:27:20 -07:00
Eric Huss
f37a89cd4c Merge pull request #998 from integer32llc/links-improvements
Refactoring of some functionality in links.rs
2019-08-07 10:33:11 -07:00
Eric Huss
aaeb3e2852 Merge pull request #985 from Michael-F-Bryan/enable-caching
Allow backends to cache previous results
2019-08-07 10:26:06 -07:00
Carol (Nichols || Goulding)
8c4b292d58 Rework a match to possibly be more understandable 2019-08-06 22:14:17 -04:00
Carol (Nichols || Goulding)
40159362c0 Unnest another conditional 2019-08-06 22:14:16 -04:00
Carol (Nichols || Goulding)
aa67245743 Unnest a conditional 2019-08-06 22:14:16 -04:00
Carol (Nichols || Goulding)
d968443074 Don't bother splitting the path after the 3rd colon 2019-08-06 22:14:16 -04:00
Carol (Nichols || Goulding)
3716123e10 Increase test coverage of parse_include_path 2019-08-06 22:14:16 -04:00
Carol (Nichols || Goulding)
50a2ec3cf1 Ensure the iterator will always return None after the first None
I'm not sure in what cases this iterator might possibly return Some
again, but let's make absolutely sure.
2019-08-06 22:14:16 -04:00
Carol (Nichols || Goulding)
07459aef60 Factor out the use of different ranges from linktype
This eliminates some duplication and will enable different kinds of
LinkTypes to have line number ranges.

Implement `From` for the std `Range` types to enable easier
construction.

The new code reaaalllly makes me wish for a delegation mechanism though
:(
2019-08-06 22:14:16 -04:00
Eric Huss
0f56c09d3a Merge pull request #996 from lzutao/temporary-disable-sccache
build(CI): Temporary disable sccache
2019-08-05 18:00:35 -07:00
Lzu Tao
63ad3d9340 build(CI): Temporary disable sccache 2019-08-03 23:19:04 +07:00
WofWca
1c5dc1e310 ui: Improve next/prev chapter links' style 2019-08-03 22:56:25 +08:00
Steve Klabnik
77af889a2e Merge pull request #991 from lbeckman314/patch-1
Add `--path .` to cargo install commands.
2019-08-01 18:37:33 -05:00
Liam Beckman
e48fed74bf Add --path . to cargo install commands.
Changing `cargo install` to `cargo install --path .` prevents the following error:

<span style="color: red;">error:</span> Using `cargo install` to install the binaries for the package in current working directory is no longer supported, use `cargo install --path .` instead. Use `cargo build` if you want to simply build the package.
2019-07-31 14:49:25 -07:00
Sorin Davidoi
e512850c13 fix(css/chrome): Use standard property for scrollbar (#816)
This was recently standardized and is currently implemented in Firefox Nightly.
2019-07-28 21:01:33 +02:00
Michael Bryan
bb412edf53 Made sure the tests pass 2019-07-21 04:32:28 +08:00
Michael Bryan
5b0a23ebab Updated the documentation 2019-07-21 02:40:58 +08:00
Michael Bryan
e56c41a1c2 The HTML renderer now cleans its own build directory 2019-07-21 02:37:09 +08:00
Michael Bryan
d1b5a8f982 The MDBook::build() method no longer cleans the renderer's build directory 2019-07-21 02:35:18 +08:00
Eric Huss
f396623b63 Merge pull request #983 from meichstedt/me/fix-config-docs
Remove redundant occurrence of 'in the'
2019-07-17 09:56:01 -07:00
Matthias Eichstedt
9ec43b6c6d Remove redundant occurrence of 'in the' 2019-07-17 17:20:18 +02:00
Eric Huss
7c4d2070f7 Merge pull request #981 from ehuss/release-0.3.1
Release 0.3.1
2019-07-15 14:58:07 -07:00
Eric Huss
50d5917530 Release 0.3.1 2019-07-15 14:56:59 -07:00
Eric Huss
9cd47eb80f Merge pull request #979 from ehuss/fix-links
Fix some broken links.
2019-07-15 14:55:21 -07:00
Eric Huss
4932df2570 Merge pull request #980 from ehuss/appveyor-one-job
Only run 1 job on appveyor when a PR is opened.
2019-07-15 14:54:55 -07:00
Eric Huss
11d31c989c Only run 1 job on appveyor when a PR is opened. 2019-07-15 13:16:55 -07:00
Eric Huss
e5ace6d6a4 Fix some broken links. 2019-07-15 12:51:46 -07:00
Eric Huss
e7c3d02c61 Merge pull request #851 from CBenoit/master
Add include by anchor in preprocessor (partial include)
2019-07-15 12:31:59 -07:00
Benoît CORTIER
d8a68ba3f6 Document anchor-based partial include feature in the book 2019-07-14 21:55:51 -04:00
Benoît CORTIER
d29a79349c Add include by anchor in preprocessor. 2019-07-14 21:55:51 -04:00
Eric Huss
d6088c8a57 Merge pull request #978 from ehuss/bump-elasticlunr
Bump elasticlunr.
2019-07-12 21:59:39 -07:00
Eric Huss
b91e5c8807 Merge pull request #977 from sunng87/feature/handlebars-2.0
(feat) update handlebars to 2.0
2019-07-12 09:56:51 -07:00
Eric Huss
6199e4df79 Bump elasticlunr. 2019-07-12 09:53:11 -07:00
Ning Sun
2d11eb05fe (feat) update handlebars to 2.0 2019-07-13 00:11:05 +08:00
Carol (Nichols || Goulding)
3d45e40693 Small cleanups of variable/field names (#970)
* Rename a variable from playpen to link

Links can now be more than only playpen links

* Rename a field to match the enum type it holds

Also so that link.link.stuff doesn't happen when a variable link holds a
Link instance
2019-07-04 11:31:04 +02:00
Eric Huss
228e99ba11 Fix even more print page links. (#963) 2019-07-01 17:52:25 +02:00
Eric Huss
4b569edadd Fix memory leak and warning (#967) 2019-07-01 17:49:57 +02:00
Eric Huss
3e652b5bfc Merge pull request #965 from lzutao/missed-sccache
Fix broken cache by updating sccache version
2019-06-29 13:42:43 -07:00
Lzu Tao
ba41d73dc3 build: Fix stale builds 2019-06-28 23:14:26 +07:00
Lzu Tao
1ce1401263 travis: Include cargo registry when cache
This reduces the crates downloading time upto 30 seconds
on fast network.
2019-06-28 11:13:54 +07:00
Lzu Tao
00b3d9cf86 build: Fix broken cache by updating sccache 2019-06-28 11:13:54 +07:00
Eric Huss
bb3398bdbb Merge pull request #941 from rnitta/configurable-language
Change language attribute of the book to configurable
2019-06-24 08:56:22 -07:00
Eric Huss
19c26217c0 Don't keep gh-pages history. (#964) 2019-06-21 07:17:03 +02:00
Eric Huss
a2029f0a78 Merge pull request #959 from jeremystucki/refactoring
Minor Refactoring
2019-06-20 20:05:02 -07:00
Eric Huss
7c33ac800c Merge pull request #962 from integer32llc/rangebounds
Use stdlib RangeBounds
2019-06-20 20:01:52 -07:00
Eric Huss
d371001ab8 Merge pull request #961 from integer32llc/fs-read-to-string
Switch to the standard library's fs::read_to_string
2019-06-20 20:00:35 -07:00
Eric Huss
d73504eb23 Merge pull request #960 from integer32llc/update-min-rust-version
Update specified minimum Rust version and test it in travis
2019-06-20 19:59:15 -07:00
Carol (Nichols || Goulding)
abddd7c6f7 Use stdlib RangeBounds 2019-06-20 21:56:31 -04:00
Carol (Nichols || Goulding)
31e36f85e7 Update specified minimum Rust version and test it in travis 2019-06-20 15:04:55 -04:00
Jeremy Stucki
92a7b0cdcd Use iterator instead of for loop 2019-06-20 15:12:56 +02:00
Jeremy Stucki
592140db5b Remove redundant closure 2019-06-20 14:56:47 +02:00
Jeremy Stucki
3a0eeb4bbb Remove needless scope 2019-06-20 14:29:14 +02:00
Jeremy Stucki
a9dae326fa Use unwrap_or instead of match on Result 2019-06-20 14:27:57 +02:00
Jeremy Stucki
abba959add Remove needless lifetime 2019-06-20 14:18:31 +02:00
Jeremy Stucki
ea15e55829 Use map instead of match on Option 2019-06-20 14:18:17 +02:00
j143-bot
d07bd9fed4 Update the master-docs link to ../mdBook (#958) 2019-06-20 08:54:38 +02:00
Carol (Nichols || Goulding)
b83c55f7ef Switch to the standard library's fs::read_to_string 2019-06-19 22:49:18 -04:00
Eric Huss
69a08ef390 Merge pull request #956 from ehuss/rel-0.3.0
Release 0.3.0
2019-06-18 16:02:43 -07:00
Eric Huss
1cd1151790 Release 0.3.0 2019-06-18 15:24:26 -07:00
Eric Zubriski
84d4063e4a Fix-681 (#954)
* Adding section for code snippets.

* Reformatting sections.

* Update mdbook.md
2019-06-13 07:38:12 +02:00
Eric Huss
07830f7f11 Merge pull request #891 from integer32llc/include-before-test
Write preprocessed content to file before testing with rustdoc
2019-06-12 15:01:58 -07:00
Eric Huss
828b7d05c5 Merge pull request #953 from ehuss/update-changelog
Update changelog.
2019-06-12 09:31:45 -07:00
Eric Huss
379004efcb Update changelog. 2019-06-12 09:30:58 -07:00
Eric Huss
2497e77bf1 Support strikethrough and tasklists. (#952) 2019-06-12 17:02:03 +02:00
Eric Huss
0c2292b9aa Update css to support diff syntax highlighting. (#943)
This adds the rules to highlight diff lines with highlight.js.
2019-06-12 16:59:55 +02:00
lzutao
4386a10e87 Explicitly mark fonts and images files as binary (#951) 2019-06-11 21:44:15 +02:00
Eric Huss
3cfed10098 Update to pulldown-cmark 0.5. (#898)
* Update to pulldown-cmark 0.4.1.

* Update to pulldown-cmark 0.5.2.

* Remove pulldown-cmark-to-cmark dependency.

Since it is not compatible with the new pulldown-cmark. This example isn't
directly usable, anyways, and I think the no-op example sufficiently shows how
to make a preprocessor.

* cargo fmt

* Fix example link.
2019-06-11 18:26:24 +02:00
rnitta
a655d5d241 Header elements wrap links (#948)
* swap hierarchy of header for that of link

* fix comment
2019-06-03 14:31:15 +02:00
Eric Huss
f8c3a2deea Update highlight.js (#942)
Updates to v9.15.8.

My main motivation is to fix a minor issue with TOML highlighting.

This keeps the same language list as before with the addition of a new "common"
language `properties` and added `julia` because someone asked for it and I like
julia. The full list from building:

	:common armasm d go handlebars haskell julia rust scala swift x86asm yaml

- apache
- armasm
- bash
- coffeescript
- cpp
- cs
- css
- d
- diff
- go
- xml
- handlebars
- haskell
- http
- ini
- java
- javascript
- json
- julia
- makefile
- markdown
- nginx
- objectivec
- perl
- php
- properties
- python
- ruby
- rust
- scala
- shell
- sql
- swift
- x86asm
- yaml
2019-06-03 14:22:32 +02:00
Eric Huss
b226d2fc55 cargo fmt 2019-05-31 09:19:46 -07:00
lzutao
53ba0d6655 Remove 'static lifetime from static vars (#947) 2019-05-31 18:01:02 +02:00
Eric Huss
43ead86ecc Update toml. (#945)
Just keeping up-to-date.
2019-05-31 18:00:15 +02:00
Eric Huss
1d3ec7e0c7 Support rust edition in playground. (#946)
The endpoint was recently updated to support the edition param.
2019-05-31 17:59:44 +02:00
Eric Huss
f4017376a9 Merge pull request #944 from lzutao/formatting
Minor formatting fixes
2019-05-30 11:12:57 -07:00
Lzu Tao
672cf456eb Remove unnecessary ::<crate>
Find and replace with `git grep -E '\W::[a-z]'` command.
2019-05-30 23:12:33 +07:00
Lzu Tao
8dce00d54d Cargo.toml: Sort dependencies fields 2019-05-30 22:23:42 +07:00
rnitta
4f7c299de7 update language attribute to configurable 2019-05-30 11:53:49 +09:00
Eric Huss
04e74bfa1b Merge pull request #931 from ehuss/update-deps
cargo update
2019-05-26 11:23:00 -07:00
Eric Huss
4026a586a1 cargo update 2019-05-26 09:23:23 -07:00
lzutao
71281bff10 Update some updatable dependencies (#934)
* Update ammonia dependency

* Update env_logger

* Update itertools

* Update ws dep

* Update pretty_assertions dep
2019-05-26 14:05:42 +02:00
lzutao
8542f7f29d Transition to 2018 edition (#933)
* Transition to 2018 edition

* Update Travis CI badge in README

* Remove non-idiomatic `extern crate` lines
2019-05-25 20:50:41 +02:00
Eric Huss
fe492d1cb9 Merge pull request #937 from ehuss/fix-changelog-typo
Fix changelog typo
2019-05-25 09:02:09 -07:00
Eric Huss
481c2f2194 Fix changelog typo 2019-05-25 09:00:33 -07:00
lzutao
882014860c Update ace editor to v1.4.4 (#935) 2019-05-25 14:39:16 +02:00
Bas Bossink
e3ec751a3f Issue 703 (#929)
* Replace all occurances of altenate backend with alternative backed

Rename test for consistency of the terminology.

* Use better sed command
2019-05-19 22:16:10 +02:00
Eric Huss
fc565df86b Some documentation fixes. (#925) 2019-05-19 00:05:57 +02:00
Eric Huss
ec8e63145c Add a changelog. (#926) 2019-05-18 23:56:01 +02:00
Bas Bossink
2752c88c46 Fix issue #703. (#928) 2019-05-18 23:38:08 +02:00
Eric Huss
e7befd19bc Merge pull request #924 from ehuss/fix-appveyor-token
Fix appveyor github token.
2019-05-16 13:20:42 -07:00
Eric Huss
644b8e132c Fix appveyor github token. 2019-05-16 13:19:39 -07:00
Eric Huss
8e82ae534a Merge pull request #923 from ehuss/new-deploy
Fix automatic deploy.
2019-05-16 09:34:39 -07:00
Eric Huss
6a8a5b7642 Fix automatic deploy.
This should fix deploying release artifacts and gh-pages for the documentation.
Secrets should now be configured in the UI for travis and appveyor.

This also removes some of the appveyor jobs, since they aren't really
necessary, and there are limited jobs on rust-lang-libs.
2019-05-15 15:50:01 -07:00
Roman Proskuryakov
c3284a2ae9 Update mdbook 0.1 -> 0.2 in docs for CI (#918) 2019-05-11 20:30:21 +02:00
Allen
df12cc55c8 Revert "Merge pull request #889 from s3bk/master" (#917)
* Revert "Merge pull request #889 from s3bk/master"

This reverts commit b30b58b565, reversing
changes made to c6220fba83.

* format tests :P
2019-05-09 20:18:28 +02:00
Eric Huss
cb4a3e0711 Fix more print.html links. (#871) 2019-05-08 23:50:59 +02:00
lzutao
9194a40acd CI: Check Rust formatting for each commit (#909) 2019-05-08 21:20:38 +02:00
Bas Bossink
506996808b Fix issue 832 (#841)
* Add if around stub summary creation

Check if an existing SUMMARY.md is present to prevent overwriting it
with the stub SUMMARY.md.

[#832]

* Add test for existing SUMMARY.md
2019-05-08 21:13:20 +02:00
Philipp Hansch
5163c5ab75 Don't let robots index the print.html (#844) 2019-05-08 00:32:43 +02:00
Stefanie Jäger
ecfaed1e02 Change overflow-x to initial (#818)
Change overflow-x from auto to initial.
This resolves weird rendering behavior in Chrome and Safari on macOS.

With help from @bash

Co-authored-by: Ruben Schmidmeister <ruben.schmidmeister@icloud.com>
2019-05-08 00:30:28 +02:00
Eric Huss
8bb5426441 Fix keyboard chapter navigation for file urls. (#915) 2019-05-08 00:29:46 +02:00
Eric Huss
a674c9eff1 Fix "next" navigation on index.html. (#916) 2019-05-08 00:27:48 +02:00
lzutao
7ab939f8f2 CI: Enable sccache build (#913) 2019-05-06 23:41:44 +02:00
lzutao
581187098c Deny 2018 edition idioms globally (#911) 2019-05-06 22:50:34 +02:00
lzutao
ab7802a9a9 Fix most of clippy warnings (#914)
* Fix clippy: cast_lossless

* Fix clippy: match_ref_pats

* Fix clippy: extra_unused_lifetimes

* Fix clippy: needless_lifetimes

* Fix clippy: new_without_default

* Fix clippy: or_fun_call

* Fix clippy: should_implement_trait

* Fix clippy: redundant_closure

* Fix clippy: const_static_lifetime

* Fix clippy: redundant_pattern_matching

* Fix clippy: unused_io_amount

* Fix clippy: string_lit_as_bytes

* Fix clippy: needless_update

* Fix clippy: blacklisted_name

* Fix clippy: collapsible_if

* Fix clippy: match_wild_err_arm

* Fix clippy: single_match

* Fix clippy: useless_vec

* Fix clippy: single_char_pattern

* Fix clippy: float_cmp

* Fix clippy: approx_constant
2019-05-06 20:20:58 +02:00
Dylan DPC
345acb8597 Merge pull request #908 from lzutao/fmt
Formatting whole project
2019-05-06 00:26:50 +02:00
Dylan DPC
6380526e93 Merge pull request #907 from lzutao/lock
Update Cargo.lock
2019-05-05 22:57:41 +02:00
Lzu Tao
4560bdeb47 Update Cargo.lock 2019-05-06 00:12:53 +07:00
Lzu Tao
0aa3a9045a cargo fmt 2019-05-05 22:00:24 +07:00
Dylan DPC
b30b58b565 Merge pull request #889 from s3bk/master
new "Book" theme
2019-05-04 17:45:37 +02:00
Dylan DPC
c6220fba83 Merge pull request #906 from rust-lang-nursery/fix/typo
fixes typo in code
2019-05-04 17:33:05 +02:00
Dylan DPC
652eab6e7e Update custom_preprocessors.rs 2019-05-03 20:32:56 +02:00
Dylan DPC
5726a8afd6 Update build_process.rs 2019-05-03 20:00:43 +02:00
Dylan DPC
7e26a8430d Update mod.rs 2019-05-03 19:59:58 +02:00
Dylan DPC
07a64b110a Merge pull request #905 from ehuss/fix-code-inline-color
Fix color of `code spans` that are links.
2019-05-02 21:14:28 +02:00
Eric Huss
dd69e03ff5 Fix color of code spans that are links. 2019-05-02 11:07:24 -07:00
Dylan DPC
7f3a0ff6a0 Merge pull request #886 from bluejekyll/master
add docs for publishing to github pages manually
2019-04-30 00:50:58 +02:00
Dylan DPC
aea317e173 Update continuous-integration.md 2019-04-30 00:50:35 +02:00
Dylan DPC
f9454615b1 Update book-example/src/continuous-integration.md
Co-Authored-By: bluejekyll <benjaminfry@me.com>
2019-04-29 15:33:31 -07:00
Dylan DPC
39211291d9 Update book-example/src/continuous-integration.md
Co-Authored-By: bluejekyll <benjaminfry@me.com>
2019-04-29 15:33:25 -07:00
Dylan DPC
f01fe854fa Merge pull request #883 from anp/custom_summary
Expose API for building a book with a custom Summary.
2019-04-30 00:25:03 +02:00
Dylan DPC
6eeaaaa44d Merge pull request #819 from StefanieJaeger/css-comment
Update comment in editor.js
2019-04-28 23:56:13 +02:00
Dylan DPC
357ebcf7ce Merge pull request #849 from gentoo90/sidebar-resize
Add sidebar resize
2019-04-28 23:29:07 +02:00
Dylan DPC
1a4f38eace Merge pull request #903 from FreeMasen/master
remove walkdir from lib via handlebars
2019-04-28 22:19:30 +02:00
rfm
1d3f83eede remove walkdir from lib via handlebars 2019-04-28 12:54:01 -05:00
Dylan DPC
9712347b9c Merge pull request #796 from badboy/dont-trim-external-js-path
Don't strip relative path of additional javascript files
2019-04-26 09:01:39 +02:00
Dylan DPC
f73d42d994 Merge pull request #878 from shen390s/master
Cleanup build directory before preprocessors run to keep files genera…
2019-04-26 00:17:09 +02:00
Dylan DPC
a647017e4b Merge pull request #861 from k-nasa/add_colored_help
Add colored help
2019-04-25 23:19:18 +02:00
Dylan DPC
a66d44190e Merge pull request #900 from felixrabe/patch-2
Typo
2019-04-23 22:13:07 +02:00
Felix Rabe
01fd7a76f0 Typo 2019-04-23 22:11:12 +02:00
Dylan DPC
99dc62f9c3 Merge pull request #867 from ffissore/master
Fixed loss of focus when clicking the Copy button
2019-04-23 20:25:58 +02:00
Dylan DPC
b891fd5a12 Merge pull request #834 from donald-pinckney/master
Fixes #826
2019-04-23 11:36:43 +02:00
Federico Fissore
02fa7b0a11 When the Copy button is pressed, focus is lost and scrolling the page
with the arrow keys stops working. Fixed by upgrading ClipboardJS to
the latest version
2019-04-23 09:29:22 +02:00
Dylan DPC
8b2e1c2daa Merge pull request #870 from cauebs/group-events
Group file changes and rebuild book only once
2019-04-23 00:20:54 +02:00
Dylan DPC
88d2f69138 Merge pull request #860 from k-nasa/fix_duplication
Fix duplication with Cargo.toml
2019-04-22 12:31:50 +02:00
Dylan DPC
cb94053779 Merge pull request #892 from integer32llc/fix-warnings
Fix deprecation warnings for trim left/right matches
2019-04-21 21:20:39 +02:00
Dylan DPC
0a8707b1e6 Merge pull request #872 from ehuss/travis-deploy
Fix deploy on Travis.
2019-04-20 19:11:38 +02:00
Donald Pinckney
0dc2728fa9 Merge branch 'master' of github.com:rust-lang-nursery/mdBook 2019-04-18 12:29:32 -04:00
Dylan DPC
9b02cd7496 Merge pull request #897 from ji-zhou/master
Correct grammar: remove the redundancy
2019-04-17 23:47:08 +02:00
ji.zhou
11f86f4511 Correct grammar: remove the redundancy 2019-04-12 22:53:21 +08:00
Carol (Nichols || Goulding)
4abac12c04 Fix deprecation warnings for trim left/right matches 2019-03-23 08:47:10 -04:00
Carol (Nichols || Goulding)
d7c7d91005 Write preprocessed content to file before testing with rustdoc
Fixes #855.
2019-03-23 08:35:44 -04:00
Sebastian Köln
9243cf9d95 well. typo 2019-03-21 07:56:48 +01:00
Sebastian Köln
d2470730fc center book title 2019-03-20 22:13:12 +01:00
Sebastian Köln
6a2e2461fb quote inline code 2019-03-20 17:02:05 +01:00
Sebastian Köln
3faa3e42f0 switch to Source font family 2019-03-20 16:34:19 +01:00
Sebastian Köln
9c8fae4704 fix forgotten rename 2019-03-20 15:36:40 +01:00
Sebastian Köln
9b6f5a9840 add Book theme (Liberation fonts need to be in /fonts/ on the server) 2019-03-20 15:21:36 +01:00
Benjamin Fry
62af2367bb add docs for publishing to github pages manually 2019-03-12 11:22:00 -07:00
Adam Perry
37808b7e08 Expose API for building a book with a custom Summary.
This is useful for situations where you'd like to
supplement or replace the existing Summary parsing with
custom filesystem traversal code or other similar changes.
2019-03-04 11:44:00 -08:00
Rongsong Shen
b37f21a09b Cleanup build directory before preprocessors run to keep files generated by preprocessors 2019-02-16 12:17:26 +08:00
Eric Huss
966632a724 Fix deploy on Travis.
The deploy scripts require TARGET env var to be set, but it wasn't set anywhere, causing it to fail: https://travis-ci.com/rust-lang-nursery/mdBook/builds/97850452.

This also reduces the number of mac builders, since they aren't necessary, and capacity is limited.

The api key will likely need to be updated, too, since the transition to travis.com.

Appveyor also seems to be broken, but I suspect it is also a key issue.
2019-02-03 15:45:02 -08:00
Cauê Baasch de Souza
c7281459f9 Group file changes and rebuild book only once 2019-01-31 16:31:02 -02:00
nasa
ae3f87ad0c fix: Fix Cargo.toml description 2019-01-20 15:12:51 +09:00
Steve Klabnik
c068703028 start next development iteration 0.2.4-alpha.0 2019-01-18 10:43:59 -05:00
Steve Klabnik
6cbc41d413 version 0.2.3 2019-01-18 10:39:51 -05:00
Steve Klabnik
25c1ca1275 Merge pull request #866 from rust-lang-nursery/gh828
Fixing links in print.html
2019-01-18 09:54:17 -05:00
Steve Klabnik
acbb951240 Merge pull request #865 from sderosiaux/patch-1
Fix websocket hostname usage
2019-01-17 15:08:18 -05:00
Steve Klabnik
9e96165d8f Merge pull request #845 from phansch/update_contributing
Update CONTRIBUTING.md (Clippy is on stable now)
2019-01-17 15:07:21 -05:00
Steve Klabnik
5c5ef2f86b Merge pull request #853 from sshplendid/broken-link
Update broken link at the user guide.
2019-01-17 15:06:45 -05:00
Steve Klabnik
23ac06e2eb Fix a bug in link re-writing
In a regex, `.` means `[0-9a-zA-Z]`, not a period character. This means
that this regex worked, unless a link anchor contained `md` inside of
it. This fixes the regex to match a literal period.

Reported by @ehuss in
https://github.com/rust-lang-nursery/mdBook/pull/866#issuecomment-454595806
2019-01-16 15:44:51 -05:00
Steve Klabnik
2ddbb37f49 Fix the bug 2019-01-15 14:10:02 -05:00
Steve Klabnik
a481735fa2 failing test 2019-01-15 14:08:53 -05:00
Stéphane Derosiaux
954cfa86e5 Fix websocket hostname usage
The livereload url was using an unknown property "websocket-address" instead of "websocket-hostname", hence it was always fallback onto the hostname (which can be different).
2019-01-09 17:59:45 +01:00
k-nasa
7e52da3c1b Add colored help 2018-12-25 21:35:37 +09:00
k-nasa
4e8d051bd1 Delete extra space 2018-12-25 21:10:45 +09:00
k-nasa
78ee8e43bb Fix duplication with Cargo.toml 2018-12-25 21:10:07 +09:00
Shawn
b675b91980 Update broken link
https://www.rust-lang.org/downloads.html is the outdated link.
2018-12-15 10:09:23 +09:00
gentoo90
3d8db7f25c Disable text selection and CSS transition while resizing sidebar 2018-12-12 21:55:50 +02:00
gentoo90
3d37e24c14 Add sidebar resizing 2018-12-12 21:55:50 +02:00
Philipp Hansch
eb19d2d654 Update CONTRIBUTING.md (Clippy is on stable now) 2018-12-08 13:48:59 +01:00
Michael Bryan
1052ee92e1 Merge pull request #837 from basbossink/master
Random acts of kindness
2018-12-08 15:44:40 +08:00
Bas Bossink
3598e905aa Make failing_alternate_backend test more platform specific
Use the suggestion from @Michael-F-Bryan to make the passing_ and
failing_alternate_backend test more reliable across platforms.
2018-12-05 22:26:53 +01:00
Bas Bossink
3f002979c4 Suppress dead_code warning in test 2018-12-04 00:57:15 +01:00
Bas Bossink
742dbbc917 Run rustfmt. 2018-12-04 00:11:41 +01:00
Bas Bossink
991a725c26 Solve the simplest clippy warnings and run rustfmt 2018-12-04 00:10:09 +01:00
Donald Pinckney
317c7731da Remove extra comment 2018-11-28 20:07:37 -05:00
Donald Pinckney
4c17b11ed0 Fix #826 2018-11-28 20:05:37 -05:00
Michael Bryan
005dfc55bf Merge pull request #829 from kingdido999/patch-1
Fix invalid url in renderer documentation
2018-11-22 20:12:19 +08:00
Desmond
8c86031384 Fix invalid url in renderer documentation 2018-11-21 08:59:53 +08:00
Stefanie Jäger
5151aae07e Update comment
Comment in editor.js referenced file called "general.styl", changed that
to "general.css".
2018-11-09 17:34:57 +01:00
Michael Bryan
42b87e0fbc Merge pull request #804 from Bassetts/default-theme-option
Default theme option
2018-10-30 21:18:48 +08:00
Matt Ickstadt
33add4b532 Merge pull request #782 from mattico/document-dest-dir-rel
Document dest-dir relative path behavior
2018-10-23 12:16:37 -05:00
Michael Bryan
b0513ee771 Merge pull request #788 from weihanglo/feat/non-ascii-heading-anchor
Allow non alphabetic initial in heading anchor
2018-10-23 19:21:44 +08:00
Michael Bryan
b4538da9c3 Merge pull request #802 from Bassetts/git-button
Implement a git repository button
2018-10-23 19:16:45 +08:00
Michael Bryan
7ac3e50b37 Merge pull request #809 from hikarinotomadoi/fix-documentation-comments-for-HtmlConfig
Improve documentation comments
2018-10-23 19:15:51 +08:00
yoshimura masataka
13a9aab2b2 Improve documentation comments 2018-10-23 10:34:14 +09:00
Jason Liquorish
eccec9bb52 Update documentation for 2018-10-21 13:16:59 +01:00
Michael Bryan
e63f53fe47 (cargo-release) start next development iteration 0.2.3-alpha.0 2018-10-20 14:22:47 +08:00
Michael Bryan
2c20c99d4a (cargo-release) version 0.2.2 2018-10-20 14:21:21 +08:00
Michael Bryan
c6125b184f Merge pull request #807 from rust-lang-nursery/update-readme
Update the readme to mention plugins
2018-10-20 14:17:57 +08:00
Michael Bryan
dfb6e3cb10 Merge pull request #806 from rust-lang-nursery/serialize-checks
Add some round-trip checks for preprocessor input serialization
2018-10-20 14:17:03 +08:00
Michael Bryan
cffc385b0c Updated the user guide's config section to mention specifying plugin commands 2018-10-20 14:16:07 +08:00
Michael Bryan
e73928f933 Mentioned plugins in the README 2018-10-20 14:01:51 +08:00
Michael Bryan
41071a5dd9 Bumped dependencies 2018-10-20 12:51:45 +08:00
Michael Bryan
f6a7432569 Added a round-trip test to make sure parse_input() is always correct 2018-10-20 12:50:35 +08:00
Michael Bryan
89ea60e7a5 Made __non_exhaustive fields #[serde(skip)] 2018-10-20 11:21:24 +08:00
Jason Liquorish
10b69e60c8 Add documentation and tests 2018-10-15 21:40:59 +01:00
Jason Liquorish
336e08fe50 Update FontAwesome version to 4.7.0 2018-10-15 20:01:36 +01:00
Jason Liquorish
5bfdf9fcc8 Added git-repository-icon option
Updated documentation and added tests.
2018-10-15 19:48:54 +01:00
Michael Bryan
29f8b791f1 Merge pull request #792 from rust-lang-nursery/custom-preprocessor
WIP: Custom Preprocessors
2018-10-16 00:02:12 +08:00
xyh
877bf37d18 avoid using cd in example travis-ci script (#803) 2018-10-15 18:52:37 +08:00
Jason Liquorish
d2565af000 Add helper to format theme name for theme changer 2018-10-13 14:44:10 +01:00
Jason Liquorish
599e47f1f1 Initial implementation of a git repository button 2018-10-13 12:17:33 +01:00
Jason Liquorish
0c31ab2953 Initial implementation of default theme option 2018-10-12 19:57:59 +01:00
Michael Bryan
b1c7c54108 Rewrote a large proportion of the Preprocessor docs to be up-to-date 2018-09-25 19:48:20 +08:00
Jan-Erik Rediger
f654c42426 Don't strip relative path of additional javascript files
Previously, additional JavaScript files inside a directory were
correctly copied (with their parent created), but the link to it was
stripped of that parent.
There's no need for that (and it was not done for CSS)
2018-09-19 20:36:32 +02:00
Jan-Erik Rediger
0c926b3e88 Ensure section numbers are correctly incremented after a horizontal separator (#790)
Fixes #779
2018-09-19 23:33:28 +08:00
mwilbur
e4eddb3f26 Fix broken link to API pages (#795) 2018-09-19 23:32:37 +08:00
Michael Bryan
adec78e7f5 Forgot to implement 3rd party preprocessor discovery 2018-09-19 23:16:11 +08:00
Michael Bryan
5cd5e4764c Fleshed out the api docs 2018-09-16 23:44:52 +08:00
Michael Bryan
132f4fd358 Fixed a bug where the tests use the wrong dummy book 2018-09-16 23:33:58 +08:00
Michael Bryan
1d72cea972 The example preprocessor works 2018-09-16 23:28:01 +08:00
Michael Bryan
1aa1194d79 We can shell out to the preprocessor 2018-09-16 23:23:03 +08:00
Michael Bryan
304234c122 The example can now tell mdbook if renderers are supported 2018-09-16 23:00:19 +08:00
Michael Bryan
729c94a7e4 Started working on a custom preprocessor 2018-09-16 22:49:52 +08:00
Ramon Buckland
df874cdbdb Resolves #270. details for Clippy and Rustmft usage (#776)
* Resolves #270. details for Clippy and Rustmft usage

* Fix Typo
2018-09-16 14:39:18 +08:00
Michael Bryan
5dce539928 Notify preprocessors of the mdbook version and add __non_exhaustive elements 2018-09-16 14:27:37 +08:00
Michael Bryan
206a00915b Export the mdbook version from the crate root 2018-09-16 14:22:50 +08:00
Ramon Buckland
ced74ca4dd Updated the documentation for new preprocessor format (#787)
* Updated the documentation for new preprocessor format

* adjusted the descriptions for preprocessors
2018-09-10 19:51:18 +08:00
Michael Bryan
09667c9956 Configurable preprocessor (#658)
* The preprocessor trait now returns a modified book instead of editing in place

* A preprocessor is told which render it's running for

* Made sure preprocessors get their renderer's name

* Users can now manually specify whether a preprocessor should run for a renderer

* You can normally use default preprocessors by default

* Got my logic around the wrong way

* Fixed the `build.use-default-preprocessors` flag
2018-09-10 18:55:58 +08:00
Weihang Lo
d729a762fe Remove insertion on non alphabetic initial headings 2018-09-09 12:00:28 +08:00
Weihang Lo
43b3d157d9 (test) validate id from non ascii headings 2018-09-09 12:00:25 +08:00
Matt Ickstadt
a9f3be6f44 Make serve command note more prominent 2018-09-06 10:24:56 -05:00
Matt Ickstadt
34356b87a0 Document dest-dir relative path behavior 2018-09-06 10:24:42 -05:00
Matt Ickstadt
48c97dadd0 Merge pull request #777 from wirelyre/fix-additional-css-and-js
Fix paths to additional CSS and JavaScript files
2018-09-04 14:16:42 -04:00
wirelyre
65198a7632 Fix paths to additional CSS and JavaScript files
Expressions in an `#each` block need to begin with "../" to reference
values in the main context.
2018-08-31 20:03:34 -05:00
Matt Ickstadt
a0e7b19784 (cargo-release) start next development iteration 0.2.2-alpha.0 2018-08-22 08:51:07 -05:00
Matt Ickstadt
7e2e095c26 (cargo-release) version 0.2.1 2018-08-22 08:48:25 -05:00
Matt Ickstadt
5baaf55abc Merge pull request #770 from mattico/improve-travis
Improve CI
2018-08-22 08:55:06 -05:00
Matt Ickstadt
9157f6e32d Improve CI
- Try to get OSX releases working
- Use LTO for appveyor releases
- Remove unused install.sh
2018-08-21 11:18:20 -05:00
Matt Ickstadt
3688f73052 rustfmt
using rustfmt 0.99.2-nightly
2018-08-21 10:58:44 -05:00
Matt Ickstadt
3e89e8b1bd Update dependencies 2018-08-21 10:51:34 -05:00
Matt Ickstadt
e08fc148b1 Merge pull request #769 from dguo/patch-1
Fix a typo
2018-08-21 09:44:35 -05:00
Danny Guo
d9c1c77aae Fix a typo 2018-08-20 23:48:18 -04:00
Matt Ickstadt
bb2ca4f938 Merge pull request #765 from weihanglo/fix/quote-table-colors
Fix table and quote related color
2018-08-13 11:08:29 -05:00
Weihang Lo
42aded9577 Fix table and quote related color 2018-08-12 02:47:06 +08:00
Matt Ickstadt
7fb2d5437a Merge pull request #761 from sunng87/feature/handlebars-1.0
Update to handlebars 1.0
2018-08-07 15:39:09 -05:00
Ning Sun
4cc3a1333b (feat) update to handlebars 1.0 2018-08-05 15:08:47 +08:00
Matt Ickstadt
322e8fcf77 Rewrap guide markdown at 80 columns
Much of the book was wrapped at around 80 columns, but let's make this consistent.
2018-08-02 21:34:26 -05:00
Matt Ickstadt
a8a460545f Update installation instructions in guide 2018-08-02 21:19:47 -05:00
Matt Ickstadt
1d69ccae48 Run rustfmt
using 0.8.2-stable included in rustc 1.28.0
2018-08-02 20:22:49 -05:00
Matt Ickstadt
762d89ebbf (cargo-release) start next development iteration 0.2.1-alpha.0 2018-08-02 19:20:05 -05:00
Matt Ickstadt
91ffca1bbc (cargo-release) version 0.2.0 2018-08-02 19:17:40 -05:00
Matt Ickstadt
6f963bbe3c Run AppVeyor on version tags 2018-08-02 19:10:41 -05:00
Matt Ickstadt
93af92910a Remove travis github_pages deploy
Since it doesn't work at the moment and it takes a lot of time.
2018-08-02 19:10:11 -05:00
Matt Ickstadt
f30ce0184d Fix escaped link preprocessor 2018-08-02 19:04:35 -05:00
Matt Ickstadt
ccb2340fbe Update dependencies 2018-08-02 17:33:56 -05:00
Matt Ickstadt
bbe6e324d0 Merge pull request #757 from mattico/improve-argparse
Improve command-line argument parsing
2018-08-02 17:28:45 -05:00
Matt Ickstadt
a776aa9783 Update documentation for commands 2018-08-02 17:01:47 -05:00
Matt Ickstadt
b8f8e76899 Improve command-line argument parsing 2018-08-02 16:52:41 -05:00
Matt Ickstadt
ac4e00c7c6 Begin development for the 0.2.0 release 2018-08-02 13:31:58 -05:00
Matt Ickstadt
67fde37030 Merge pull request #756 from mattico/test-dir
Fix relative paths in index.html
2018-08-02 13:12:34 -05:00
Matt Ickstadt
b2eb1ace08 Fix relative paths in index.html 2018-08-02 12:43:40 -05:00
Matt Ickstadt
b5fd170008 Merge pull request #755 from mattico/test-dir
Add directory argument to `mdbook test`
2018-08-01 23:11:32 -05:00
Matt Ickstadt
b3665c287d Add directory argument to mdbook test 2018-08-01 17:59:40 -05:00
Matt Ickstadt
436c084b9e Merge pull request #754 from mattico/playpen-api
Use stable rust playground API
2018-08-01 15:22:06 -05:00
Matt Ickstadt
47f85e71a8 Use stable rust playground API
and also add timeouts to these fetches.
2018-08-01 12:38:36 -05:00
Matt Ickstadt
1d448fc8cc (cargo-release) start next development iteration 0.1.11-alpha.0 2018-07-30 19:23:20 -05:00
Matt Ickstadt
add23a43c2 (cargo-release) version 0.1.10 2018-07-30 19:21:18 -05:00
Matt Ickstadt
8ba1830750 Merge pull request #752 from mattico/icon-margin-padding
Icon button hit-test dead-space fix
2018-07-30 19:19:31 -05:00
Matt Ickstadt
76c1c9e0a8 Merge pull request #751 from mattico/update-playpen-bt
Fix rust playground execute API
2018-07-30 19:18:18 -05:00
Matt Ickstadt
d054140117 Fix rust playground execute API 2018-07-30 19:17:53 -05:00
Matt Ickstadt
512826c465 Fix hiding theme menu 2018-07-30 19:06:50 -05:00
Matt Ickstadt
99019b74aa Remove hit-test dead space between buttons 2018-07-30 19:03:29 -05:00
Matt Ickstadt
d87e77edd0 Merge pull request #744 from eminence/noplaypen_class
Add a "noplaypen" class for rust code samples.
2018-07-28 19:18:30 -05:00
Andrew Chin
abfc3009fc Add a "noplaypen" class for rust code samples.
This class will supress the "play" button in the html backend (which you
can also do with the "ignore" class), but it will still let the code be
tested via `mdbook test` (which is not possible with the "ignore" class).

This is useful for code examples that don't really do much (and so the
user doesn't gain much from running them), but as an author you still
want to test them to guard against syntax errors and typos and the like.
2018-07-26 17:55:14 -04:00
Matt Ickstadt
028c8b0f75 Merge pull request #743 from mattico/remove-stylus-redux
Convert Stylus to CSS
2018-07-26 15:37:52 -05:00
Matt Ickstadt
05f3c693a7 Ensure theme selection button is the full-width of the menu 2018-07-26 15:28:09 -05:00
Matt Ickstadt
8b3038e3ef Remove unconditional searchindex.js load
which should have been included in #707
2018-07-26 15:28:09 -05:00
Matt Ickstadt
bc432c8f42 Fix favicon in subfolders 2018-07-26 15:28:09 -05:00
Matt Ickstadt
e88970d172 Don't use CSS variables in media queries
since they don't work :'(
2018-07-26 15:28:09 -05:00
Matt Ickstadt
4c87a0b5f0 Remove stylus support 2018-07-26 15:28:09 -05:00
Matt Ickstadt
ac38f05bb6 Change template to use new CSS 2018-07-26 15:28:05 -05:00
Matt Ickstadt
3119a7e4bf Fix several CSS bugs 2018-07-26 13:49:57 -05:00
Matt Ickstadt
cc745d04f2 Merge css files 2018-07-26 13:37:22 -05:00
Matt Ickstadt
d1a23109e2 Convert stylus files to CSS 2018-07-26 13:37:22 -05:00
Matt Ickstadt
b3e0942bc9 Fix travis deploy out of disk space error 2018-07-26 13:18:33 -05:00
Matt Ickstadt
3e998eb766 (cargo-release) start next development iteration 0.1.10-alpha.0 2018-07-26 12:50:07 -05:00
Matt Ickstadt
2bbabdcd62 (cargo-release) version 0.1.9 2018-07-26 12:44:29 -05:00
Matt Ickstadt
a287a0dcc8 Merge pull request #742 from mattico/narrow-device-style-fixes
Reduce the margins on header icons on narrow devices
2018-07-25 13:41:33 -05:00
Matt Ickstadt
e7afb3340c Reduce the margins on header icons on narrow devices 2018-07-25 13:28:05 -05:00
Matt Ickstadt
b4e15e5357 Merge pull request #741 from mattico/fix-mdbook-test
Fix `mdbook test`
2018-07-25 12:56:28 -05:00
Matt Ickstadt
1d1d4d7c30 Update tests to handle added dummy_book chapter 2018-07-25 12:45:20 -05:00
Matt Ickstadt
35c2d1ff91 Merge pull request #740 from mattico/fix-ios-text-size
Prevent certain mobile browsers from enlarging fonts in landscape ori…
2018-07-25 12:27:16 -05:00
Matt Ickstadt
fd9d27e082 rustfmt 2018-07-25 12:20:48 -05:00
Matt Ickstadt
0e1787c617 Don't run index preprocessor on mdbook test 2018-07-25 12:19:01 -05:00
Matt Ickstadt
e5563182fc Add readme to cause test to fail
The test for `mdbook test` fails due to the index preprocessor which only runs on README files.
2018-07-25 12:14:27 -05:00
Matt Ickstadt
a08255316a Prevent certain mobile browsers from enlarging fonts in landscape orientation 2018-07-25 11:25:09 -05:00
Matt Ickstadt
ebea8c2337 Fix travis cache configuration 2018-07-24 17:29:44 -05:00
Matt Ickstadt
a7342230d5 Merge pull request #739 from mattico/travis-cache-timeout
Increase the travis-ci cache timeout
2018-07-24 17:25:36 -05:00
Matt Ickstadt
15b18a682b Increase the travis-ci cache timeout 2018-07-24 17:23:51 -05:00
Matt Ickstadt
a8590928cf Update env_logger version 2018-07-24 16:55:02 -05:00
Matt Ickstadt
c9a9987aec Merge pull request #738 from mattico/fix-cargo-bin
Move subcommand modules to match cargo conventions
2018-07-24 16:46:57 -05:00
Matt Ickstadt
775377acce Merge pull request #737 from mattico/update-deps-easy
Update dependencies
2018-07-24 16:43:14 -05:00
Matt Ickstadt
5dd0496a4f Update dependencies
`crossbeam` and `time` are removed since they're no longer used.
2018-07-24 16:40:34 -05:00
Matt Ickstadt
f300a21a47 Move subcommand modules to match cargo conventions 2018-07-24 16:34:49 -05:00
Matt Ickstadt
0f89abb1c7 Merge pull request #735 from mattico/fix-travis-deploy
Fix travis deploy script
2018-07-24 14:13:39 -05:00
Matt Ickstadt
b5e32f57dc Fix travis deploy script 2018-07-24 14:12:27 -05:00
Matt Ickstadt
b88abb171c Merge pull request #710 from Eyenseo/master
Fix different font sizes in editor and code
2018-07-24 13:34:34 -05:00
Matt Ickstadt
7c8dd5085b Merge pull request #732 from mattico/sidebar-overflow
Allow sidebar section titles to wrap
2018-07-24 12:11:46 -05:00
Matt Ickstadt
4f793af53b Allow sidebar section titles to overflow 2018-07-24 12:00:48 -05:00
Matt Ickstadt
29b3ff14c7 Merge pull request #719 from lucasem/patch-1
rustdoc codeblock hash escape
2018-07-24 11:09:28 -05:00
Matt Ickstadt
0ac36f2183 Merge pull request #690 from mattico/rustfmt
Remove rustfmt.toml
2018-07-23 12:47:33 -05:00
Matt Ickstadt
5835da2432 Run rustfmt 2018-07-23 12:47:04 -05:00
Matt Ickstadt
646e3f8fd2 Remove rustfmt.toml 2018-07-23 12:39:18 -05:00
Matt Ickstadt
da9be67516 Merge pull request #707 from mattico/search-index-opt
Optimize search index
2018-07-23 12:32:05 -05:00
Matt Ickstadt
d9dbba49ea Fix for relative paths 2018-07-23 12:19:59 -05:00
Matt Ickstadt
384582aeba Cleanup add_doc 2018-07-23 12:08:04 -05:00
Matt Ickstadt
e94078cc9c Fix tests 2018-07-23 12:08:04 -05:00
Matt Ickstadt
e1a46d213e Use JSON search index with JS fallback
This allows the search index to be loaded asynchronously, and should
use fewer resources as it doesn't have to execute the JS.
JS loading is kept as a fallback for CORS issues with file:// URIs in Chrome.
2018-07-23 12:08:04 -05:00
Matt Ickstadt
62c8311301 Don't copy search js when disabled 2018-07-23 12:08:04 -05:00
Matt Ickstadt
b8011de3e8 Warn when search index is >10MB 2018-07-23 12:08:04 -05:00
Matt Ickstadt
019e74041d Use integer doc_refs to shrink the search index
This change reduced the searchindex.js of book_example from 508KB to 317KB.
2018-07-23 12:08:04 -05:00
Matt Ickstadt
8cd7061ff2 Add search.enable config field 2018-07-23 12:08:04 -05:00
Matt Ickstadt
96b99472fd Merge pull request #709 from mattico/no-playpen-no-fetch
Only fetch crates list on pages with playpens
2018-07-23 12:06:02 -05:00
Matt Ickstadt
4d357b6779 Merge pull request #728 from kggp1995/master
- Fixed token type.
2018-07-23 12:01:35 -05:00
Corey Farwell
1e6328c112 Merge pull request #727 from waywardmonkeys/update-toml-query
Update to toml-query 0.7
2018-07-22 17:26:16 -04:00
Ganesh Prasad Kumble
21c24c2815 - Fix token type
OAuth token type doesn't work. Have to change it to PAT.
2018-07-21 19:23:47 +05:30
Corey Farwell
bb8b43d396 Merge pull request #726 from waywardmonkeys/update-elasticlunr
Update to elasticlunr 2.3.
2018-07-19 06:38:58 -04:00
Bruce Mitchener
f07e734efc Update to toml-query 0.7
This was just released with an update to its dependencies, so that
mdBook could update its dependencies.
2018-07-19 17:35:34 +07:00
Bruce Mitchener
db2c16102e Update to elasticlunr 2.3.
This removes one of the remaining dependencies upon pre-1.0 regex.
2018-07-19 11:11:54 +07:00
Matt Ickstadt
cae8a8ffe2 Only fetch crates list on pages with playpens 2018-07-16 19:17:00 -05:00
cetra3
bdb37ec117 Use relative links and translate internal references (#603)
* Relative links for 0.1.8

* Compat for IE11 search
2018-07-11 21:33:44 +08:00
Michael Bryan
01656b610f (cargo-release) start next development iteration 0.1.9-alpha.0 2018-07-09 18:40:43 +08:00
Michael Bryan
b9ff0e8a77 (cargo-release) version 0.1.8 2018-07-09 18:39:35 +08:00
Michael Bryan
0bda57175d Metadata for cargo-release should be in release.toml (#722) 2018-07-09 18:36:55 +08:00
Lucas Morales
374e1d3f94 rustdoc codeblock hash escape
pending merge of rust-lang/rust#51803
2018-07-04 16:54:55 +04:00
Steve Klabnik
6287e6a44f Merge pull request #715 from fitzgen/continuous-integration-instructions
user guide: Add instructions for running `mdbook` in CI
2018-07-03 10:01:19 -07:00
Corey Farwell
953d3821b6 Merge pull request #701 from kubo39/saturating_sub
Use `saturating_sub` instead of `checked_sub.unwrap_or`
2018-06-27 07:40:20 -04:00
Nick Fitzgerald
488ace15ff user guide: Add instructions for running mdbook in CI
This adds instructions for building and testing books in CI on every PR and
push, as well as instructions for how to automatically deploy to gh-pages on
successful CI runs on `master`.

Fixes #714
2018-06-22 10:31:49 -07:00
eyenseo
b452d5e0c7 Fix different font sizes in editor and code
Fixes #705
2018-06-19 22:28:23 +02:00
Hiroki Noda
289028850f Use saturating_sub instead of checked_sub.unwrap_or 2018-06-04 01:42:09 +09:00
Andrew Gauger
2a55ff62f3 Recursively apply preprocessor (#682) 2018-05-20 18:36:19 +08:00
Mathieu David
6bf86806e4 Merge pull request #691 from phansch/update_regex
Update Regex to 1.0.0
2018-05-18 16:58:01 +02:00
Philipp Hansch
90bd7207ec Add minimum required Rust version to README 2018-05-18 09:04:41 +02:00
Mathieu David
27b29fdaf2 Merge pull request #696 from mattico/fix-theme-dir
Fix default theme dir selection
2018-05-16 21:58:41 +02:00
Matt Ickstadt
154e0fb308 Rustfmt 2018-05-16 12:08:23 -05:00
Matt Ickstadt
0de177a344 Add a warning for possible theme directories which will no longer be used 2018-05-16 12:06:55 -05:00
Mathieu David
f154b2fb65 Merge pull request #697 from mattico/fix-fontawesome-gh-pages
Fix FontAwesome directory missing from Github Pages sites
2018-05-15 23:23:09 +02:00
Matt Ickstadt
d7759fbf4d Remove underscore from FontAwesome directory 2018-05-15 12:34:44 -05:00
Matt Ickstadt
f84e670edd Add a .nojekyll file
to allow users to have other files with leading underscore names.
2018-05-15 12:34:44 -05:00
Matt Ickstadt
9a9c625319 Fix default theme dir selection 2018-05-14 14:52:29 -05:00
Tim Ryan
b9ca108fca Support reproducible builds by forcing window.search to use stable key ordering. (#692) 2018-05-14 18:22:21 +08:00
Philipp Hansch
e99dc51fb3 Update Regex to 1.0.0 2018-05-13 12:35:17 +02:00
Mathieu David
7ee5b6643b Merge pull request #689 from gnzlbg/patch-1
remove removed rustfmt options
2018-05-10 10:31:15 +02:00
gnzlbg
42781bcd6b remove removed rustfmt options
Closes #688
2018-05-09 15:29:46 +02:00
Weihang Lo
41d372de26 Update documentation for preprocessor (#686) 2018-05-06 23:48:11 +08:00
Weihang Lo
69599646e7 Add index preprocessor (#685)
* Add index preprocessor

README.md is a de facto index file in markdown-based documentation.
Hence, we respect to README.md and convert it into index.html.

* Fix warning for unused variables

* Update tests for config

* Match file stem case-insensitively for IndexPreprocessor

* Add tests for IndexPreprocessor

* Update book example to fit index preprocessor
2018-05-04 19:41:28 +08:00
Matt Ickstadt
69fef40e57 Improve print output (#680)
* Update print styles for new sidebar behavior

* Hide copy icons in print output

* Wait for mathjax rendering to complete before printing

* Remove old wrapping css
Browsers this old are already hilariously broken, so we don't need these fallbacks.

* Change mathjax script type
Chrome won't execute this if it's not marked as js

* Ensure page has rendered before printing
In certain situations Chrome willl fire window.onLoad before it's
done rendering. Add a 100ms delay to work around this.
2018-05-01 20:29:34 +08:00
Michael Bryan
a323620e02 (cargo-release) start next development iteration 0.1.8-alpha.0 2018-04-23 07:42:43 +08:00
Michael Bryan
ea0b835b38 (cargo-release) version 0.1.7 2018-04-23 07:41:31 +08:00
Mathieu David
58f0f3b0f2 Merge pull request #672 from mattico/update-deps
Update deps
2018-04-22 22:58:35 +02:00
Matt Ickstadt
e7a61efb39 Fix warning 2018-04-22 13:01:10 -05:00
Matt Ickstadt
d48bc29373 Update dependencies 2018-04-22 13:01:05 -05:00
Michael Bryan
72f154bee4 (cargo-release) start next development iteration 0.1.7-alpha.0 2018-04-22 00:45:07 +08:00
Matt Brubeck
1c71eaa964 Put the search bar into an HTML form (#669)
This enables "Add a keyword for this search" in the contex menu for the
search field, in Firefox and other browsers.
2018-04-21 23:27:51 +08:00
Matt Ickstadt
c195aa990d Update dependencies (#670) 2018-04-21 23:22:05 +08:00
Mathieu David
34bdcaf8b3 Merge pull request #660 from THeK3nger/doc-mathjax-note
Add a note in MathJax documentation
2018-04-16 02:24:49 +02:00
Michael Bryan
41399fc29c Revert "Fixes the search box overlapping with content when first shown (#666)" (#667)
This reverts commit 7f82a197b9.
2018-04-11 10:23:56 +08:00
Michael Bryan
7f82a197b9 Fixes the search box overlapping with content when first shown (#666) 2018-04-10 22:02:27 +08:00
Gwen Lofman
71d44933f0 Replace his with their in reference to reader (#665)
The reader should not be assumed male; I'm a developer and user,
I'm not male.  Makes documentation's language gender neutral to
make it more welcoming to people that do not use he/him pronouns.
2018-04-10 07:02:53 +08:00
Matt Ickstadt
f01bf88e69 Fix several theme issues (#648)
* Don't hide page content when displaying search

* Decrease sidebar animation time

* Fix search key event handler
which wasn't completely de-jqueryified.

* Avoid reflowing page content on small screens
This reduces jank caused by reflowing the page text while animating the
sidebar, and it looks nicer.

* Don't use HTMLParentNode.prepend()
since edge doesn't support it yet

* Don't animate menu border bottom color
since it's the same color as the background, which isn't animated.

* Small CSS improvments
- Remove invalid `pointer: cursor` style
- Disable transitions for noscript to stop page from spazzing on every load
- Add `cursor: pointer` to mark
- Disable `cursor: pointer` on noscript menu-title

* JS fixes

- Load MathJax async
- Always use local fontawesome and clipboard.js
- Move js class to html element to make theme switching easier

* Give the print button a bit more margin
2018-04-09 12:10:44 +08:00
Michael Bryan
b5ea84c60d Remove unnecessary travis jobs (#664)
* Removed all the unnecessary CI jobs

* Updated dependencies

* Removed a deprecation warning
2018-04-07 15:47:08 +08:00
Nils
148c806e34 Prevent search from triggering when editing code (#653) 2018-04-07 06:31:51 +08:00
Davide Aversa
38279deed7 Add a note in MathJax documentation 2018-04-03 10:17:06 +02:00
Bastien Orivel
55f7ed1c37 Replace tempdir by tempfile (#650)
The former has been deprecated in favor of the latter
2018-03-27 07:47:37 +08:00
Anders Rasmussen
eb0f7179ab Use git config to get author name in mdbook init (#649)
* Use `git config` to get author name in `mdbook init`

* Return `None` if `git` command fails

* Use `.ok()?` to convert from Result to Option and return early if `None`
2018-03-26 22:37:11 +08:00
Matt Ickstadt
5fb3675151 Update elasticlunr-rs (#646)
* Update dependencies

* Use config structs from elasticlunr-rs

* Update searchindex fixture
2018-03-20 20:22:35 +08:00
Michael Bryan
77b4f6a940 (cargo-release) start next development iteration 0.1.6-alpha.0 2018-03-16 07:38:05 +08:00
Michael Bryan
6308da699a (cargo-release) version 0.1.5 2018-03-16 07:36:40 +08:00
Guillaume Gomez
62a727c041 Fix search (#645) 2018-03-16 07:37:08 +08:00
Michael Bryan
3bc5d907f4 Merge pull request #641 from rust-lang-nursery/pre-release
Pre release
2018-03-15 09:24:26 +08:00
Michael Bryan
3cd12e7092 (cargo-release) start next development iteration 0.1.5-alpha.0 2018-03-15 09:22:59 +08:00
Michael Bryan
c8bbfd4bc1 (cargo-release) version 0.1.4 2018-03-15 09:21:49 +08:00
Michael Bryan
d48a27f94f Updated the appveyor CI image 2018-03-15 09:19:58 +08:00
Michael Bryan
8c456666ff Added a stability warning to the API docs 2018-03-14 23:48:57 +08:00
Michael Bryan
48b0f547c5 Updated serde dependencies 2018-03-14 23:48:57 +08:00
Michael Bryan
867fbfec05 Updated the call site for handlebars rendering 2018-03-14 23:48:56 +08:00
Michael Bryan
951c873df6 Updated deps 2018-03-14 23:48:56 +08:00
Michael Bryan
4af155e963 Exposed the sections inside a book (#642) 2018-03-14 23:47:17 +08:00
Dylan Maccora
07719a8e0e Adding for content to book.toml on init (#627)
* Obtaining author name from gitconfig

* Writing theme to config on init

* Addressing a FIXME came across

* Add request for book title.
2018-03-14 23:27:56 +08:00
Guillaume Gomez
cc92d665ca Improve css so anchor don't go under sidebar (#638) 2018-03-14 23:23:55 +08:00
Pawel Duzinkiewicz
b86533b2a1 pulldown-cmark updated to 0.1.2, fixmes removed, new cargo.lock generated. (#639) 2018-03-11 22:17:38 +08:00
Matt Ickstadt
b2ad669c61 Search with Elasticlunr, updated (#604)
* Add search with elasticlunr.js

This commit adds search functionality to mdBook, based on work done by @phaiax. The in-browser search code uses elasticlunr.js to execute the search, using an index generated at book build time by elasticlunr-rs.

* Add generator comment
Someone on Reddit was wondering how the rust book was generated and said they checked the source. Thought I'd put this here. Might be a good idea to have a little footer "made with mdBook", but this'll do for now.

* Remove search/editor file override behavior

* Use for loop for book iterator

* Improve HTML regex

* Fix search CORS in file URIs

* Use ammonia to sanitize HTML

* Filter html5ever log messages
2018-03-07 21:02:06 +08:00
Sebastian Thiel
bb043ef660 Add complete preprocessor example (#629)
* First version of preprocessor example, with quicli

It seems it's not worth it right now.

* Remove quicli, just to simplify everything

* Finish de-emphasise example

* Finish preprocessor example in book

* Rename preprocessor type

* Apply changes requested in review

* Update preprocessor docs with latest code

[skip CI]
2018-02-24 18:14:52 +08:00
Sorin Davidoi
82aef1bc3f fix(theme/book): Workaround focusout bug in macOS and iOS (#630) 2018-02-24 17:23:45 +08:00
Dylan Maccora
38c883e1ef Changing clap settings (#624) 2018-02-18 15:10:47 +08:00
Sorin Davidoi
8a00a004d8 Handle some cases when JavaScript is disabled (#614)
* feat(theme/index): Assume the sidebar is initially visible

In case the inline script does not execute, the fallback is to show the sidebar.

* feat(theme/index): Hide sidebar toggle and theme selector buttons when JavaScript is disabled

Makes no sense to show them in this case since they do not work.
2018-02-18 15:05:15 +08:00
Bulat Musin
6af77a7792 Update documentation to reflect addition of clean subcommand. (#607)
* update documentation

Update README.md and User Guide to reflect addition of `clean`
subcommand. Do minor spelling fixes too.

* fix grammar in `clean` documentation
2018-02-18 15:04:04 +08:00
Michael Bryan
b5ca820345 (cargo-release) start next development iteration 0.1.4-alpha.0 2018-02-16 07:47:35 +08:00
Michael Bryan
b765023da3 (cargo-release) version 0.1.3 2018-02-16 07:45:52 +08:00
Sorin Davidoi
d306aed587 Accessibility improvements (#611)
* fix(theme/book/themes): Check for control keys in event listener

* fix(theme/index): Menu role for theme selector

* fix(theme/book/themes): Handle focus when toggling theme list

* feat(theme/book/themes): Handle ArrowUp, ArrowDown, Home and End
2018-02-15 07:37:19 +08:00
Sorin Davidoi
89a5dbaf9a fix(theme/stylus/sidebar): Contain scrolling to the sidebar (#612)
> A position fixed left navigation bar does not want to hand off scrolling to the document because a scroll gesture performed on the navigation bar is almost never meant to scroll the document. In this case, the author can use contain on the sidebar to prevent scrolling from being chained to the parent document element.

https://wicg.github.io/overscroll-behavior/#motivating-examples
2018-02-15 07:24:39 +08:00
Ryan Scheel
6961247f56 Include Cargo.lock (#620) 2018-02-15 07:03:10 +08:00
Sorin Davidoi
07551760c9 feat(theme/stylus/sidebar): Reduce padding on non-touch devices (#615)
Closes #594.
2018-02-15 06:59:55 +08:00
Sorin Davidoi
990daceed5 feat(theme/book): Scroll to top when clicking the page title (#613)
Common pattern, especially on mobile devices where the page can be quite long.
2018-02-09 18:34:18 +08:00
Mathieu David
2989096188 Merge pull request #609 from bchatard/typo
Fix typo in format configuration
2018-02-05 15:17:24 +01:00
bchatard
03c6c44e5b Fix typo in format configuration 2018-02-05 13:01:17 +01:00
Ofek Lev
31a370d149 fix readme (#606) 2018-02-05 07:11:55 +08:00
Bulat Musin
0bc1030a02 implement clean subcommand (#583) 2018-02-04 21:00:29 +08:00
boxdot
43fcd00cd5 Inline footnotes. (#600) 2018-02-02 20:15:48 +08:00
Mathieu David
3d83b784b3 Merge pull request #601 from tshepang/patch-1
doc: small fixes
2018-02-01 11:31:55 +01:00
Tshepang Lekhonkhobe
5d42738a79 doc: small fixes 2018-02-01 03:29:39 +02:00
Michael Bryan
1f4dab3e5c (cargo-release) start next development iteration 0.1.3-alpha.0 2018-01-31 19:19:50 +08:00
Michael Bryan
7181993b43 (cargo-release) version 0.1.2 2018-01-31 19:18:02 +08:00
boxdot
bf9f58e11b Add docs for mdBook specific include feature (#593)
* Add docs for mdBook specific include feature.

Also:
* Fix bug in take_lines taking `end`-many lines instead of
  `end-start` many.
* Handle special case `include:number` as including a single line.
* Start counting lines at 1 and not 0.

* Merge mdBook and rust specific features into one chapter.
2018-01-31 18:57:47 +08:00
Steve Klabnik
3ba71c570c Handle input path with regards to custom css (#598)
* Handle input path with regards to custom css

Before, when someone like the Reference set their extra css as
"theme/reference.css" in their book.toml, this path would be treated as
relative to the invocation of mdbook, and not respect the input path. This
PR modifies these relative paths to do so.

Fixes the build of https://github.com/rust-lang/rust/pull/47753 which
blocks updating rustc to mdbook 0.1

* don't use file-name

the style name is theme/reference.css, this results in a Err(StripPrefixError(())), which means that we push only the file_name, losing the theme bit
2018-01-30 12:29:09 +08:00
Sorin Davidoi
674e58e747 fix(theme): Use aria-label alonside title (#568)
Tested this on macOS with VoiceOver, and it does not pick up the title as the text of the button. Kind of makes sense, since title and aria-label are not the same. This will make sure that the buttons and links are labeled properly.
2018-01-27 18:52:47 +08:00
Michael Bryan
348c5d07c5 (cargo-release) start next development iteration 0.1.2-alpha.0 2018-01-27 11:56:22 +08:00
Michael Bryan
1790b04e03 (cargo-release) version 0.1.1 2018-01-27 11:54:27 +08:00
Michael Bryan
50ee15472b Updated the light theme to have a lighter scrollbar (#590) 2018-01-27 11:52:43 +08:00
Michael Bryan
ffb90bb9e2 Made sure we create the themes directory (#586) 2018-01-26 14:38:53 +08:00
Sorin Davidoi
186e649530 feat(src/theme): Scrollbar theme (#563) 2018-01-26 01:17:02 +08:00
Michael Bryan
adc1f4ade7 Reverted #549 (#565) 2018-01-26 01:12:10 +08:00
Michael Bryan
b777a318f7 Expose functionality for creating core types (#578)
* You can now add chapters to a Book

* Made the RenderContext::new() constructor public
2018-01-26 01:11:48 +08:00
Michael Bryan
30e3b83167 Updated Cargo.toml metadata to make releases easier (#584) 2018-01-26 01:11:32 +08:00
Sorin Davidoi
f082187844 fix(theme/book): Use passive listeners for touchstart, touchmove (#575) 2018-01-25 18:44:22 +08:00
Michael Bryan
6119972fa7 Merge pull request #581 from bmusin/patch-3
fix typo
2018-01-25 17:49:40 +08:00
Michael Bryan
a910435fd9 Merge pull request #577 from Michael-F-Bryan/missing-backends-arent-fatal
Missing backends shouldn't be fatal
2018-01-25 07:33:54 +08:00
Bulat Musin
53b902b479 remove dot for consistency (#580) 2018-01-25 07:32:52 +08:00
Bulat Musin
2e9d8671a0 fix typo (insert dash) (#582) 2018-01-25 07:32:33 +08:00
Bulat Musin
50cdfc9623 fix typo (#579) 2018-01-25 07:25:56 +08:00
Bulat Musin
d47f4dce7f fix typo 2018-01-24 21:52:51 +03:00
Michael Bryan
bda23f0183 Missing backends are no longer fatal 2018-01-25 01:15:29 +08:00
Michael Bryan
1fbad982d8 (cargo-release) start next development iteration 0.1.1-alpha.0 2018-01-23 22:06:55 +08:00
Michael Bryan
fada73eb74 (cargo-release) version 0.1.0 2018-01-23 22:05:07 +08:00
Michael Bryan
dee91b146b Added Michael-F-Bryan to the authors list 2018-01-23 22:04:45 +08:00
Michael Bryan
492f393c0b Escaped the book's example {{#include ...}} tag 2018-01-23 21:13:33 +08:00
Sorin Davidoi
bcfb37d964 fix(theme): Sticky header support in Safari (#572)
Safari scrolls on body, not on the html tag. It also needs sticky to be prefixed.
2018-01-23 21:13:11 +08:00
Markus Kohlhase
b1b8ba4b98 fix(doc): make installation from git work again (#570)
cargo install --git https://github.com/rust-lang-nursery/mdBook.git
leads to error: multiple packages with binaries found: mdbook, mdbook-wordcount
Fix: append name of binary (`mdbook`).
2018-01-23 21:07:14 +08:00
Sorin Davidoi
0531b585e4 fix(theme/index): Use localStorage, not store (#574)
* fix(theme/index): Use localStorage, not store

* fix(theme/index): Handle quotes values in localStorage
2018-01-23 20:30:50 +08:00
Michael Bryan
5379a0bdf8 Made the logging a lot quieter by default (#569) 2018-01-23 01:28:37 +08:00
Michael Bryan
0d146ffa82 Improve SUMMARY parser error messages (fixes #566) (#567) 2018-01-22 20:47:29 +08:00
Sorin Davidoi
0bc3544c81 refactor: Remove store.js (use localStorage) (#550) 2018-01-22 07:04:16 +08:00
Michael Bryan
c89245b45b Recursively apply replace_all() when running the links preprocessor (#564)
* Looks like we forgot to recursively apply replace_all() in #532

* Removed some print statements

* Made sure we ignore the rendered dummy_book
2018-01-22 06:44:28 +08:00
Sorin Davidoi
05e4157c2e refactor(theme/book): Split into modules (#556)
Advantages:
 - Easier to reason about
 - Can easily disable some modules when debugging
 - Shared dependencies are explicit (playpen_text)
 - Enables some fancier things later one (e.g. run `codeSnippets` slightly later, to avoid blocking the page)

I'm aware that `codeSnippets` should be split into the highlighter and the editor, but I'm not sure I understand exactly how they interact so I've left it as it is for now.
2018-01-21 23:01:57 +08:00
Michael Bryan
9fe19d8f31 Increase Documentation Coverage (#543)
* Added documentation to the `config` module

* Added an example to the `config` module

* Updated the docs in lib.rs regarding implementing backends

* Started writing an alternate backends walkthrough

* Mentioned the output.foo.command key

* Added example output

* Added a config section to the backends tutorial

* Finished off the backends tutorial

* Made sure travis checks mdbook-wordcount

* Fixed the broken link at in the user guide

* Changed how travis builds the project

* Added a conclusion

* Went through and documented a lot of stuff

* Added a preprocessors chapter and updated For Developers
2018-01-21 22:35:11 +08:00
Michael Bryan
232a923676 Added a windows-specific tee equivalent (#561)
* Added a windows-specific `tee` equivalent

* Changed how the windows "tee" command gets quoted

* Temporarily disabled the backends_receive_render_context_via_stdin test
2018-01-20 21:46:44 +08:00
Sorin Davidoi
3d1a311638 refactor: Remove jQuery file (#562) 2018-01-20 15:56:32 +08:00
Sorin Davidoi
80f42675d6 feat(theme/stylus/menu): Make sticky (#551)
* feat(theme/stylus/menu): Make sticky

* feat(theme/stylus/menu): Faint bottom border

* feat(theme/book): Auto hide menu when scrolling down

* feat(theme/stylus/menu): Don't hide title

* feat(theme/stylus/menu): Only show bottom border when sticky

* fix(theme/stylus/menu): Don't hide when sidebar is expanded

* feat(theme/book): Show menu bar on hover
2018-01-19 23:41:50 +08:00
Michael Bryan
fa84da0856 Stop pulling pulldown-cmark from master (#555)
* Manually implemented PartialEq for pulldown_cmark types

* Fixed an issue where we wouldn't skip a tag properly
2018-01-19 01:21:04 +08:00
Michael Bryan
947d0312c6 Merge pull request #554 from sorin-davidoi/fix-disable-stylesheet
fix(theme/book): Disable stylesheets by property, not attribute
2018-01-19 00:40:10 +08:00
Sorin Davidoi
05a0d7e625 fix(theme/book): Disable stylesheets by property, not attribute
Closes #553.
2018-01-18 17:12:41 +01:00
Michael Bryan
7b356b7530 Merge pull request #538 from sorin-davidoi/remove-jquery
Remove jQuery
2018-01-18 07:26:18 +08:00
Michael Bryan
d44b67bbcc Merge pull request #552 from projektir/editor-docs
Documenting the editor #521
2018-01-18 07:19:52 +08:00
Michael Bryan
7b4b70a49d Merge pull request #532 from JaimeValdemoros/implementing-preprocessors
implementing preprocessors
2018-01-18 07:18:54 +08:00
Jaime Valdemoros
1136f671a0 Log as each preprocessor is run 2018-01-17 19:05:15 +00:00
Jaime Valdemoros
80a20eb730 Use Arc instead of lazy_static for dummy preprocessor 2018-01-17 19:02:25 +00:00
Jaime Valdemoros
0d62578c7b Make Preprocessor context store config and root 2018-01-17 09:44:52 +00:00
projektir
57f960a03b Documenting the editor #521 2018-01-16 21:26:13 -08:00
Jaime Valdemoros
47cc57177d Update comment with rustdoc link 2018-01-16 23:02:50 +00:00
Jaime Valdemoros
90fa1b4909 Turn chained if's into match 2018-01-16 22:39:11 +00:00
Jaime Valdemoros
f2d7b705af Pull out default preprocessors into function 2018-01-16 22:39:11 +00:00
Jaime Valdemoros
4177288b11 Add test to make sure pre-processors are being run 2018-01-16 22:39:11 +00:00
Jaime Valdemoros
b599956516 Move preprocess field location and add tests 2018-01-16 22:39:11 +00:00
Jaime Valdemoros
08027b86cc Revert reordering 2018-01-16 22:39:11 +00:00
Jaime Valdemoros
b98ed3f794 Clean up LinkPreprocessor exports and use explicit PreprocessorContext struct 2018-01-16 22:39:11 +00:00
Jaime Valdemoros
9c922cf26b Add LinkPreprocessor::new constructor 2018-01-16 22:39:11 +00:00
Jaime Valdemoros
144358bec6 Change name of link preprocessor 2018-01-16 22:39:11 +00:00
Jaime Valdemoros
4cc708e00f Preprocess links by default 2018-01-16 22:39:11 +00:00
Jaime Valdemoros
12815fe399 Add pre-processing step to build method of MDBook 2018-01-16 22:39:11 +00:00
Jaime Valdemoros
f282a553fd Remove unnecessary mem::replace 2018-01-16 22:39:11 +00:00
Jaime Valdemoros
966811061b Start determining preprocessors 2018-01-16 22:39:11 +00:00
Jaime Valdemoros
cad76a9f6c Factor out replace_all preprocessor 2018-01-16 22:39:11 +00:00
Jaime Valdemoros
01df904bb3 Initial Preprocessor trait implementation 2018-01-16 22:39:11 +00:00
Sorin Davidoi
5a4adcce53 refactor(theme): Remove jQuery 2018-01-16 16:31:08 +01:00
Michael Bryan
bf093e2f5f Temporarily ignore OSX jobs on travis (#549)
* Made sure the CmdRenderer always creates the destination dir

* Commented out osx jobs temporarily
2018-01-16 23:29:46 +08:00
Michael Bryan
be9a524eeb Made sure the CmdRenderer always creates the destination dir 2018-01-16 21:39:59 +08:00
Sorin Davidoi
b0e91193e9 Meta theme color (#547)
* feat(theme/index): Add meta tag for theme-color

* feat(theme/book): Sync theme-color meta tag with the current theme
2018-01-16 20:29:20 +08:00
Sorin Davidoi
61fad2786b Improve accessibility (#535)
* fix(theme/index): Use nav element for Table of Content

* fix(renderer/html_handlebars/helpers/toc): Use ol instead of ul

Chapters and sections are ordered, so we should use the appropriate HTML tag.

* fix(renderer/html_handlebars/helpers/toc): Hide section number from screen readers

Screen readers have this functionality build-in, no need to present this. Ideally, this should not even be in the DOM tree, since the numbers can be shown by using CSS.

* fix(theme/index): Remove tabIndex="-1" from .page

Divs are not focusable by default

* fix(theme): Make sidebar accessible

Using aria-hidden (together with tabIndex) takes the links out of the tab order.
http://heydonworks.com/practical_aria_examples/#progressive-collapsibles

* fix(theme/index): Wrap content inside main tag

The main tag helps users skip additional content on the page.

* fix(theme/book): Don't focus .page on page load

The main content is identified by the main tag, not by auto-focusing it on page load.

* fix(theme/index): Make page controls accessible

* fix: Make theme selector accessible

- Use ul and li (since it is a list)
- Add aria-expanded and aria-haspopup to the toggle button
- Use button instead of div (buttons are accessible by default)
- Handle Esc key (close popup)
- Adjust CSS to keep same visual style

* fix(theme/stylus/sidebar): Make link clickable area wider

Links now expand to fill the entire row.

* fix(theme): Wrap header buttons and improve animation performance

Previously, the header had a fixed height, which meant that sometimes the print button was not visible. Animating the left property is expensive, which lead to laggy animations - transform is much cheaper and has the same effect.

* fix(theme/stylus/theme-popup): Theme button inherits color

Bug introduced while making the popup accessible

* fix(theme/book): Handle edge case when toggling sidebar

Bug introduced when switching from animating left to using transform.
2018-01-15 21:26:53 +08:00
Michael Bryan
9ab54412ea Made it so the CmdRenderer writes directly to the child's stdin (#544) 2018-01-14 19:14:27 +08:00
Michael Bryan
be949ceae8 Cleaned up the is_legacy_format() function 2018-01-14 04:54:11 +08:00
Michael Bryan
a1b6ccc29a Override configuration using environment variables (#541)
* Added the ability to update config settings from env vars

* Added tests

* Documented that you can override configuration with environment
variables

* Refactored the config get() methods to use toml-query

* Made the `Updateable` trait more generic
2018-01-14 02:38:43 +08:00
vabc3
e825357848 Add option to disable section label in html (#533) 2018-01-08 00:31:46 +08:00
vabc3
fd8f3bb415 Remove unneeded mut modifier in test (#534) 2018-01-08 00:25:45 +08:00
Michael Bryan
fd7e8d1b7b Add support for alternative backends (#507)
* Added a mechanism for creating alternate backends

* Added a CmdRenderer and the ability to have multiple renderers

* Made MDBook::load() autodetect renderers

* Added a couple methods to RenderContext

* Converted RenderContext.version to a String

* Made sure all alternate renderers are invoked as `mdbook-*`

* Factored out the logic for determining which renderer to use

* Added tests for renderer detection

* Made it so `mdbook test` works on the book-example again

* Updated the "For Developers" docs

* Removed `[output.epub]` from the example book's book.toml

* Added a bit more info on how backends should work

* Added a `destination` key to the RenderContext

* Altered how we wait for an alternate backend to finish

* Refactored the Renderer trait to not use MDBook and moved livereload to the template

* Moved info for developers out of the book.toml format chapter

* MOAR docs

* MDBook::build() no longer takes &mut self

* Replaced a bunch of println!()'s with proper log macros

* Cleaned up the build() method and backend discovery

* Added a couple notes and doc-comments

* Found a race condition when backends exit really quickly

* Added support for backends with arguments

* Fixed a funny doc-comment
2018-01-07 22:10:48 +08:00
Jan Likar
dedc208a6a Prohibit 'print.md' files (#524)
* Prohibit 'print.md' files

Fix #258 by emmiting an error whenever an mdBook contains a
"print.md" file in its root.

* Apply suggested changes

* Add tests
2018-01-07 00:02:23 +08:00
boxdot
e461610dab Implement partial include of source files (#520)
* Implement partial include of source files.

The macro `{{include some_file}}` accepts now optional line number
arguments, s.t. the specified line range is included. The following
forms are supported:

* `{{include some_file::}}` is equivalent to `{{include some_file}}`
* `{{include some_file:from:}}` includes lines [from, infinity)
* `{{include some_file::to}}` includes lines [0, to]
* `{{include some_file:from:to}}` includes lines [from, to]

* Remove the special case IncludeFull which is IncludeFrom(0).

* Use Range, RangeFrom, RangeTo and RangeFull to represent include-ranges.

Also:
* Move out introduced methods as free functions.
* Introduce RangeArgument trait as long it is unstable in stdlib.
* Use itertools for joining of lines on the fly.
* Split tests.
* Simplify include file argument parsing.

* Make utils::string private and link collections_range feature issue.
2018-01-06 05:03:30 +08:00
Michael Bryan
e791f250fa Workaround for travis-ci/travis-ci#4704 (#529)
large writes to stdout error with errno 11 (resource unavailable)
2018-01-06 04:47:59 +08:00
Michael Bryan
cd1abf8ec2 Revert "Added dummy df statements to debug the travis failures (#526)" (#528)
This reverts commit 2b943d703f.
2018-01-06 04:41:26 +08:00
Michael Bryan
2b943d703f Added dummy df statements to debug the travis failures (#526)
https://internals.rust-lang.org/t/rustdoc-ice-in-ci-build/6480/2
2018-01-05 18:39:23 +08:00
Michael Bryan
b9ab71b231 Reformatted the README and added a link to the master docs (#525) 2018-01-05 11:32:54 +08:00
Mario Nebl
7c81335c9a Use <button> for menu bar (#523) 2018-01-04 17:19:20 +08:00
Michael Bryan
e74c376833 You need to call rx.iter() to iterate over events from a channel (#522) 2018-01-03 19:32:49 +08:00
Michael Bryan
6ba0162ff7 Merge pull request #519 from Michael-F-Bryan/rollback-iron-version
Roll back iron version in Cargo.toml
2018-01-02 23:27:21 +08:00
Michael Bryan
b5382f49c6 Merge pull request #474 from stgn/sidebar-swipe
Basic swipe gesture functionality for opening/closing sidebar
2018-01-02 22:10:30 +08:00
Michael Bryan
daade63c27 Rolls back the Iron version due to issues with staticfile 2018-01-02 22:02:34 +08:00
Michael Bryan
9480ac0ea6 All git commands in github_pages.sh are now --quiet 2017-12-30 23:31:32 +08:00
Michael Bryan
65900b87e6 Use cargo run for github pages instead of hard-coding the binary path 2017-12-30 21:47:53 +08:00
Michael Bryan
d4a5176f26 Forgot to install npm deps globally in #516 2017-12-30 20:23:06 +08:00
Michael Bryan
c721ba82b2 Update travis CI (#516)
* Use japaric/trust for travis configuration

* Moved the github pages logic (not running the script breaks the build)

* Removed the x86 linux musl build
2017-12-30 19:15:17 +08:00
Michael Bryan
bd134fbaa4 Merge pull request #517 from Michael-F-Bryan/update-deps
Update dependency versions and made logging more readable
2017-12-30 19:05:46 +08:00
Michael Bryan
cba16a0083 Updated dependencies and made logging more readable 2017-12-30 18:43:46 +08:00
Michael Bryan
549a9ffd54 Merge pull request #470 from stgn/sidebar-page-ux
Improve experience on smaller screens
2017-12-30 16:15:50 +08:00
Michael Bryan
06c9d67e75 Merge pull request #515 from jridgewell/playpen-default
Implement playpen defaults
2017-12-21 14:36:09 +08:00
Justin Ridgewell
61356ce5fe Implement playpen defaults
Avoids issues where we enable `editable` but forget to specify `editor`
(eg, https://github.com/rust-lang/rust-by-example/issues/963).  Since we
already include Ace editor, seems like we can just treat it as the
default.
2017-12-21 00:18:12 -05:00
Shane Nelson
31fb443562 Cleanup and various fixes 2017-12-18 00:14:25 -05:00
Shane Nelson
a2759b7bd2 Prevent horizontal scroll on mobile browsers if page wrapper is pushed off-screen 2017-12-17 23:04:30 -05:00
Shane Nelson
71689da6b1 Force hidden sidebar on load for screen widths smaller than sidebar plus content and simplify styles 2017-12-17 23:04:30 -05:00
Shane Nelson
6e90e520d6 Avoid resizing page/content on sidebar toggle 2017-12-17 23:04:30 -05:00
Michael Bryan
65acb355d7 Merge pull request #513 from Michael-F-Bryan/error-messages
Added better error messages for missing CSS/JS
2017-12-14 20:28:28 +11:00
Michael Bryan
89eff2d824 Added better error messages for missing CSS/JS 2017-12-14 20:03:17 +11:00
Michael Bryan
a280a3003b Merge pull request #447 from Listwon/clipboard
Fix copy to clipboard is available only for rust snippets
2017-12-13 14:32:41 +11:00
Michael Bryan
cb6f2289cf Merge pull request #510 from Michael-F-Bryan/book-json-warning
Added a warning if people use the book.json config file
2017-12-13 13:18:51 +11:00
Michael Bryan
396426662d Made mdbook watch and mdbook serve rebuild the book again (#508)
Made `mdbook watch` and `mdbook serve` rebuild the book again
2017-12-13 12:04:24 +11:00
Michael Bryan
718d251c7f Added a warning if people use the book.json config file 2017-12-13 11:55:37 +11:00
Michael Bryan
d69bc9c7c3 Merge pull request #491 from Michael-F-Bryan/book-representation-3
WIP: Book representation - Attempt 3
2017-12-12 19:24:13 +11:00
Michael Bryan
a46e2e2b27 Merge branch 'master' into book-representation-3 2017-12-11 19:06:09 +11:00
Michael Bryan
75dac15f09 Fixed a couple issues with the docs 2017-12-11 18:50:31 +11:00
Michael Bryan
5041359817 Updated the pulldown-cmark patch in Cargo.toml 2017-12-11 17:36:13 +11:00
Michael Bryan
ff9e0b0add Made sure create_missing also creates the parent directory 2017-12-11 17:29:32 +11:00
Michael Bryan
148511eceb Able to parse all existing SUMMARY.md files 2017-12-11 17:20:05 +11:00
Michael Bryan
f5e9b857de Rewrote summary parser from a state machine to use recursive descent 2017-12-11 15:17:20 +11:00
Michael Bryan
4f4e86db3a Added tests to make sure we parse existing SUMMARY.md's 2017-12-11 12:26:11 +11:00
Michael Bryan
ebcf41c25b Improved error messages using error_chain::ChainedError::display_chain() 2017-12-11 11:42:36 +11:00
Michael Bryan
1b51cd244e Moved the book examples to the top level lib.rs 2017-12-11 11:29:30 +11:00
Michael Bryan
be4654c9c2 Fleshed out the docs for the book module 2017-12-11 11:24:43 +11:00
Michael Bryan
ace0b51fb6 Put the create_missing feature back in 2017-12-11 10:32:35 +11:00
Michael Bryan
9950f69c48 Removed the MDBook::read_config() method because it's redundant now 2017-12-10 23:13:46 +11:00
Michael Bryan
12d1ed5558 The example book renders correctly 2017-12-10 22:59:35 +11:00
Michael Bryan
751da4f05f Added a test to make sure you can include rust files in chapters 2017-12-10 22:59:35 +11:00
Michael Bryan
527fc5cf79 Completely removed the create_missing option from MDBook 2017-12-10 22:52:20 +11:00
Michael Bryan
f993677626 All tests finally pass! 2017-12-10 22:52:00 +11:00
Michael Bryan
21498631b3 Made sure the dummy book can build 2017-12-10 22:50:57 +11:00
Michael Bryan
8b21da9950 Fleshed out book creation 2017-12-10 22:50:57 +11:00
Michael Bryan
47eb4788cb Introduced the BookBuilder.
- You now use a `BookBuilder` for creating a book directory tree

- This also removes the `--no-create` argument
2017-12-10 22:49:40 +11:00
Michael Bryan
cafb8b75e7 The library not compiles (probably completely broken) 2017-12-10 22:44:20 +11:00
Michael Bryan
4c6c696c87 Copied across the summary parser and Book structure (doesn't compile) 2017-12-10 22:43:12 +11:00
Michael Bryan
3838fa0e68 Merge pull request #501 from lifta42/master
Fix misplaced "previous" icon
2017-12-10 22:34:09 +11:00
Michael Bryan
4619ab60b0 (cargo-release) start next development iteration 0.0.29-alpha.0 2017-12-09 21:26:12 +11:00
Michael Bryan
2a5409db20 (cargo-release) version 0.0.28 2017-12-09 21:23:44 +11:00
Michael Bryan
dc89a82329 Merge pull request #506 from Michael-F-Bryan/quickfix
Added a quick fix so if the config isn't found we use a default
2017-12-09 21:18:34 +11:00
Michael Bryan
42ff5a895c Added a test to make sure book.toml isn't required 2017-12-09 20:46:39 +11:00
Michael Bryan
8ee795045a Added a quick fix so if the config isn't found we use a default 2017-12-09 20:36:23 +11:00
Michael Bryan
f22835f7bc (cargo-release) start next development iteration 0.0.28-alpha.0 2017-12-07 21:40:45 +11:00
Michael Bryan
1f84f66041 Bumped the version number in preparation for the next release 2017-12-07 21:35:50 +11:00
lifta42
9143110a43 Optimized the stylesheet for better performance 2017-12-06 16:20:22 +08:00
Michael Bryan
e735bc6d3e Merge pull request #500 from cspiegel/create-missing
WIP: Add a create-missing option to book.toml.
2017-12-06 00:30:49 +08:00
Chris Spiegel
803df90efa Add tests to check create-missing. 2017-12-02 22:53:19 -08:00
lifta42
3b136689ee Fix a CSS bug to show arrow properly
The arrow for "previous chapter" was on the incorrect position when screen width is between 1060px and 1250px.
2017-12-02 14:25:24 +08:00
Michael Bryan
b614b0fd65 Merge pull request #454 from projektir/header_partial
Adding a header partial integration #453
2017-12-02 13:36:09 +08:00
projektir
32df76d077 Adding a header partial integration #453 2017-11-30 21:48:29 -08:00
Chris Spiegel
dacc274e0d Add myself to the contributors list. 2017-11-30 07:54:43 -08:00
Chris Spiegel
b0b09bad3f Clean up build configuration.
This rolls all "create missing" handling into BuildConfig, and moves the
build-dir option from the "book" table to the "build" table. Some
documentation cleanup surrounding the build table is also updated.
2017-11-30 07:39:58 -08:00
Chris Spiegel
93874edebf Add a create-missing option to book.toml. 2017-11-29 20:02:58 -08:00
shan1024
1aa9c92ac1 Fix typo 2017-11-27 13:18:51 +01:00
Anna Liao
5ce05a79be updated links from azerupi to rust-lang-nursery (#489) 2017-11-22 11:35:18 +01:00
Aaron Turon
c51e080783 Update broken doc link 2017-11-21 20:32:08 -08:00
Michael Bryan
dd5d94393d Fixed the OSX/beta travis builds (#492)
Fixed the OSX/beta travis builds
2017-11-19 01:12:25 +08:00
Jacob Wahlgren
3d5eb48e32 Refactor navigation helpers (#465)
* Refactor navigation helpers

* Target::find: take previous_item by reference

This makes more sense for find as an interface, though it causes a
second clone in some cases. Maybe rustc is smart here?

* Test next and previous navigation helpers

* Add more next/previous tests
2017-11-18 19:17:26 +08:00
Michael Bryan
d56ff94ce6 Regression tests (#422)
* Created regression tests for the table of contents

* Refactoring to make the test more readable

* Fixed some bitrot and removed the (now redundant) tests/helper module

* Removed the include_str!() stuff and use just the dummy book for testing

* Regression tests now pass again!

* Pinned a `*` dependency to use a particular version

* Made sure test mocks return errors instead of panicking

* Addressed the rest of @budziq's review

* Replaced a file open/read with file_to_string
2017-11-16 15:51:12 +08:00
Michael Bryan
fb99276f52 Merge pull request #457 from Michael-F-Bryan/config
Making configuration more flexible
2017-11-12 21:47:10 +08:00
Michael Bryan
5eff572dbb Updated the warning to give some basic migration instructions 2017-11-12 21:37:39 +08:00
Michael Bryan
238dfb7d1d Added in legacy config format support 2017-11-12 21:37:38 +08:00
Michael Bryan
c777913136 Updated the configuration chapter in the book-example 2017-11-12 21:37:38 +08:00
Michael Bryan
c25c5d72c8 Went back and simplified Config to be a smart wrapper around toml::Table 2017-11-12 21:37:38 +08:00
Michael Bryan
3aa6436679 Added in things from @Phaiax's review 2017-11-12 21:37:38 +08:00
Michael Bryan
d37821c194 Rebased after #438 2017-11-12 21:37:38 +08:00
Michael Bryan
1b5137c84e All tests pass again :) 2017-11-12 21:37:37 +08:00
Michael Bryan
18c725ee12 Integration tests pass again 2017-11-12 21:37:37 +08:00
Michael Bryan
1743f2a39f Removed the now redundant config files 2017-11-12 21:37:37 +08:00
Michael Bryan
cee3296a32 main library tests pass 2017-11-12 21:37:37 +08:00
Michael Bryan
ddb0834da8 Upgraded binaries to new configuration API 2017-11-12 21:37:36 +08:00
Michael Bryan
b74c2c18ef Removed all references to old the configuration from the html renderer 2017-11-12 21:37:36 +08:00
Michael Bryan
c056b5cbd0 Removed old configs from MDBook 2017-11-12 21:37:36 +08:00
Michael Bryan
8d7970b32d Changed to the new config types 2017-11-12 21:37:36 +08:00
Michael Bryan
1d22a9a040 Added some basic deserializing tests and helpers 2017-11-12 21:37:36 +08:00
Michael Bryan
6059883229 Added some basic configuration objects 2017-11-12 21:37:35 +08:00
Bartłomiej T. Listwon
8960013322 Fix copy to clipboard is available only for rust snippets
Fixes #432
2017-11-10 21:18:14 +01:00
Michael Bryan
79dd03e8e9 Merge pull request #471 from stgn/theme-popup-absolute
Use absolute positioning for theme popup
2017-11-10 13:31:12 +08:00
François
aecc403fb8 add tooltip to icons (#477)
add tooltip to icons and previous/next chapter links
2017-10-27 14:46:55 +02:00
Shane Nelson
6e4d2485c3 Basic swipe gesture functionality for opening/closing sidebar 2017-10-23 20:51:43 -04:00
Mathieu David
cd711bfb1c Merge pull request #456 from Michael-F-Bryan/conditional-ga
Conditional Google Analytics
2017-10-18 14:10:53 +02:00
Mathieu David
afd9ccb7b1 Merge pull request #461 from Michael-F-Bryan/move-custom-js
Custom JS belongs at the bottom
2017-10-18 14:09:14 +02:00
Mathieu David
cb5ae21b89 Merge pull request #469 from jacwah/ignore
Fix last clippy warnings
2017-10-18 14:07:10 +02:00
Shane Nelson
dd3bef8000 Use absolute positioning for theme popup 2017-10-16 21:40:32 -04:00
Jacob Wahlgren
7e5892bd35 Ignore unhelpful clippy warning
As discussed in https://github.com/azerupi/mdBook/pull/466
2017-10-12 22:14:48 +02:00
Jacob Wahlgren
56cee872e8 Box Handlebars template error
See https://github.com/azerupi/mdBook/pull/466#issuecomment-335450110
2017-10-12 21:50:33 +02:00
Michael Bryan
a554390aa2 Slightly cleaned up the google analytics tag (skip ci) 2017-10-09 09:53:02 +08:00
Mathieu David
c64384abc3 Merge pull request #462 from Michael-F-Bryan/update-contributors
Updated Contributors
2017-10-08 16:07:19 +02:00
Mathieu David
ba7d40284b Merge pull request #466 from jacwah/lints
Fix some clippy warnings
2017-10-08 16:06:39 +02:00
Jacob Wahlgren
8f6523a94c Fix some clippy warnings 2017-10-07 18:11:05 +02:00
Michael Bryan
8fbc59720d Added myself to the contributors list 2017-10-04 20:04:26 +08:00
Michael Bryan
ac9c150902 Moved custom JS to the bottom 2017-10-04 19:59:10 +08:00
Michael Bryan
f2e56c887b Got the logic around the wrong way 2017-10-04 19:57:06 +08:00
Michael Bryan
b4a12fa723 Made sure google analytics isn't included when inspecting locally 2017-10-04 19:57:06 +08:00
Pratik Karki
382fc4139b run rustfmt on the repository #398(Updated) (#438)
rustfmt the repository #398
2017-10-03 13:40:23 +02:00
steveklabnik
b45e5e4420 Release 0.0.26
Fixes #460
2017-10-02 09:10:17 -04:00
Mathieu David
a6d4881e00 Merge pull request #450 from Zengor/master
Call playground with /execute
2017-09-23 21:35:41 +02:00
Mathieu David
a0515bd104 Merge pull request #449 from steveklabnik/fix-regression
Change key for theme to not clobber old books
2017-09-23 20:42:31 +02:00
steveklabnik
9b64db908f prefix sidebar too 2017-09-22 13:58:45 -04:00
steveklabnik
f562878131 I forgot one theme, thanks budziq 2017-09-22 13:56:58 -04:00
Zengor
3823fc0e74 Call playground with /execute and not the legacy /evaluate.json
This commit changes the url used to call the playground, and the
request parameter format to go with it. The older evaluate is
available in the playground as a form of backwards compatibility
and swithcing now opens way for using newer features.
2017-09-21 00:24:47 -03:00
steveklabnik
793fb8f654 Change key for theme to not clobber old books
Fixes https://github.com/azerupi/mdBook/issues/448
2017-09-19 16:59:16 -04:00
Bartłomiej T. Listwon
911683d2cf Fix styling regression on print media in chromium
Forces 0px left padding on print view even if sidebar is visible
2017-09-18 22:10:31 +02:00
Mathieu David
2ae6e6a6e3 Merge pull request #445 from Listwon/master
Fix code snippet font size a little smaller in FF
2017-09-18 14:32:57 +02:00
Bartłomiej T. Listwon
91fd8a2865 Fix code snippet font size a little smaller in FF 2017-09-18 11:18:21 +02:00
Steve Klabnik
a3b6e549e2 Merge pull request #440 from budziq/force_runnable
added `mdbook-runnable` infostring support
2017-09-14 12:48:29 -04:00
Steve Klabnik
d450518292 Merge pull request #439 from azerupi/fix-print
Fix the issue with pages named print not at the root
2017-09-14 11:44:38 -04:00
Michal Budzynski
c056df597a added mdbook-runnable infostring support
makes `ignore`'d playpens runnable
2017-09-13 22:54:01 +02:00
Mathieu David
0d6adc5fc9 Fix the issue with pages named print not at the root 2017-09-13 22:17:23 +02:00
Mathieu David
0226da91e4 Fix shield in README 2017-09-11 19:47:39 +02:00
Mathieu David
ef5895fa78 Update all dependencies 2017-09-11 19:38:10 +02:00
Mathieu David
8e0abfb22f Fix test condition in Travis config 2017-09-10 09:06:46 +02:00
Mathieu David
c9bc13d786 Merge pull request #429 from azerupi/ci-infra
Revive Travis
2017-09-10 00:09:08 +02:00
Mathieu David
7ce78cbfea Fix missing && in travis config 2017-09-08 20:24:29 +02:00
Mathieu David
26544fa531 Fix Travis script 2017-09-08 20:24:29 +02:00
Mathieu David
0c93770f4a Update and simplify Travis CI 2017-09-08 20:24:29 +02:00
Mathieu David
743713ad3a Merge pull request #425 from dvberkel/correct-documentation-of-inline-mathematics
Correct inline mathematics delimiters
2017-09-08 20:23:08 +02:00
Mathieu David
e3f4bb5101 (cargo-release) start next development iteration 0.0.26-alpha.0 2017-09-08 20:21:49 +02:00
Mathieu David
441bcb5963 (cargo-release) version 0.0.25 2017-09-08 20:20:48 +02:00
Mathieu David
84ef4d2617 preserve dashes when generating anchors and trim whitespace 2017-09-08 19:59:04 +02:00
Daan van Berkel
bd30cae17e Correct inline mathematics delimiters
This fixes #424
2017-09-08 09:21:20 +02:00
Mathieu David
6f0b67f44f (cargo-release) start next development iteration 0.0.25-alpha.0 2017-09-07 23:32:57 +02:00
Mathieu David
abf86eefd9 (cargo-release) version 0.0.24 2017-09-07 23:31:57 +02:00
Mathieu David
016ec8836c Merge pull request #415 from azerupi/fix-print-title
Fix the print title that was using the title from the last rendered chapter
2017-09-07 23:29:54 +02:00
Mathieu David
881a1b39ff Remove the logic in handlebars and expose the 3 different titles in the handlebars variables 2017-09-07 23:19:22 +02:00
Mathieu David
a1e58229b2 Merge pull request #418 from behnam/manifest
[Cargo.toml] Fix package.exclude warnings
2017-09-07 22:46:49 +02:00
Mathieu David
276eab095c Merge pull request #427 from budziq/spurious_reloads
Do not trigger spurious watch events on Write and Remove
2017-09-07 22:45:12 +02:00
Mathieu David
f4513d3b5c Merge pull request #419 from behnam/nested
Fix heading links in nested pages
2017-09-07 22:39:51 +02:00
Michal Budzynski
570ce6681f Do not trigger spurious watch events on Write and Remove 2017-09-06 22:33:56 +02:00
Behnam Esfahbod
ddee839d9c [renderer] Err on bad file names, instead of panic
Addressing the review comments.
2017-09-06 02:25:10 -07:00
Behnam Esfahbod
99945542ca [renderer] Add normalize_path()
On the web, the normalized path separator is forward-slash (`/`), so we
use the built-in `is_separator()` method to replace any path separator
with the forward-slash, to ensure consistent output on unix and windows
machines.
2017-09-06 00:52:17 -07:00
Behnam Esfahbod
956a5cc7fd Fix heading links in nested pages
Plus fixing the whitespace chars not being replaced by hyphen.

Also expand tests for link creations, and add test for nested pages.

Fixes <https://github.com/azerupi/mdBook/issues/416>
Fixes <https://github.com/azerupi/mdBook/issues/417>
2017-09-06 00:52:17 -07:00
Behnam Esfahbod
cef62ec42e Fix build and test warnings
Move non-test test module files into their own directories to prevent
cargo from running them as tests. Then suppress the left-over warnings.

Move *dummy book* code and data into a shared folder, and leave the rest
of helper utilities (one function) in the original module.
2017-09-06 00:52:17 -07:00
Behnam Esfahbod
b1362bfa06 [watch] Fix build warnings 2017-09-06 00:52:15 -07:00
Behnam Esfahbod
a529ca5e65 [Cargo.toml] Fix package.exclude warnings
IIUC, the existing exclude rule has meant to do what it will do in the
future (gitignore-like matching, not glob-only matching). This fix makes
the rule to do what it was expected to do, and is forward-compatible,
therefore fixing the warning messages.
2017-09-06 00:52:15 -07:00
Michal Budzynski
6bc3039b4f Both static and ACE editable snippets have optional play button
- list of available crates is dynamically loaded from play.rust-lang.org
- play button is enabled only if crates used in snippet are available on playground
- ACE editor's play button is dynamically updated on each text change
- `no_run` is honored by always disabling the play button
- minor cleanups
2017-09-06 00:18:24 +02:00
Michal Budzynski
cd90fdd407 first prototype of play-button enabling only if crate list supported
also minor refactor of clipboard handling
TODO:
- `no_run` support
- test with ACE
- disable play button with tooltip instead of hiding
2017-09-06 00:18:24 +02:00
Mathieu David
a6a7c95c78 Merge pull request #343 from budziq/appveyor_css
fixed `cargo build --features=regenerate-css` on win 10 / nightly
2017-09-05 19:33:57 +02:00
Mathieu David
0a4a2b66da Fix the print title that was using the title from the last rendered chapter. Fixes #414 2017-09-01 08:22:24 +02:00
Mathieu David
2f3c14d609 ignore vscode dir in git 2017-09-01 08:22:01 +02:00
Mathieu David
ebcf1e495d Merge pull request #413 from behnam/gitignore
[book] Prevent over-matching in gitignore rule
2017-08-31 19:27:38 +02:00
Behnam Esfahbod
40a4840867 [book] Prevent over-matching in gitignore rule
To only ignore the output destination (default: `book`) and no other
file/directory with the same name under the mdbook root, we should
prefix the gitignore rule with a leading slash (default: `/book`).
2017-08-30 16:01:45 -07:00
steveklabnik
313f9b9403 Bump version in Cargo.toml for next release 2017-08-29 12:53:32 -04:00
Steve Klabnik
d94c097495 Merge pull request #411 from steveklabnik/master
Fix toml problem and release 0.0.23
2017-08-29 12:51:11 -04:00
steveklabnik
b7372d3bf2 Fix toml problem and release 0.0.23
The toml crate removed its serde dependency in 0.3, but in 0.4, it
went away. Cargo didn't warn on this, but now it does. As such, we
need a release so that rust's build doesn't warn constantly.
2017-08-29 10:53:20 -04:00
Michal Budzynski
d0a6aea3aa fixed cargo build --features=regenerate-css on windows 10
also added cargo build --features=regenerate-css to appveyor.yml
2017-08-12 13:20:26 +02:00
Mathieu David
a1926bbe8e Update documentation for mathjax 2017-08-11 13:55:11 +02:00
Mathieu David
094c1e7a52 Add documentation about additional-js 2017-08-11 13:55:11 +02:00
Mathieu David
4528e24080 Improve wording of documentation 2017-08-11 13:55:11 +02:00
Michal Budzynski
31983cae6c fixed missing playpen css class when codeblock properties had whitespace 2017-08-11 12:39:27 +02:00
Michal Budzynski
ddf31dcc08 Fixed mdbook test for {{#playpen file.rs}}
- now `mdbook test` does full link expansion to temp file prior to running
- also minor reformat and cleanup of `HtmlHandlebars::render_item`
2017-08-07 21:42:28 +02:00
Michal Budzynski
c36eca15c2 renamed Playpen to Playground in ajax error handling 2017-08-06 17:10:52 +02:00
Mathieu David
798225bcdc Merge pull request #393 from budziq/playpen_errors
handle play.rust-lang.org communication errors in playpens
2017-08-06 15:16:11 +02:00
Michal Budzynski
eed1a0a591 handle play.rust-lang.org communication errors in playpens
also add 15s communication timeout
2017-08-06 14:59:19 +02:00
Mathieu David
35a447d08a Merge pull request #338 from projektir/ace_editor
Ace editor
2017-08-05 12:24:12 +02:00
projektir
16aa545c5b Integrating Ace #247 2017-08-03 22:45:33 -04:00
projektir
6601dbdd61 Adding ace.js, Rust highlighter, and themes #247 2017-08-03 20:00:39 -04:00
Mathieu David
373e36ebfb Merge pull request #380 from ffissore/master
Fixed wrong filename when post processing html
2017-08-03 16:27:18 +02:00
Mathieu David
ef435825b0 Merge pull request #377 from Michael-F-Bryan/dry-themes
Make themes module more DRY
2017-08-03 14:06:45 +02:00
Michael Bryan
2f8d5ce263 Removed a lot of the repetition in Theme::new() 2017-08-03 07:01:52 +08:00
Michael Bryan
ce2d7153f7 removed some repetition from the themes module 2017-08-02 23:31:37 +08:00
Mathieu David
6628757d8e Merge pull request #374 from Michael-F-Bryan/moar-tests
High level integration tests
2017-08-02 17:01:40 +02:00
Michael Bryan
e2eb40bded Got some feedback from azerupi and added a DummyBook builder 2017-08-02 22:29:28 +08:00
Mathieu David
4f754a73ba Remove the empty introduction chapter 2017-08-02 15:04:03 +02:00
Mathieu David
ba719c00be Possible fix for automatic deployment to gh-pages (GH_TOKEN has been updated on Travis) 2017-08-02 12:58:59 +02:00
Mathieu David
64f6f78663 Merge pull request #385 from azerupi/readme-pin-ci
Add a note about version pinning in the README
2017-08-01 14:32:43 +02:00
Mathieu David
3b0d2d1238 Add a note about version pinning for people doing automatic deployments of their books 2017-08-01 14:16:39 +02:00
Mathieu David
6ab3d3da2a ignore MacOS .DS_Store temporary files 2017-08-01 13:55:51 +02:00
Michal Budzynski
ee29b9d5f6 added clone derives and made the separating space mandatory in links with paths 2017-08-01 13:50:12 +02:00
Michal Budzynski
d7ecb1a80c Rewrite of {{#}} links handling in preprocess module
- Replaced link parser with a Regex
- Implemented {{#include}} links
- Will display relatively nice error when cannot open {{#}} linked file
- Escaped links no longer render with escape char
- utils::fs::file_to_path no takes AsRef<Path>
- sorted export/mod in lib.rs
2017-08-01 13:50:12 +02:00
Michal Budzynski
f3f6b40ea9 Moved playpen.rs renderer helper to preprocess/links.rs module 2017-08-01 13:50:12 +02:00
Michał Budzyński
c482650e56 Merge pull request #384 from budziq/travis-rustup-beta
fix travis ci for beta channel
2017-08-01 01:39:29 +02:00
Michał Budzyński
5da75bc798 fix travis ci for beta channel
travis started to fail for beta channel.
2017-08-01 01:04:05 +02:00
Federico Fissore
07b80723b6 Fixed wrong filename when post processing html 2017-07-24 11:37:31 +02:00
Michael Bryan
0c3a2b80f8 Tested MDBook::init with custom args 2017-07-10 18:23:51 +08:00
Michael Bryan
29e00c0d97 Broke the integration tests out into individual sections 2017-07-10 18:17:19 +08:00
Michael Bryan
7e8819f4d2 Bye bye println() debugging 2017-07-09 22:08:57 +08:00
Michael Bryan
c90c0f7848 Updated the book testing to take into account #340 2017-07-09 20:02:31 +08:00
Michael Bryan
cd11035a69 trivial change to make travis run again 2017-07-09 19:59:29 +08:00
Michael Bryan
8b7c95e02f Made sure the rendered content actually contains the original text 2017-07-09 19:59:29 +08:00
Michael Bryan
e3f047a35d Added playpen and mdbook init tests 2017-07-09 19:59:29 +08:00
Michael Bryan
9fab267da1 Added some end-user "sanity" tests 2017-07-09 19:59:29 +08:00
Mathieu David
55e7e82e5c Merge pull request #340 from messense/feature/mdbook-test-library-path
Add library path argument for `mdbook test`
2017-07-08 23:27:28 +02:00
Mathieu David
325458c957 Merge pull request #369 from budziq/info_logger
Increased default logging level to info unless RUST_LOG is set
2017-07-08 19:55:59 +02:00
Michał Budzyński
9c21fe32c1 Merge pull request #373 from Michael-F-Bryan/appveyor
Updated appveyor.yml to use rustup for installing Rust
2017-07-08 11:25:28 +02:00
Michael Bryan
eaec9eff37 Updated appveyor.yml to use rustup for installing Rust 2017-07-08 12:47:27 +08:00
Michal Budzynski
287f539b7d Increased default logging level to info unless RUST_LOG is set 2017-06-28 23:37:03 +02:00
Mathieu David
a220528c15 Merge pull request #367 from messense/feature/fix-mdbook-test-error
Print stdout when `mdbook test` failed
2017-06-28 08:41:13 +02:00
messense
7c023e2d1d Add library path argument for mdbook test 2017-06-28 10:33:52 +08:00
messense
f2544e0707 Print stdout when mdbook test failed 2017-06-28 10:28:50 +08:00
Mathieu David
4974d2cfa1 Merge pull request #362 from budziq/nonopt_htmlconfig
Make HtmlConfig is no longer optional
2017-06-27 14:33:56 +02:00
Michal Budzynski
b1ca9cf5b5 HtmlConfig is no longer optional
`HtmlConfig` was both guaranteed to exist within `BookConfig`
and `expect`ed in few places.
This simplifies the API a little by representing the fact that
`HtmlConfig` is currently mandatory for proper mdBook binary operation.
2017-06-27 14:01:33 +02:00
Mathieu David
5a27207844 Merge pull request #366 from budziq/split_commands
Split commands to separate files and register conditional ones if required features enabled
2017-06-27 13:37:57 +02:00
Michal Budzynski
5e088d92c9 Merge remote-tracking branch 'upstream/master' into split_commands 2017-06-27 13:06:19 +02:00
Mathieu David
ea0c8ddea6 Merge pull request #364 from budziq/clippy_nits
Correct clippy complaints
2017-06-27 12:17:10 +02:00
Michal Budzynski
b3c9ba4555 Correct clippy nits 2017-06-27 09:08:58 +02:00
Michal Budzynski
7f51039f9a Rename and move the clap sub-command generation functions 2017-06-27 07:59:50 +02:00
Michal Budzynski
7799ce285e Do not use wildcard imports if not needed 2017-06-26 23:17:46 +02:00
Michal Budzynski
fe62d0c407 Merge remote-tracking branch 'upstream/master' into split_commands 2017-06-26 23:11:00 +02:00
Mathieu David
c9a117cc4e Merge pull request #361 from Michael-F-Bryan/error-chain
Add error-chain throughout the codebase
2017-06-26 17:07:51 +02:00
Mathieu David
13ab20ea49 Merge pull request #363 from budziq/opt_mathjax
Make MathJax support optional
2017-06-26 17:01:52 +02:00
Michal Budzynski
f3c8535870 Extracted mdbook test and mdbook init to separate files/modules 2017-06-26 01:24:33 +02:00
Michal Budzynski
35ed9fc286 corrected indentation in serve and watch subcommands definitions 2017-06-26 01:22:38 +02:00
Michal Budzynski
efdd0330c1 Extracted mdbook init to separate file/module 2017-06-26 01:02:32 +02:00
Michal Budzynski
4c78fdf431 Extracted mdbook build to separate file/module 2017-06-26 01:00:18 +02:00
Michal Budzynski
b09fdf07e4 Register serve and watch subcommands only if given features enabled 2017-06-26 00:43:28 +02:00
Michal Budzynski
5c524da3c2 Extracted mdbook watch to separate file/module 2017-06-25 23:44:28 +02:00
Michal Budzynski
99224f40d5 Extracted mdbook serve to separate file/module 2017-06-25 23:05:58 +02:00
Michael Bryan
83354ab24b Fixed up some unused-imports warnings 2017-06-25 14:21:23 +08:00
Michael Bryan
af05306046 Tried making sure travis installs all the musl tools when required 2017-06-25 14:11:43 +08:00
Michael Bryan
b796ee7c36 Made sure travis installs musl for the musl builds 2017-06-25 13:17:44 +08:00
Michal Budzynski
db94b3d839 Add minimal testing for the optional MathJax support 2017-06-25 00:39:57 +02:00
Michal Budzynski
f214c7108f Make MathJax support optional
to enable add following to book.toml
```toml
[output.html]
mathjax-support = true
```
2017-06-25 00:32:33 +02:00
Michael Bryan
2abebfb244 Removed the default error-chain features
On `x86_64-unknown-linux-musl` it looks like travis can't compile
the `backtrace-sys` crate because the `./configure` step fails.

The error message `./configure` gives is:

configure: error: in `/home/travis/build/azerupi/mdBook/target/x86_64-unknown-linux-musl/debug/build/backtrace-sys-204dc57c91e9a514/out':
configure: error: C compiler cannot create executables
2017-06-25 00:40:56 +08:00
Michael Bryan
fd821a5ead the binary now uses error-chain 2017-06-25 00:13:41 +08:00
Michael Bryan
487f5ce339 Added error-chain to the renderer module 2017-06-25 00:10:06 +08:00
Michael Bryan
1356e0f068 Added error-chain to the book and utils modules 2017-06-25 00:04:57 +08:00
Michael Bryan
0f93cd002b Added error-chain to the config files 2017-06-24 23:53:08 +08:00
Michael Bryan
6761442241 Added error-chain to lib.rs 2017-06-24 23:48:50 +08:00
Mathieu David
b441066105 Merge pull request #335 from Michael-F-Bryan/refactor-hbs-renderer
Refactor hbs renderer
2017-06-24 14:44:12 +02:00
Mathieu David
d50486e337 Merge pull request #314 from budziq/fix_theme
Fixes missing the default "theme" dir location
2017-06-24 14:03:10 +02:00
Michael Bryan
c3dfabd5a2 Merge branch 'upstream/master' into refactor-hbs-renderer
Notably, this takes into account the curly-quotes pull request (#305)
2017-06-24 16:07:01 +08:00
Michael Bryan
4c187bcb9f Explained what HtmlHandlebars::write_custom_function() does 2017-06-24 15:50:51 +08:00
Michal Budzynski
d42ef1cdbc reduced code repetition in fill_from_tomlconfig 2017-06-23 17:01:11 +02:00
Mathieu David
03193e0bd7 Merge pull request #334 from budziq/hide_popup
Hide theme selection popup after interaction
2017-06-23 14:15:54 +02:00
Michal Budzynski
672d91e6c2 Hide theme selector popup on interaction outside of it
Also set cursor to pointer on theme selector items.
2017-06-23 13:31:28 +02:00
Michal Budzynski
6d8ac6a23c Fixes missing the default "theme" dir location
if not specified in book.toml
2017-06-23 13:29:46 +02:00
Mathieu David
69b3e2b5cb Merge pull request #332 from budziq/silence_404s
error spewing on iron 404 errors
2017-06-23 11:27:31 +02:00
Mathieu David
5e93decf6e Merge pull request #328 from sunng87/feature/handlebars-upgrade
Update handlebars and some helpers
2017-06-23 11:16:52 +02:00
Michal Budzynski
79cdcb46de extract serving code to a separate module 2017-06-23 08:59:42 +02:00
Michal Budzynski
f889eb3d12 first draft of silencing 404 errors 2017-06-23 08:54:14 +02:00
Mathieu David
3306c030e1 Merge branch 'master' of github.com:azerupi/mdBook 2017-06-23 01:10:38 +02:00
Mathieu David
239886a5cf Merge branch 'budziq-minor_refactor' 2017-06-23 01:10:29 +02:00
Mathieu David
f3cb4265ca Fix typo 2017-06-23 01:10:18 +02:00
Mathieu David
28afebdca2 Merge branch 'minor_refactor' of https://github.com/budziq/mdBook into budziq-minor_refactor 2017-06-23 01:09:26 +02:00
Mathieu David
ab31f4b027 Merge pull request #310 from jimmydo/ios-scroll-to-top
On iOS, allow scrolling to the top of the page by tapping the top of the screen
2017-06-23 01:01:19 +02:00
Mathieu David
4128a78171 Merge branch 'master' of github.com:azerupi/mdBook 2017-06-23 00:50:11 +02:00
Mathieu David
7f60db069f Merge branch 'jimmydo-curly-quotes' 2017-06-23 00:49:46 +02:00
Mathieu David
26fc980ffb Remove 'curly_quotes' key from the json config 2017-06-23 00:48:59 +02:00
Mathieu David
d252dc82d6 Merge branch 'curly-quotes' of https://github.com/jimmydo/mdBook into jimmydo-curly-quotes 2017-06-23 00:43:57 +02:00
Mathieu David
c186d72b40 Merge pull request #346 from projektir/playpen_no_html
Creating markdown code from playpen files instead of HTML #345
2017-06-21 16:46:05 +02:00
projektir
73160877b3 Creating markdown code from playpen files instead of HTML #345 2017-06-21 09:33:41 -04:00
Michael Bryan
33f3bec301 Cleaned up the filter_map for normalizing id's using a more readable procedural style 2017-06-20 11:23:53 +08:00
Michael Bryan
8c30de16d6 Used the Entry API to make id counter incrementing nicer 2017-06-20 11:15:12 +08:00
Michael Bryan
fa95546988 Broke the header link wrapping out into smaller functions 2017-06-20 11:06:30 +08:00
Michael Bryan
ac16d7aef1 Added some tests for the original build_header_links function 2017-06-20 10:54:32 +08:00
Michael Bryan
e2a7adaa79 Introduced a RenderItemContext to make item rendering easier
I also accidentally ran `rustfmt` instead of `rustfmt-nightly`, so there are a lot of unnecessary style changes :(
2017-06-20 08:54:39 +08:00
Michael Bryan
75f0196c55 Pulled index rendering out into its own method 2017-06-20 07:53:46 +08:00
Mathieu David
49336e0698 Merge branch 'master' of github.com:azerupi/mdBook 2017-06-18 19:21:08 +02:00
Mathieu David
f0c697afd5 Merge branch 'jmillikan-master' 2017-06-18 19:20:23 +02:00
Mathieu David
cff1ed5e08 remove #content 2017-06-18 19:19:48 +02:00
Mathieu David
73c845fbbe Merge branch 'master' of git://github.com/jmillikan/mdBook into jmillikan-master 2017-06-18 19:14:32 +02:00
Jimmy Do
193f014a5b Add an option to convert to curly quotes when rendering to HTML 2017-06-18 10:11:04 -07:00
Jimmy Do
bd9b0d29ea On iOS, allow scrolling to the top of the page by tapping the top of the screen
* This is a built-in function of iOS Safari that didn't work because the
  page content was inside absolutely-positioned, scrollable divs.

* The fix is to stop using absolute positioning on `.page-wrapper` and
  `.page`, so that the content uses static positioning and flows
  naturally down the page.

* Consequently, `.sidebar` and `.nav-chapter` now have to use `position:
  fixed` in order to be positioned relative to the viewport.

* This fix also enables Safari's built-in behavior of automatically
  hiding the top and bottom toolbars when scrolling down the page.
2017-06-18 09:58:52 -07:00
Michael Bryan
4af10ce60c Renamed a couple functions to be more descriptive and ran rustfmt 2017-06-17 21:15:54 +08:00
Mathieu David
29708db467 Merge pull request #337 from budziq/focus_fix
Select right pane content on page load
2017-06-16 13:40:36 +02:00
Michael Bryan
deab3ba751 Tiny whitespace changes 2017-06-16 06:50:13 +08:00
Michal Budzynski
c1c06d6dc1 Auto focus on content to allow keyboard navigation 2017-06-15 23:15:41 +02:00
Michael Bryan
b7aa78c3c0 Minor refactoring 2017-06-15 18:39:41 +08:00
Michael Bryan
2568986fd5 fixed a typo 2017-06-15 18:17:16 +08:00
Michael Bryan
f946ef6327 Pulled some more little bits out into their own helper functions 2017-06-15 18:03:10 +08:00
Michael Bryan
0d0deb7c40 Pulled page rendering out into its own method 2017-06-15 17:43:44 +08:00
Michal Budzynski
e8908e32c9 Minor cleanup
- removing need to explicitly use `Path::new` all over the place
- removed warnings from doctests (normally invisible unless `cargo test -- --nocapture`)
- no doctests are norun/ignore now
- updated docs both in book-example and in docs not to refer to nonexisting API's
2017-06-14 21:55:42 +02:00
Mathieu David
9e9a08806d Merge pull request #329 from budziq/ios_playpen_buttons
Fix for playpen buttons missing on mobile safari and chrome IOS
2017-06-13 18:43:34 +02:00
Michal Budzynski
ee9fa8c86f Fix for playpen buttons missing on mobile safari and chrome IOS 2017-06-13 16:59:29 +02:00
Ning Sun
e890579141 (fix) some merge issue 2017-06-13 20:53:25 +08:00
Ning Sun
9aa39a6a12 (chore) update handlebars to 0.27.0
Signed-off-by: Ning Sun <sunng@about.me>
2017-06-13 20:43:36 +08:00
Ning Sun
6ee6da074e (refactor) rework helpers based on new handlebars api
Signed-off-by: Ning Sun <sunng@about.me>
2017-06-13 20:43:17 +08:00
Ning Sun
2bb274d424 Merge branch 'master' of github.com:azerupi/mdBook 2017-06-13 20:40:46 +08:00
Mathieu David
19692c76df Merge pull request #326 from budziq/fix_clipboard
copying to clipboard no longer copies the compilation results from "play"
2017-06-12 14:15:41 +02:00
Michal Budzynski
a6275ebcdb copying to clipboard no longer copies the compilation results from "play" 2017-06-12 14:02:53 +02:00
Mathieu David
6a279e2775 Merge branch 'Cldfire-master' 2017-06-12 11:26:19 +02:00
Mathieu David
9ce6eebe43 Merge branch 'master' of git://github.com/Cldfire/mdBook into Cldfire-master 2017-06-12 11:19:31 +02:00
Mathieu David
0b6378eb13 Merge branch 'budziq-custom_js' 2017-06-12 11:10:46 +02:00
Mathieu David
350c86155b Merge branch 'custom_js' of git://github.com/budziq/mdBook into budziq-custom_js 2017-06-12 11:09:07 +02:00
Mathieu David
ad9bda2d69 Merge pull request #324 from budziq/store_js
Move from localStorage to store.js (v2.0.3) - also hide sidebar on mobile
2017-06-12 11:03:03 +02:00
Michal Budzynski
08fd255a56 Move from localStorage to store.js (v2.0.3)
Fixes a lot of browser incompatibilities in localStorage/cookie handling
Including but not limited to:

- loss of styling and functionality on chromium private mode
- loss of styling and functionality on safari and safari private mode
- awaiting verification if problems in mobile safari are solved.
2017-06-12 01:53:25 +02:00
Michal Budzynski
f607978780 Hide sidebar on link selection when it occupies large space
in relation to the whole screen width (solves problems on phones)
2017-06-11 15:13:31 +02:00
Michal Budzynski
f96e7e5cba Implemented support for additional JS 2017-06-11 15:08:09 +02:00
Mathieu David
6c279453d9 Merge pull request #321 from pravic/es5-fix
One more ES5 fix.
2017-06-09 22:10:03 +02:00
pravic
56163f69f8 One more ES5 fix. 2017-06-09 22:48:57 +03:00
Mathieu David
a9862a56b3 Merge pull request #320 from pravic/es5-fix
Fix ES5 compatibility.
2017-06-09 21:41:23 +02:00
pravic
eba90f5440 Fix ES5 compatibility. 2017-06-09 21:59:29 +03:00
Cldfire
44efc65c63 Add Ayu theme
Also adds the a new variable, `$inline-code-color`, to base.styl. The `Ayu` theme needed this to change the text color of inline code.
2017-06-06 16:35:44 -04:00
Steve Klabnik
8a05f0d499 Merge pull request #287 from azerupi/toml-config
Revamp config code
2017-06-05 10:56:44 -04:00
Mathieu David
f1121cf8c2 fix build failure 2017-06-04 20:47:34 +02:00
Mathieu David
1a8e54bb52 remove unused methods 2017-06-04 20:41:31 +02:00
Mathieu David
23efa9e146 Document the TOML configuration file 2017-06-04 20:41:31 +02:00
Mathieu David
bb4ceb481f Allow an additional custom stylesheets, closes #178 2017-06-04 20:41:31 +02:00
Mathieu David
c6bfe0b1d7 Adds a test for #240 2017-06-04 20:41:31 +02:00
Mathieu David
2e812db13c Fix for google-analytics 2017-06-04 20:41:31 +02:00
Mathieu David
70383d0a25 New config structs supports json again (the old style) for a little deprecation period 2017-06-04 20:41:31 +02:00
Mathieu David
d3ae2eda56 Replace the old book structure with the new one 2017-06-04 20:41:31 +02:00
Mathieu David
170bf8b1eb New configuration struct + tests #285 2017-06-04 20:41:31 +02:00
Mathieu David
272022621d Merge pull request #307 from budziq/theme_reload
Now changes to `theme` directory trigger rebuild for `mdbook serve`
2017-06-01 13:56:26 +02:00
Michal Budzynski
be3418a269 Now changes to theme directory trigger rebuild for mdbook serve
As `theme` dir is no longer under `src`. Updates to "theme" did not
trigger book rebuild.
Also fixed misleading docs about `theme` dir being located in `src`
2017-06-01 13:11:39 +02:00
Mathieu David
3e80268a44 Merge pull request #303 from budziq/clipboard
RFC - Initial implementation of clipboard handling
2017-05-31 22:22:15 +02:00
Michal Budzynski
3a809e4a1c Added local fallback for clipboard.js 2017-05-31 21:51:19 +02:00
Michal Budzynski
dfc24bec01 Fixed tooltip styling
Also fixed problem with garbage being put in clipboard
when triggered repeatedly
2017-05-31 21:07:47 +02:00
Michal Budzynski
e567d22f1c Initial implementation of clipboard handling 2017-05-31 19:56:17 +02:00
Mathieu David
bfc3fbb405 Merge pull request #304 from budziq/hljs_update
Updated highlight.js to v9.12.0
2017-05-31 15:50:06 +02:00
Michal Budzynski
8bfcd9939c Updated highlight.js to v9.12.0
Fixing problem with raw strings syntax highlighting
Also backported updates to atelier-dune-light.css
2017-05-31 15:12:20 +02:00
Mathieu David
316bcf7b5d Merge pull request #300 from budziq/serving_url
Reformatted "Serving on " message for easier consumption
2017-05-27 11:54:12 +02:00
Michal Budzynski
453b97bec0 Reformatted "Serving on " message for easier consumption
Now we have: `Serving on: http://localhost:3000`
2017-05-27 11:34:46 +02:00
Mathieu David
4364ec3a7b Merge pull request #298 from superstring/master
Fix websocket port option for serve
2017-05-26 13:54:07 +02:00
superstring
7de24f86a9 Change --ws-port to --websocket-port 2017-05-26 19:18:32 +08:00
superstring
027c21aef7 Fix websocket port option for serve 2017-05-26 12:04:20 +08:00
Mathieu David
64f0bdbfba Merge pull request #297 from aaaxx/master
CSS: better fallback stack for monospaced fonts
2017-05-24 10:28:25 +02:00
aaaxx
cc1cb9edb0 CSS: better fallback stack for monospaced fonts
List of system fonts (R, I, B means roman, italic and bold. Ubuntu probably comes with more fonts, but I couldn't find a list to confirm.):

```txt
Windows
----------
Consolas            R RI  B BI
Courier             R
Courier New         R RI  B BI
Lucida Console      R

Mac
----------
Andale Mono         R
Courier             R RI  B BI
Courier New         R RI  B BI
Menlo               R RI  B BI
Monaco              R

Ubuntu
----------
Ubuntu Mono         R RI  B BI
DejaVu Sans Mono    R RI  B BI
```

```css
font-family: Consolas, "Ubuntu Mono", Menlo, "DejaVu Sans Mono", monospace, monospace;
```

Consolas and Ubuntu are professionally designed fonts ([Lucas de Groot][1] and [Dalton Maag][2]), with true, calligraphic italic, so they go at the top of the stack.

Menlo is [based on DejaVu Sans Mono][3], the only difference being a few tweaked glyphs, so DejaVu serves as a fallback for it.

As for Courier New, other than being unreadably spindly, it's the default monospaced font in all browsers, so there's no need to include it in the stack.

The `monospace, monospace;` declaration is, by now, [a standard hack][4] that overrides some browsers' behaviour of defaulting the `monospace` elements to smaller font size. Without it, any relative font size you apply to them will be calculated from that reduced size (seems to be 13 px in all browsers).


[1]: https://en.wikipedia.org/wiki/Luc(as)_de_Groot
[2]: https://en.wikipedia.org/wiki/Dalton_Maag
[3]: http://www.leancrew.com/all-this/2009/10/the-compleat-menlovera-sans-comparison/
[4]: https://stackoverflow.com/questions/38781089/font-family-monospace-monospace
2017-05-24 06:07:58 +02:00
Mathieu David
35ef31757b Merge pull request #295 from budziq/err_ch
Friendlier errors from build.rs and support for Windows stylus build
2017-05-22 18:20:57 +02:00
Michal Budzynski
87f26a82b6 Fix for different naming of nodejs on ubuntu
also added static lifetime to str constants as these were failing on nightly windows
2017-05-22 17:06:38 +02:00
Michal Budzynski
1d141aa27b Workaround for not being able to run stylus on windows 2017-05-22 16:35:39 +02:00
Michal Budzynski
a84c1ecf33 Implemented a more friendly stylus error handling
Added error-chain as build-dependency
2017-05-22 04:25:59 +02:00
Mathieu David
2518d5c827 Fix error in contribution guide 2017-05-20 19:43:32 +02:00
Mathieu David
3f98d69690 Merge pull request #289 from budziq/highlight
Inline code with hyperlink is now highlighted
2017-05-20 17:27:56 +02:00
Michal Budzynski
9c8c819ec3 Inline code with hyperlink is now highlighted
Inline code with hyperlink has now a different color then
standard inline code and has a on hover underline.
2017-05-20 17:10:53 +02:00
Mathieu David
f038dcb404 Merge pull request #288 from budziq/rustfmt_update
Made changes with rustfmt including `use_try_shorthand`
2017-05-19 13:43:49 +02:00
Michal Budzynski
75bbd55128 Changes made with rustfmt including use_try_shorthand
Updated the project rustfmt.toml to include `use_try_shorthand = true`.
Run rustfmt on all rust sources.
2017-05-19 13:04:37 +02:00
Mathieu David
faa716d99c update all dependencies 2017-05-18 11:56:04 +02:00
Mathieu David
b1601b16ea Merge pull request #278 from azerupi/contributing
Contributing file
2017-05-18 09:55:26 +02:00
Mathieu David
379ed9dc16 Merge pull request #284 from budziq/indentation
Fix indentation of hidden code blocks
2017-05-18 09:36:53 +02:00
Mathieu David
7b6836b75e Merge pull request #283 from budziq/quick_main
Do not add playpen boilerplate when using quick_main!
2017-05-18 09:29:57 +02:00
Michal Budzynski
e4dd03c8f0 Fix indentation of hidden code blocks
Hidden code blocks are no longer indented with
one additional space (required for doctests to compile in some cases)
Now the behavior is similar to the rustdoc's
2017-05-18 00:04:09 +02:00
Michał Budzyński
c99ce06370 Do not add playpen boilerplate quick_main! is used
code snippets using quick_main! macro from error-chain
https://docs.rs/error-chain/0.10.0/error_chain/macro.quick_main.html
no longer have `fn main` implicitly added
2017-05-17 22:27:03 +02:00
Mathieu David
0f67cae1ef Wrap lines and add more whitespace in CONTRIBUTING.md 2017-05-17 18:36:52 +02:00
Mathieu David
0443f8a709 Merge pull request #262 from Rufflewind/master
Fix broken link in book-example/src/lib/lib.md
2017-05-17 11:37:07 +02:00
Mathieu David
1442923a0a Add simple issue examples 2017-05-16 22:16:59 +02:00
Mathieu David
9447274fa5 Modify the Readme for the new contribution guide 2017-05-16 22:10:24 +02:00
Mathieu David
7a59591109 Added a contributing file 2017-05-16 22:02:07 +02:00
Mathieu David
d636ca45e8 Merge pull request #276 from steveklabnik/gh158
Remove allow-failure on MUSL
2017-05-16 20:40:37 +02:00
steveklabnik
832ef446dd Remove allow-failure on MUSL
This should work now.

Fixes #158
2017-05-16 13:06:08 -04:00
Mathieu David
74e75d2cfb Merge pull request #273 from Michael-F-Bryan/google-analytics-docs
Added a note about google analytics to the docs
2017-05-16 14:19:14 +02:00
Michael-F-Bryan
95750be815 Added a note about google analytics to the docs 2017-05-16 17:40:14 +08:00
Mathieu David
4ad6fab5e3 Merge pull request #272 from Michael-F-Bryan/google-analytics
Support for Google Analytics
2017-05-16 09:13:57 +02:00
Michael-F-Bryan
94dce4f796 Added google_analytics so it can be inserted into handlebars 2017-05-16 13:28:59 +08:00
Michael-F-Bryan
ada1f29b34 Added a google_analytics field to BookConfig
This commit:
- Adds an Option<String> field to the BookConfig which should
  contain your google analytics ID
- Allows the google analytics ID to be extracted from the config
  file (key is google_analytics_id)
- Adds a test to make sure the field is populated from a config
  file correctly
2017-05-16 13:15:04 +08:00
Michael-F-Bryan
4a634f08da Updated google analytics to index.hbs and hbs_renderer.rs 2017-05-16 13:05:21 +08:00
Mathieu David
e8b88cfa5e Merge pull request #267 from Rufflewind/mathjax
Change MathJax to use CDNJS
2017-05-06 17:41:42 +02:00
Phil Ruffwind
3066597acc Change MathJax to use CDNJS
Because the MathJax CDN will soon be retired.
2017-05-05 17:08:59 -04:00
Ning Sun
d1f9174e7f (feat) adopt new handlebars navigate api
Signed-off-by: Ning Sun <sunng@about.me>
2017-05-05 08:41:50 +08:00
Phil Ruffwind
7eade3b101 Fix broken link in book-example/src/lib/lib.md
The template sets `<base href="../">` so it's not necessary to have
`../` in the link.
2017-05-01 20:32:06 -04:00
Mathieu David
435682e95c (cargo-release) start next development iteration 0.0.22-pre 2017-04-27 16:05:45 +02:00
Mathieu David
69188445e7 (cargo-release) version 0.0.21 2017-04-27 16:03:02 +02:00
Mathieu David
9b7a26effd Merge pull request #259 from azerupi/incorrect-conditional
Fix incorrect conditional.
2017-04-27 16:00:29 +02:00
Corey Farwell
4f4120b5a4 Fix incorrect conditional.
I accidentally introduced this in 4525810737.
2017-04-27 09:16:19 -04:00
Mathieu David
607bf4426e (cargo-release) start next development iteration 0.0.21-pre 2017-04-26 19:25:14 +02:00
Mathieu David
8b84b8fa82 (cargo-release) version 0.0.20 2017-04-26 19:22:37 +02:00
Corey Farwell
a4a708bdda Merge pull request #254 from frewsxcv/frewsxcv-no-create
Implement new 'no-create' build flag.
2017-04-21 23:03:23 -04:00
Steve Klabnik
a3b925e3ab Merge pull request #256 from steveklabnik/master
bump for 0.0.19
2017-04-18 10:52:33 -04:00
steveklabnik
cba988f009 bump for 0.0.19 2017-04-18 10:50:58 -04:00
Corey Farwell
4525810737 Rewrite an emptiness check. 2017-04-17 21:58:34 -04:00
Corey Farwell
5d72d966ad Wrap long line. 2017-04-17 21:56:01 -04:00
Corey Farwell
15dcca87d8 Refactor to prevent excessive indentation. 2017-04-17 21:55:32 -04:00
Corey Farwell
c6e81337fb Implement new 'no-create' build flag.
Fixes https://github.com/azerupi/mdBook/issues/253.
2017-04-17 21:53:27 -04:00
Steve Klabnik
9602acce80 Merge pull request #252 from crazymerlyn/fix-runnable-files
Remove the extra run button on runnable rust files
2017-04-16 11:58:07 -04:00
CrazyMerlyn
65d7e86024 Remove the extra run button on runnable rust files
The playpen helper now uses a simple pre block instead of a pre block
with class playpen as it led to nested playpens.
2017-04-16 18:17:59 +05:30
Mathieu David
b5ec813d2f Merge pull request #250 from regexident/master
Added monospace font with support for box-drawing chars
2017-04-15 20:37:17 +02:00
Vincent Esche
41735b4579 Added monospace font with support for box-drawing chars 2017-04-15 14:16:28 +02:00
Jesse Millikan
d24ad83a5c Empty header sections 2017-04-14 15:51:23 -04:00
Steve Klabnik
9cb232058b Merge pull request #243 from steveklabnik/gh241
Accept nightly examples.
2017-04-14 15:19:07 -04:00
Mathieu David
ef402c16e8 Merge pull request #248 from mthh/master
Fix alignement of chapters with three digit numbering
2017-04-14 20:25:21 +02:00
mthh
df5472ab5a Should fix sections created with chapter of more than two digits 2017-04-07 12:46:28 +02:00
mthh
d768963c30 Revert "should fix sections created with chapter of more than two digits"
This reverts commit 8e7ec6e1fd.
2017-04-07 10:47:45 +02:00
mthh
8e7ec6e1fd should fix sections created with chapter of more than two digits 2017-04-07 02:37:46 +02:00
steveklabnik
80f01d70c6 Accept nightly examples.
This also brings us to parity with rustdoc regarding attributes in
general; while this PR was focused on enabling nightly, that was a
happy accident.
2017-03-31 17:06:03 -04:00
Mathieu David
40f275bf21 Merge pull request #236 from steveklabnik/master
add a .gitattributes to ensure proper line ending settings
2017-03-31 15:27:11 +02:00
Mathieu David
af8300c0b4 Merge pull request #239 from tshepang/misplaced
move misplaced example
2017-03-31 15:26:00 +02:00
Tshepang Lekhonkhobe
793a88260c move misplaced example 2017-03-30 14:09:14 +02:00
Steve Klabnik
1ec776244d Merge pull request #238 from tshepang/misc
typos
2017-03-29 14:17:44 -04:00
Tshepang Lekhonkhobe
4af107b0ca typos 2017-03-29 16:42:55 +02:00
steveklabnik
35e2807138 add a .gitattributes to ensure proper line ending settings 2017-03-28 09:50:57 -04:00
Mathieu David
1632d2e339 Merge pull request #230 from crazymerlyn/ignore_arrow_keys_with_modifier
Fix keyboard navigation to trigger only if no modifier key is pressed
2017-03-26 18:49:27 +02:00
Steve Klabnik
7c3932cef9 Merge pull request #231 from crazymerlyn/fix-header-link-id
Fix header links
2017-03-24 10:24:53 -04:00
CrazyMerlyn
ed1a216121 Fix header links
Header fragment links now use "id" attribute instead of the depreciated
"name" attribute.

Similar headers are given numbered ids to avoid id collisions.
For instance, if there are three headers named "Example", their ids
would be "#example", "#example-1", and "#example-2" respectively.
2017-03-23 23:24:26 +05:30
CrazyMerlyn
f814e96459 Fix keyboard navigation to trigger only if no modifier key is pressed 2017-03-23 13:29:04 +05:30
Jesse Millikan
980ea5796e next and prev attributes on the next and prev links, and #content 2017-03-19 16:21:38 -04:00
Jesse Millikan
8500d1c8a7 Relative links for non-JS browsers 2017-03-19 03:53:24 -04:00
Steve Klabnik
a7272e0ff5 Merge pull request #226 from steveklabnik/master
bump version
2017-03-10 10:40:21 -08:00
steveklabnik
1cf4774737 bump version 2017-03-10 13:39:35 -05:00
Steve Klabnik
c6a5d12002 Merge pull request #222 from steveklabnik/gh29
Implement playpen support for ```rust
2017-03-10 08:59:15 -08:00
steveklabnik
b120ce7397 inject allow(unused_variables) 2017-03-10 09:46:11 -05:00
Steve Klabnik
c7916c4818 Merge pull request #225 from integer32llc/update-hljs
Update to highlight.js 9.10.0
2017-03-10 05:53:10 -08:00
Carol (Nichols || Goulding)
56f597b90c Update to highlight.js 9.10.0 2017-03-09 22:45:59 -05:00
steveklabnik
c5f9625feb inject main 2017-03-06 13:27:25 -05:00
steveklabnik
79f00eeea3 Implement playpen support for ```rust
Fixes #29
2017-03-06 12:23:15 -05:00
Mathieu David
677fa42458 (cargo-release) start next development iteration 0.0.18-pre 2017-02-28 17:22:51 +01:00
Mathieu David
a8bba0b94d (cargo-release) version 0.0.17 2017-02-28 17:20:28 +01:00
Mathieu David
e5a973a18d Merge pull request #212 from azerupi/fix-anchors
Fix anchors #211
2017-02-28 14:50:40 +01:00
Mathieu David
e218257e42 fix anchor links 2017-02-28 12:42:11 +01:00
Mathieu David
1345c05b18 Fix anchors, Fixes #211 2017-02-28 12:40:05 +01:00
Mathieu David
5e3a3f3482 Merge pull request #214 from azerupi/fix-rust-hide
Fix code blocks with comma separated classes
2017-02-28 12:33:52 +01:00
Mathieu David
7f46071faa Merge pull request #215 from steveklabnik/travis
Try to fix Travis
2017-02-28 10:59:02 +01:00
Steve Klabnik
5674da2afb fix travis 2017-02-27 20:21:35 -05:00
Mathieu David
01341a7705 Fix code blocks with comma separated classes 2017-02-28 01:41:06 +01:00
Mathieu David
0c624d0f74 bump version 2017-02-20 16:16:21 +01:00
Mathieu David
58cfef00f2 Merge pull request #209 from steveklabnik/gh204
Print version: fix up header links
2017-02-20 16:12:00 +01:00
Steve Klabnik
6af3eea24b Print version: fix up header links 2017-02-20 09:28:49 -05:00
Mathieu David
c88656284c Regenerate css 2017-02-19 11:13:19 +01:00
Mathieu David
14a28080c1 Merge pull request #208 from frewsxcv/bump
Bump crates.
2017-02-19 11:10:46 +01:00
Corey Farwell
7fa36f82b0 Bump ws crate to 0.6. 2017-02-18 20:28:12 -05:00
Corey Farwell
3a30e65eef Bump staticfile crate to 0.4, iron to 0.5. 2017-02-18 20:26:12 -05:00
Corey Farwell
fab24f5224 Bump notify crate to 0.4. 2017-02-18 20:24:27 -05:00
Corey Farwell
cfa4295d79 Bump toml crate to 0.3. 2017-02-18 20:22:55 -05:00
Mathieu David
d7f38d08fd Merge pull request #205 from frewsxcv/clippy
Address warnings found by rust-clippy.
2017-02-17 11:05:33 +01:00
Mathieu David
864be6cf42 Merge pull request #207 from steveklabnik/gh204
Generate links at compile-time rather than use JS
2017-02-17 11:00:39 +01:00
Steve Klabnik
ec42e2f771 convert to one pass
thanks @burntsushi ❤️
2017-02-16 19:31:52 -05:00
Steve Klabnik
aba153a271 update env_logger 2017-02-16 17:17:26 -05:00
Steve Klabnik
280dabecd7 update regex dep 2017-02-16 17:11:16 -05:00
Steve Klabnik
38b3516b60 Implement links in section headers.
This project already had a transitive dependency on regex; let's use it.

This isn't the most efficient solution, but it should be fine. It ends
up doing five full scans of the text. There's probably an easier way but
I'm mostly just trying to get this to work for now.

This also implements the same algorithm that rustdoc does for generating
the name for the link.

Fixes #204
2017-02-16 17:07:17 -05:00
Steve Klabnik
d609988264 remove js rendering 2017-02-16 17:07:16 -05:00
Corey Farwell
95fd292b4f Address warnings found by rust-clippy.
https://github.com/Manishearth/rust-clippy
2017-02-16 16:55:28 -05:00
Mathieu David
f3fb1f1e16 Merge pull request #206 from frewsxcv/serde
Bump serde, serde_json, and handlebars crates.
2017-02-16 22:51:37 +01:00
Corey Farwell
152ebba762 Bump serde, serde_json, and handlebars crates. 2017-02-15 23:31:05 -05:00
Mathieu David
23d25c853e Merge pull request #202 from paiv/paiv-widen-menu-hitregions
widen hit regions of menu buttons
2017-02-11 23:45:59 +01:00
Pavel Ivashkov
b97a8205f6 widen hit regions of menu buttons
![see here](http://i.imgur.com/jCZTCfr.png)
2017-02-11 21:20:12 +02:00
Mathieu David
82faec6b5a Merge pull request #201 from petehayes102/master
Add docs for --dest-dir option
2017-01-17 12:21:21 +01:00
Pete Hayes
32814f6f71 Remove blank ***note*** section 2017-01-17 00:19:09 +00:00
Pete Hayes
ac6f15cb27 Add docs for --dest-dir option 2017-01-17 00:19:09 +00:00
Mathieu David
0d6185ac96 Merge pull request #199 from petehayes102/master
Add --dest-dir option to build, watch and serve subcommands
2017-01-13 12:07:34 +01:00
Pete Hayes
4b31ae6789 Add --dest-dir arg to build, watch and serve subcommands 2017-01-12 12:26:22 +00:00
Pete Hayes
1afa2debc1 Fix spelling of omitted 2017-01-12 12:23:39 +00:00
Mathieu David
3a71371946 Merge pull request #198 from mbrubeck/watch
Update watch command to use `notify` 3.0
2017-01-02 19:58:47 +01:00
Mathieu David
9a318adc03 Merge pull request #197 from mbrubeck/cleanup
Clean up some Path code in bookconfig
2017-01-02 19:43:45 +01:00
Matt Brubeck
c7b4147ba7 Watch both book.json and book.toml 2017-01-01 16:03:49 -08:00
Matt Brubeck
1ac2602360 Update to notify 3.0
notify now does its own event debouncing, so it's no longer necessary
for mdbook to do this manually.
2017-01-01 16:03:49 -08:00
Matt Brubeck
09729aaca5 Clean up some Path code in bookconfig 2017-01-01 16:02:48 -08:00
Mathieu David
3ffd24df63 Merge pull request #196 from mbrubeck/open
Add a CLI option to open a web browser
2017-01-01 19:22:55 +01:00
Mathieu David
fe8d46b8e6 Merge pull request #195 from mbrubeck/refactor
Various refactoring and cleanup
2017-01-01 19:21:40 +01:00
Matt Brubeck
21bc3d47c8 Add a CLI option to open a web browser 2017-01-01 09:58:20 -08:00
Matt Brubeck
f2b87f7944 Factor common io error handling out of renderer 2016-12-31 23:12:38 -08:00
Matt Brubeck
894a03655e Simplify error handling in utils::fs 2016-12-31 23:12:38 -08:00
Matt Brubeck
6b2572e78d Simplify some as_str error handling code 2016-12-31 18:41:59 -08:00
Matt Brubeck
fe287a1eca Code cleanup: Remove unnecessary .remove() calls
`BTreeMap::insert` will replace any existing value, so there's no need
to remove the old value first.
2016-12-31 18:33:17 -08:00
Mathieu David
375502a6fa Merge pull request #194 from mbrubeck/warnings
Fix some rustc warnings.
2016-12-31 23:45:23 +01:00
Mathieu David
a6e1844aad Merge pull request #193 from mbrubeck/chapter-title
Add current chapter title to handlebars context
2016-12-31 23:43:39 +01:00
Mathieu David
d92852867b Merge pull request #192 from mbrubeck/docs
Fix a broken link in the documentation
2016-12-31 23:38:09 +01:00
Matt Brubeck
0f0750df52 Fix unreachable code warning in parse::summary::parse_level 2016-12-31 10:39:48 -08:00
Matt Brubeck
712adcf737 Fix cfg attribute in bookconfig_test 2016-12-31 10:36:19 -08:00
Matt Brubeck
3a0cfc87df Add current chapter title to handlebars context 2016-12-31 10:34:36 -08:00
Matt Brubeck
b1e384b03b Fix a broken link in the documentation
This fixes a broken link on http://azerupi.github.io/mdBook/cli/init.html

The `..` is redundant because the document's base URI is set to
`path_to_root`.  It breaks if the base URI is not at the server root.
2016-12-31 09:20:54 -08:00
Mathieu David
6410e792d7 Merge pull request #191 from jessestricker/readme-typos
Fix some minor typos and text inconsistencies
2016-12-29 18:02:15 +01:00
Jesse Stricker
b75243f1f5 Fix some minor typos 2016-12-29 16:25:51 +01:00
Mathieu David
f1df53a4bb Merge pull request #190 from gambhiro/parse-toml
Parse toml
2016-12-26 13:36:16 +01:00
Gambhiro
8a178e311d fix test 2016-12-24 13:44:24 +00:00
Gambhiro
53ec61ac70 upd example 2016-12-24 13:34:22 +00:00
Gambhiro
97d46e79b7 convert json to toml before config parsing 2016-12-24 13:22:01 +00:00
Gambhiro
552e39c897 update example to encourage using book.toml 2016-12-23 08:17:04 +00:00
Gambhiro
791487bc84 parse either book.toml or book.json 2016-12-23 08:15:32 +00:00
Gambhiro
f67ae7c71a update dependency versions 2016-12-23 08:10:42 +00:00
Mathieu David
e53dcdcf4d Merge pull request #186 from gambhiro/book-json-keys
Book json keys
2016-12-13 00:55:51 +01:00
Gambhiro
85d8e2ebd3 use theme_path key in book.json when given 2016-12-07 14:22:32 +00:00
Gambhiro
a9e5dc63f1 use src key in book.json when given 2016-12-07 09:38:56 +00:00
Mathieu David
cf35e08abc Merge pull request #181 from thomastanck/master
Use fixed positioning and remove overflow-x's for smoother scrolling …
2016-11-22 10:06:41 +01:00
Mathieu David
c986b3afc4 Merge pull request #182 from integer32llc/hljs-class
Add hljs class to all code blocks, regardless of highlighting
2016-11-14 07:48:07 +01:00
Carol (Nichols || Goulding)
08b5d14f7e Add hljs class to all code blocks, regardless of highlighting
Fixes #179.

Highlight.js does not apply syntax highlighting to code blocks marked
no-highlight, nohighlight, plain, or text. When it finds blocks of those
languages, it does not add the `hljs` class to those code blocks either.

highlight.css and tomorrow-night.css use the `hljs` class to give code
blocks their backrgound color and text color, and we want that to apply
even if the code doesn't get syntax highlighting markup.

This is a somewhat hacky solution to get just that behavior! After this
commit, code blocks with no-highlight, nohighlight, plain, or text
language set on them will indeed get the hljs colors.
2016-11-13 21:14:00 -05:00
Thomas Tan
f9101ca62c Use fixed positioning and remove overflow-x's for smoother scrolling experience in iOS 2016-11-09 16:18:40 +00:00
Mathieu David
f0c0d71326 Merge pull request #177 from azerupi/serde
Switch from rustc_serialize to serde
2016-11-03 11:44:34 +01:00
Mathieu David
d2f3eb5007 remove unused imports 2016-11-03 02:05:35 +01:00
Mathieu David
67aee5c192 Switch from rustc_serialize to serde. Closes #18 2016-11-03 01:58:42 +01:00
Mathieu David
30eb85711e Merge pull request #175 from DenisKolodin/metadata-remove
Remove unused metadata import
2016-11-01 12:44:23 +01:00
Denis Kolodin
b0d33e76ec Remove unused metadata import 2016-11-01 11:19:08 +03:00
Mathieu David
eb65f3fd1e Merge pull request #174 from rnkaufman/update-highlight-js
Highlight js update
2016-10-29 16:42:32 +02:00
rnkaufman
2600c62cf9 Highlight js update 2016-10-27 18:26:02 -07:00
Mathieu David
ecae442d25 Merge pull request #173 from HParker/slugify-section-anchors
slugify section headers
2016-10-21 22:12:40 +02:00
Adam Hess
f26f41fde3 slugify section headers
The current section headers are url encoded.  Because of that they
have some funny characters like %20.  We can clean that up by removing
all of the non-word characters before placing them in the anchor.
2016-10-20 22:02:16 -07:00
Mathieu David
b91f817bfd Merge pull request #171 from rzlourenco/master
Fix a bug where files without an extension were not copied
2016-09-23 22:13:30 +02:00
Rodrigo Lourenço
528945d67d Copy files with no extension too. 2016-09-23 15:09:16 +01:00
Mathieu David
4852e9e65a Merge branch 'master' of https://github.com/azerupi/mdBook 2016-09-12 22:50:03 +02:00
Mathieu David
e54b6643e1 regenerate css 2016-09-12 22:43:29 +02:00
Mathieu David
c7a95ccb8b Fix round corners in theme selector, changes were previously comitted directly to the css file causing them to be overwritten 2016-09-12 22:19:36 +02:00
Mathieu David
81a8f946b7 Fix print.styl, changes were previously comitted directly to the css file causing them to be overwritten 2016-09-12 22:10:33 +02:00
Mathieu David
04a643805a Merge pull request #170 from JIghtuse/master
Make line-height for chapter greater than section
2016-09-12 22:01:13 +02:00
Boris Egorov
49608b560b Make line-height for chapter greater than section
Fixes #166
2016-09-04 22:04:55 +07:00
Mathieu David
9e634a4e83 Bump version number to 0.0.15, 0.0.14 has been published to crates.io 2016-08-31 15:11:33 +02:00
Mathieu David
c2c721025d Merge pull request #165 from waywardmonkeys/patch-1
Fix typo.
2016-08-26 20:14:14 +02:00
Bruce Mitchener
2dfc25fc6e Fix typo. 2016-08-27 00:28:17 +07:00
Mathieu David
8f8893bab2 Merge pull request #164 from gambhiro/use-log-crate
use macros from the log crate, issue #151
2016-08-14 16:19:17 +02:00
Gambhiro
4153db2624 env_logger 2016-08-14 14:55:10 +01:00
Gambhiro
db11ff27f4 use warn 2016-08-14 14:40:08 +01:00
Gambhiro
b584f6eb9c use macros from the log crate, issue #151 2016-08-14 13:34:02 +01:00
Mathieu David
a7ae0b99c4 Update README.md 2016-08-13 11:36:28 +02:00
Mathieu David
9732a3bc7d Merge pull request #161 from integer32llc/exit-status
Exit with a nonzero status if we get an error
2016-08-07 00:07:41 +02:00
Mathieu David
f3f9c93765 Merge pull request #162 from integer32llc/fix-example-book
Fix book-example tests
2016-08-07 00:06:05 +02:00
Carol (Nichols || Goulding)
a0d8013242 Tell rustdoc this mathjax is not rust
Use bash for the grey background though.
2016-08-06 15:25:40 -04:00
Carol (Nichols || Goulding)
1b9d55bcd5 Put spaces between # and hidden lines 2016-08-06 15:25:40 -04:00
Carol (Nichols || Goulding)
a459a3606e Exit with a nonzero status if we get an error
This is especially important when mdbook is used with CI.
2016-08-06 14:54:07 -04:00
Mathieu David
1e6bccd924 Merge branch 'master' of https://github.com/azerupi/mdBook 2016-08-06 11:39:17 +02:00
Mathieu David
6d77b7fd83 Fix CI for musl builds, musl builds now run but will not cause a build failure if they do not succeed 2016-08-06 11:39:00 +02:00
Mathieu David
f9ea6135c3 Merge pull request #160 from code-ape/master
Added option to configure serve interface and public websocket address.
2016-08-05 23:54:33 +02:00
Ferris
317023cd0e Added option to configure serve interface and address browser will use to connect to websocket server. 2016-08-05 21:40:00 +00:00
Mathieu David
0b88b043d0 Bump version number to 0.0.14, 0.0.13 has been published to crates.io [ci_skip] 2016-08-02 00:58:08 +02:00
Mathieu David
ac725cb39d bump version to 0.0.13 to publish to crates.io 2016-08-02 00:42:17 +02:00
Mathieu David
db0306a6d2 Fix bug in shell script that was preventing deployment of the docs to gh-pages 2016-08-02 00:15:38 +02:00
Mathieu David
02c5c971e7 (Travis-ci): Allow failure in musl builds #158 2016-08-01 20:05:03 +02:00
Mathieu David
5350d62591 Update all dependencies to latest version 2016-08-01 14:06:08 +02:00
Mathieu David
9c8a563223 Merge pull request #157 from icanrealizeum/anchorsfixxage
Fixes #156 - anchors are now URI encoded
2016-07-31 14:31:32 +02:00
icanrealizeum
b4948b680f Fixes #156 - anchors are now URI encoded
also fixes https://github.com/rust-lang/book/issues/166 anchors duplication

Thanks @azerupi for mentoring in #156 !
Cheers!
2016-07-31 15:21:58 +03:00
Mathieu David
b6df992420 Merge pull request #152 from quornian/master
Make sure <ul><li> and </li></ul> are balanced
2016-07-23 15:04:51 +02:00
Ian Thompson
b0e5f375ba Make sure <ul><li> and </li></ul> are balanced 2016-07-16 10:23:22 -04:00
Mathieu David
a4a277cb50 Merge pull request #145 from onur/light-theme-as-default
Use light theme when javascript is disabled
2016-06-15 16:45:10 +02:00
Onur Aslan
b9e22bb8f2 Use light theme when javascript is disabled
mdBook is setting theme (by adding a class attribute to body tag) with javascript.
Page is not using any theme by default and page is not using any styling unless
javascript is enabled.

This patch is adding class attribute to body tag and making mdBook to use `light`
theme when javascript is disabled.

Fixes: #144
2016-06-15 17:25:28 +03:00
Mathieu David
ab29e92071 Merge pull request #143 from austinhartzheim/us-issue-133
Fix azerupi/mdBook#133: Add link to source code
2016-06-12 10:37:38 +02:00
Austin Hartzheim
03373c6bf2 Fix azerupi/mdBook#133 by adding a link to the GitHub repo at the end of the --help output. 2016-06-11 23:08:48 +00:00
Mathieu David
425b583625 Merge pull request #142 from Bobo1239/printing
Add print media query
2016-06-10 23:32:52 +02:00
Boris-Chengbiao Zhou
dfef0d7585 Add print media query 2016-06-10 19:30:26 +02:00
Mathieu David
9b49acc2c9 Merge pull request #139 from japaric/no-default-features
ci: test without default features, closes #138
2016-05-09 09:53:25 +02:00
Jorge Aparicio
1ae0d4f637 ci: test without default features
closes #138
2016-05-08 18:26:33 -05:00
Mathieu David
f9aa9a6843 Merge pull request #137 from Bobo1239/fix-no-default-features
Fix no-default-features build, fixes #136
2016-05-08 23:29:35 +02:00
Boris-Chengbiao Zhou
9b1e224680 Fix no-default-features build 2016-05-08 21:51:34 +02:00
Mathieu David
cfcf6d952f Merge pull request #134 from Bobo1239/serve-print
Add host and port output when running mdbook serve Closes #132
2016-04-27 22:35:26 +02:00
Boris-Chengbiao Zhou
e3f398cff2 Add address output to mdbook serve 2016-04-27 22:29:48 +02:00
Mathieu David
6bc088db6e (Refactor) Move the Render trait into mod.rs instead of submodule 2016-04-27 14:19:59 +02:00
Mathieu David
e34bef0e53 (Refactor) Move mdbook.rs to mod.rs 2016-04-26 23:04:27 +02:00
Mathieu David
15d6227a11 Attempt to fix #119 replace \ with / in paths, so that Windows also uses / as separator (ugly hack) 2016-04-25 17:02:47 +02:00
Mathieu David
1b8af2bf57 Fix #120 destination and source directories can now be constructed correctly even if multiple directories do not exist on the path 2016-04-25 15:58:44 +02:00
Mathieu David
7f34512751 Merge branch 'master' of https://github.com/azerupi/mdBook 2016-04-25 15:51:27 +02:00
Mathieu David
876ea7895a Fix #131 where src and dest paths were not prefixed with the root directory if it was not the current directory 2016-04-25 15:50:34 +02:00
Mathieu David
bea80f6266 Merge pull request #130 from japaric/rustup
travis: use rustup instead of Travis built-in Rust support
2016-04-14 01:20:19 +02:00
Jorge Aparicio
334540835c travis: use rustup instead of Travis built-in Rust support
this ensures we install the correct set of standard crates when working
in the beta channel
2016-04-13 16:48:57 -05:00
Mathieu David
10e7a41d92 Bump version to 0.0.12, version 0.0.11 has been published to crates.io 2016-04-13 22:37:46 +02:00
Mathieu David
2ec5648587 Remove BookConfig field from MDBook
MDBook now stores the necessary information, BookConfig is not used as a field anymore. It is only used for parsing the configuration file. This allows to more easily replace the book.json config with the new tomlbased config
2016-04-05 12:44:14 +02:00
Mathieu David
6aa6546ce4 Merge pull request #128 from Bobo1239/serve-squashed
Implement Serve feature
2016-04-04 23:17:01 +02:00
Mathieu David
c071406fef Merge pull request #127 from japaric/mac32
travis: test/release on/for i686-apple-darwin
2016-04-04 19:23:36 +02:00
Boris-Chengbiao Zhou
c8051294b0 Switch from rust-websocket to ws-rs 2016-04-02 21:44:13 +02:00
Jorge Aparicio
807a2f116e travis: test/release on/for i686-apple-darwin 2016-04-02 09:33:05 -05:00
Boris-Chengbiao Zhou
2f43167b75 Add documentation for Serve feature 2016-04-02 05:43:21 +02:00
Boris-Chengbiao Zhou
e861880f95 Implement Serve feature 2016-04-02 05:20:46 +02:00
Mathieu David
c3564f1699 Add convenience function to read the content from a file into a string given a path 2016-03-27 18:40:50 +02:00
Mathieu David
15d26befcc Refactor: Move extern crate definitions to lib.rs 2016-03-27 18:22:17 +02:00
Mathieu David
925939e267 Merge pull request #124 from LucioFranco/insecure-content-fix
Fix for insecure content on HTTPS enabled sites
2016-03-23 23:22:44 +01:00
Lucio Franco
ceb139a848 Moved CDN's to https 2016-03-23 14:16:41 -06:00
Mathieu David
d0e39f469a Update installation instructions in the README
Closes #123
2016-03-22 14:06:32 +01:00
Mathieu David
c5752620d7 Merge pull request #122 from Bobo1239/fix_cooldown
Fix watch event cooldown
2016-03-19 19:40:58 +01:00
Mathieu David
0c93599242 Merge pull request #121 from Bobo1239/update_deps
Update dependencies
2016-03-19 19:38:01 +01:00
Boris Zhou
7f3a6c8130 Fix watch event cooldown 2016-03-19 18:28:34 +01:00
Boris-Chengbiao Zhou
b30a8bdc81 Update dependencies 2016-03-19 17:45:58 +01:00
Mathieu David
74fff81e4b Refactor: Move fs related functions from utils into their own submodule 2016-03-17 22:41:00 +01:00
Mathieu David
ad0794a0bd Add a rustfmt config and run rustfmt on the code base 2016-03-17 22:31:28 +01:00
Mathieu David
6bac41caa8 Merge pull request #118 from japaric/travis
Travis CI: expand to test and deploy for Linux and Mac
2016-03-08 17:25:52 +01:00
Jorge Aparicio
b094268b68 disable the i686-apple-darwin target 2016-03-08 09:21:50 -05:00
Jorge Aparicio
02a37e0ee9 disable doc tests when crossing 2016-03-08 08:57:35 -05:00
Mathieu David
9e34eccb3e Add windows (AppVeyor) build badge 2016-03-08 01:03:44 +01:00
Mathieu David
79fb92ed7c Merge pull request #117 from japaric/appveyor
set up AppVeyor to test and deploy on Windows
2016-03-08 00:35:54 +01:00
Jorge Aparicio
5e78697ab1 Travis CI: expand to test and deploy for Linux and Mac 2016-03-07 18:16:42 -05:00
Jorge Aparicio
469cb10d4a manually package artifact during before_deploy phase
The automatic packaging phase runs before the before_deploy phase which is too early so we can rely
on it.
2016-03-07 18:01:05 -05:00
Jorge Aparicio
0f9caf4410 set up AppVeyor to test and deploy on Windows 2016-03-07 17:14:05 -05:00
Mathieu David
f23a5f2729 Merge pull request #115 from vrinek/init-with-gitignore-take-2
Move `.gitignore` directly under the root folder
2016-03-07 12:09:25 +01:00
vrinek
bc41efe414 Move .gitignore directly under the root folder 2016-03-07 08:52:19 +00:00
Mathieu David
5316089e61 Modify wording of confirmation request before creation of .gitignore 2016-03-02 19:38:39 +01:00
Mathieu David
73ce3f814a Merge branch 'init-with-gitignore' of https://github.com/vrinek/mdBook into vrinek-init-with-gitignore 2016-03-02 19:20:21 +01:00
Mathieu David
075da959c9 bump version, v0.0.10 has been published to crates.io 2016-03-01 18:50:04 +01:00
Mathieu David
80deac90d9 Merge branch 'master' of https://github.com/azerupi/mdBook 2016-03-01 18:33:55 +01:00
Mathieu David
625f5081fa update notify and change dependency version restrictions 2016-03-01 18:32:43 +01:00
vrinek
1eb59428e6 Ask user to create .gitignore and skip on --force 2016-02-28 15:28:11 +00:00
Mathieu David
3e8151e8e3 Merge pull request #112 from jessestricker/feature-meta
Add description config option
2016-02-25 17:21:51 +01:00
Jesse Stricker
3c10a85735 Add documentation and example for description config 2016-02-25 15:01:16 +01:00
Jesse Stricker
330b1ad55d Add description config option 2016-02-25 14:32:49 +01:00
vrinek
596455f28c Generate simple .gitignore on init 2016-02-23 14:03:45 +00:00
Mathieu David
f24eb59753 Bump version number, v0.0.9 has been published to Crates.io 2016-02-22 19:03:31 +01:00
Mathieu David
01c5085725 Add an entry about the favicon in the docs 2016-02-22 18:01:36 +01:00
Mathieu David
9f17be2c32 Merge pull request #109 from jessestricker/feature-favicon
Add theme support for favicon
2016-02-22 17:28:46 +01:00
Jesse Stricker
88fabd76f0 Copy favicon on 'init --theme' 2016-02-22 17:20:54 +01:00
Jesse Stricker
f508db6113 Add favicon support to theme 2016-02-22 17:17:07 +01:00
Jesse Stricker
1083d1822d Add default favicon.png 2016-02-22 16:59:53 +01:00
Mathieu David
fc86b963bb Merge pull request #108 from funkill/styles
add rounding for first and last items in theme selector
2016-02-16 10:30:01 +01:00
funkill
f2b913c9dd add rounding for first and last items in theme selector 2016-02-16 11:15:08 +03:00
Mathieu David
dd0cfc14d4 bump version number to 0.0.9, v0.0.8 has been published to crates.io 2016-02-16 08:57:55 +01:00
258 changed files with 33056 additions and 4956 deletions

8
.gitattributes vendored Normal file
View File

@@ -0,0 +1,8 @@
[attr]rust text eol=lf whitespace=tab-in-indent,trailing-space,tabwidth=4
* text=auto eol=lf
*.rs rust
*.woff binary
*.ttf binary
*.otf binary
*.png binary

45
.github/ISSUE_TEMPLATE/bug_report.yml vendored Normal file
View File

@@ -0,0 +1,45 @@
name: Bug Report
description: Create a report to help us improve
labels: ["C-bug"]
body:
- type: markdown
attributes:
value: Thanks for filing a 🐛 bug report 😄!
- type: textarea
id: problem
attributes:
label: Problem
description: >
Please provide a clear and concise description of what the bug is,
including what currently happens and what you expected to happen.
validations:
required: true
- type: textarea
id: steps
attributes:
label: Steps
description: Please list the steps to reproduce the bug.
placeholder: |
1.
2.
3.
- type: textarea
id: possible-solutions
attributes:
label: Possible Solution(s)
description: >
Not obligatory, but suggest a fix/reason for the bug,
or ideas how to implement the addition or change.
- type: textarea
id: notes
attributes:
label: Notes
description: Provide any additional notes that might be helpful.
- type: textarea
id: version
attributes:
label: Version
description: >
Please paste the output of running `mdbook --version` or which version
of the library you are using.
render: text

View File

@@ -0,0 +1,28 @@
name: Enhancement
description: Suggest an idea for enhancing mdBook
labels: ["C-enhancement"]
body:
- type: markdown
attributes:
value: |
Thanks for filing a 🙋 feature request 😄!
- type: textarea
id: problem
attributes:
label: Problem
description: >
Please provide a clear description of your use case and the problem
this feature request is trying to solve.
validations:
required: true
- type: textarea
id: solution
attributes:
label: Proposed Solution
description: >
Please provide a clear and concise description of what you want to happen.
- type: textarea
id: notes
attributes:
label: Notes
description: Provide any additional context or information that might be helpful.

24
.github/ISSUE_TEMPLATE/question.yml vendored Normal file
View File

@@ -0,0 +1,24 @@
name: Question
description: Have a question on how to use mdBook?
labels: ["C-question"]
body:
- type: markdown
attributes:
value: |
Got a question on how to do something with mdBook?
- type: textarea
id: question
attributes:
label: Question
description: >
Enter your question here. Please try to provide as much detail as possible.
validations:
required: true
- type: textarea
id: version
attributes:
label: Version
description: >
Please paste the output of running `mdbook --version` or which version
of the library you are using.
render: text

58
.github/workflows/deploy.yml vendored Normal file
View File

@@ -0,0 +1,58 @@
name: Deploy
on:
release:
types: [created]
jobs:
release:
name: Deploy Release
runs-on: ${{ matrix.os }}
strategy:
matrix:
target:
- aarch64-unknown-linux-musl
- x86_64-unknown-linux-gnu
- x86_64-unknown-linux-musl
- x86_64-apple-darwin
- x86_64-pc-windows-msvc
include:
- target: aarch64-unknown-linux-musl
os: ubuntu-20.04
- target: x86_64-unknown-linux-gnu
os: ubuntu-20.04
- target: x86_64-unknown-linux-musl
os: ubuntu-20.04
- target: x86_64-apple-darwin
os: macos-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
steps:
- uses: actions/checkout@master
- name: Install hub
run: ci/install-hub.sh ${{ matrix.os }}
shell: bash
- name: Install Rust
run: ci/install-rust.sh stable ${{ matrix.target }}
shell: bash
- name: Build and deploy artifacts
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ci/make-release.sh ${{ matrix.os }} ${{ matrix.target }}
shell: bash
pages:
name: GitHub Pages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Install Rust (rustup)
run: rustup update stable --no-self-update && rustup default stable
- name: Build book
run: cargo run -- build guide
- name: Deploy to GitHub
env:
GITHUB_DEPLOY_KEY: ${{ secrets.GITHUB_DEPLOY_KEY }}
run: |
touch guide/book/.nojekyll
curl -LsSf https://raw.githubusercontent.com/rust-lang/simpleinfra/master/setup-deploy-keys/src/deploy.rs | rustc - -o /tmp/deploy
cd guide/book
/tmp/deploy

52
.github/workflows/main.yml vendored Normal file
View File

@@ -0,0 +1,52 @@
name: CI
on:
# Only run when merging to master, or open/synchronize/reopen a PR.
push:
branches:
- master
pull_request:
jobs:
test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
build: [stable, beta, nightly, macos, windows, msrv]
include:
- build: stable
os: ubuntu-latest
rust: stable
- build: beta
os: ubuntu-latest
rust: beta
- build: nightly
os: ubuntu-latest
rust: nightly
- build: macos
os: macos-latest
rust: stable
- build: windows
os: windows-latest
rust: stable
- build: msrv
os: ubuntu-20.04
# sync MSRV with docs: guide/src/guide/installation.md and Cargo.toml
rust: 1.60.0
steps:
- uses: actions/checkout@master
- name: Install Rust
run: bash ci/install-rust.sh ${{ matrix.rust }}
- name: Build and run tests
run: cargo test
- name: Test no default
run: cargo test --no-default-features
rustfmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Install Rust
run: rustup update stable && rustup default stable && rustup component add rustfmt
- run: cargo fmt --check

17
.gitignore vendored
View File

@@ -1,5 +1,18 @@
Cargo.lock
target
# MacOS temp file
.DS_Store
book-test
book-example/book
guide/book
.vscode
tests/dummy_book/book/
test_book/book/
# Ignore Jetbrains specific files.
.idea/
# Ignore Vim temporary and swap files.
*.sw?
*~

View File

@@ -1,20 +0,0 @@
language: rust
rust:
- stable
- beta
- nightly
matrix:
allow_failure:
- rust: nightly
env:
global:
secure: l3/qEC4krRerllLQzni8j5AjngFi6pluWvBWj//1mJLoIEYwxlQ9mYxEdd9BqccWWFn3K0bVYCVC/64+tP6sRfLkZCe2gPUtwe7ITwCDbapUxmkiRObVJCs5yMQZt6idyhHUDKAXKgNCrusfI2BM3tKGBfRK7Cnn/R/7p/U9+q7D1sgJtUKp6ypVzK6A3jLNp3dFLFI19a5KmbZMVsaa7tOhtdDJjjr7ebsc9z7HMW5/OItiWU3FSauVQQlUMaCiEgFuIG7H7OnBAYWB/gNEtLuwfLqU9UjtWk/njNNRnmJ7m3y5HbQhv5H5F5mJUOq9XFlPLwPwyTeVztSGdQm6k8Pp2pgKBUjY27afBl9BWU+msmN6k0oXfhvIebiBPe/x2udiKeFik1xqOOEU1q9dF0sZiuPxCSM1n7tgWklJ8epgaRQaMPPQw9pO/2H5/ynHCJqBlw6WcdiqWtwAyyr/GEx62u/cg5IVkqb7KLmYsWzjS8wYG4CYs1eIxCw2xPZxP0FGuUXvxTBUPipFze6Z7FqxVauXtVe2D7c1P4738HZP660rmR0GYtHtKLny1QxCCK9sxd9JmcezFCSz4YeQ1od9xc0OzGJ2ullKNGizmGfYmgL6X8faNylLIEdaiHAcY16xV3L0g3fXL1Qg360UHQyj7GIv+0nqQnf+H9xRTTU=
addons:
apt:
packages:
- nodejs
- npm
install:
- npm install stylus nib
after_success:
- test $TRAVIS_PULL_REQUEST == "false" && test $TRAVIS_BRANCH == "master" && bash deploy.sh

898
CHANGELOG.md Normal file
View File

@@ -0,0 +1,898 @@
# Changelog
## mdBook 0.4.26
[v0.4.25...v0.4.26](https://github.com/rust-lang/mdBook/compare/v0.4.25...v0.4.26)
### Changed
- Removed custom scrollbars for webkit browsers
[#1961](https://github.com/rust-lang/mdBook/pull/1961)
- Updated some dependencies
[#1998](https://github.com/rust-lang/mdBook/pull/1998)
[#2009](https://github.com/rust-lang/mdBook/pull/2009)
[#2011](https://github.com/rust-lang/mdBook/pull/2011)
- Fonts are now part of the theme.
The `output.html.copy-fonts` option has been deprecated.
To define custom fonts, be sure to define `theme/fonts.css`.
[#1987](https://github.com/rust-lang/mdBook/pull/1987)
### Fixed
- Fixed overflow viewport issue with mobile Safari
[#1994](https://github.com/rust-lang/mdBook/pull/1994)
## mdBook 0.4.25
[e14d381...1ba74a3](https://github.com/rust-lang/mdBook/compare/e14d381...1ba74a3)
### Fixed
- Fixed a regression where `mdbook test -L deps path-to-book` would not work.
[#1959](https://github.com/rust-lang/mdBook/pull/1959)
## mdBook 0.4.24
[eb77083...8767ebf](https://github.com/rust-lang/mdBook/compare/eb77083...8767ebf)
### Fixed
- The precompiled linux-gnu mdbook binary available on [GitHub Releases](https://github.com/rust-lang/mdBook/releases) inadvertently switched to a newer version of glibc. This release goes back to an older version that should be more compatible on older versions of Linux.
[#1955](https://github.com/rust-lang/mdBook/pull/1955)
## mdBook 0.4.23
[678b469...68a75da](https://github.com/rust-lang/mdBook/compare/678b469...68a75da)
### Changed
- Updated all dependencies
[#1951](https://github.com/rust-lang/mdBook/pull/1951)
[#1952](https://github.com/rust-lang/mdBook/pull/1952)
[#1844](https://github.com/rust-lang/mdBook/pull/1844)
- Updated minimum Rust version to 1.60.
[#1951](https://github.com/rust-lang/mdBook/pull/1951)
### Fixed
- Fixed a regression where playground code was missing hidden lines, preventing it from compiling correctly.
[#1950](https://github.com/rust-lang/mdBook/pull/1950)
## mdBook 0.4.22
[40c06f5...4844f72](https://github.com/rust-lang/mdBook/compare/40c06f5...4844f72)
### Added
- Added a `--chapter` option to `mdbook test` to specify a specific chapter to test.
[#1741](https://github.com/rust-lang/mdBook/pull/1741)
- Added CSS styling for `<kbd>` tags.
[#1906](https://github.com/rust-lang/mdBook/pull/1906)
- Added pre-compiled binaries for `x86_64-unknown-linux-musl` and `aarch64-unknown-linux-musl` (see [Releases](https://github.com/rust-lang/mdBook/releases)).
[#1862](https://github.com/rust-lang/mdBook/pull/1862)
- Added `build.extra-watch-dirs` which is an array of additional directories to watch for changes when running `mdbook serve`.
[#1884](https://github.com/rust-lang/mdBook/pull/1884)
### Changed
- Removed the `type="text/javascript"` attribute from `<script>` tags.
[#1881](https://github.com/rust-lang/mdBook/pull/1881)
- Switched to building with Rust Edition 2021.
This raises the minimum supported Rust version to 1.56.
[#1887](https://github.com/rust-lang/mdBook/pull/1887)
- When hidden code is hidden, the hidden parts are no longer copied to the clipboard via the copy button.
[#1911](https://github.com/rust-lang/mdBook/pull/1911)
- Various HTML changes and fixes to be more compliant with HTML5.
[#1924](https://github.com/rust-lang/mdBook/pull/1924)
- The theme picker now shows which theme is currently selected.
[#1935](https://github.com/rust-lang/mdBook/pull/1935)
### Fixed
- Avoid blank line at the end of an ACE code block
[#1836](https://github.com/rust-lang/mdBook/pull/1836)
## mdBook 0.4.21
[92afe9b...8f01d02](https://github.com/rust-lang/mdBook/compare/92afe9b...8f01d02)
### Fixed
- Fixed an issue where mdBook would fail to compile with Rust nightly-2022-07-22.
[#1861](https://github.com/rust-lang/mdBook/pull/1861)
## mdBook 0.4.20
[53055e0...da166e0](https://github.com/rust-lang/mdBook/compare/53055e0...da166e0)
### Fixed
- Fixed a regression in 0.4.19 where inline code would have excessive padding
in some situations such as headings.
[#1855](https://github.com/rust-lang/mdBook/pull/1855)
## mdBook 0.4.19
[ae275ad...53055e0](https://github.com/rust-lang/mdBook/compare/ae275ad...53055e0)
### Added
- The `serve` command now supports HEAD requests.
[#1825](https://github.com/rust-lang/mdBook/pull/1825)
### Changed
- An error is now generated when a custom theme directory does not exist.
[#1791](https://github.com/rust-lang/mdBook/pull/1791)
- Very wide tables now have independent horizontal scrolling so that scrolling
to see the rest of the table will not scroll the entire page.
[#1617](https://github.com/rust-lang/mdBook/pull/1617)
- The buttons on code blocks are now only shown when the mouse cursor hovers
over them (or tapped on mobile). There is also some extra spacing to reduce
the overlap with the code.
[#1806](https://github.com/rust-lang/mdBook/pull/1806)
- The first chapter always generates an `index.html` file. Previously it would
only generate the index file for prefix chapters.
[#1829](https://github.com/rust-lang/mdBook/pull/1829)
### Fixed
- `mdbook serve --open` now properly handles the case if the first chapter is a draft.
[#1714](https://github.com/rust-lang/mdBook/pull/1714)
[#1830](https://github.com/rust-lang/mdBook/pull/1830)
- Very long words (over 80 characters) are no longer indexed to avoid a stack overflow.
[#1833](https://github.com/rust-lang/mdBook/pull/1833)
## mdBook 0.4.18
[981b79b...ae275ad](https://github.com/rust-lang/mdBook/compare/981b79b...ae275ad)
### Fixed
- Fixed rendering of SUMMARY links that contain markdown escapes or other
markdown elements.
[#1785](https://github.com/rust-lang/mdBook/pull/1785)
## mdBook 0.4.17
[a5fddfa...981b79b](https://github.com/rust-lang/mdBook/compare/a5fddfa...981b79b)
### Fixed
- Fixed parsing of `output.html.print` configuration table.
[#1775](https://github.com/rust-lang/mdBook/pull/1775)
## mdBook 0.4.16
[68a5c09...a5fddfa](https://github.com/rust-lang/mdBook/compare/68a5c09...a5fddfa)
### Added
- Added `output.html.print.page-break` config option to control whether or not
there is a page break between chapters in the print output.
[#1728](https://github.com/rust-lang/mdBook/pull/1728)
- Added `output.html.playground.runnable` config option to globally disable
the run button in code blocks.
[#1546](https://github.com/rust-lang/mdBook/pull/1546)
### Changed
- The `mdbook serve` live reload websocket now uses the protocol, host, and
port of the current page, allowing access through a proxy.
[#1771](https://github.com/rust-lang/mdBook/pull/1771)
- The 404 not-found page now includes the books title in the HTML title tag.
[#1693](https://github.com/rust-lang/mdBook/pull/1693)
- Migrated to clap 3.0 which which handles CLI option parsing.
[#1731](https://github.com/rust-lang/mdBook/pull/1731)
### Fixed
- Minor fixes to the markdown parser.
[#1729](https://github.com/rust-lang/mdBook/pull/1729)
- Fixed incorrect parsing in `SUMMARY.md` when it didn't start with a title.
[#1744](https://github.com/rust-lang/mdBook/pull/1744)
- Fixed duplicate anchor IDs for links in search results.
[#1749](https://github.com/rust-lang/mdBook/pull/1749)
## mdBook 0.4.15
[5eb7d46...68a5c09](https://github.com/rust-lang/mdBook/compare/5eb7d46...68a5c09)
### Changed
- Major update to expand the documentation located at <https://rust-lang.github.io/mdBook/>.
[#1709](https://github.com/rust-lang/mdBook/pull/1709)
[#1710](https://github.com/rust-lang/mdBook/pull/1710)
- Updated the markdown parser with various fixes for common-mark compliance.
[#1712](https://github.com/rust-lang/mdBook/pull/1712)
## mdBook 0.4.14
[ffa8284...c9b6be8](https://github.com/rust-lang/mdBook/compare/ffa8284...c9b6be8)
### Added
- The 2021 Rust edition option has been stabilized.
[#1642](https://github.com/rust-lang/mdBook/pull/1642)
### Changed
- Header anchors no longer include any HTML tags. Previously only a small
subset were excluded.
[#1683](https://github.com/rust-lang/mdBook/pull/1683)
- Deprecated the google-analytics option. Books using this option should place
the appropriate code in the `theme/head.hbs` file instead.
[#1675](https://github.com/rust-lang/mdBook/pull/1675)
### Fixed
- Updated the markdown parser which brings in a few small fixes and removes
the custom smart quote handling.
[#1668](https://github.com/rust-lang/mdBook/pull/1668)
- Fixed iOS Safari enlarging text when going into landscape mode.
[#1685](https://github.com/rust-lang/mdBook/pull/1685)
## mdBook 0.4.13
[e6629cd...f55028b](https://github.com/rust-lang/mdBook/compare/e6629cd...f55028b)
### Added
- Added the ability to specify the preprocessor order.
[#1607](https://github.com/rust-lang/mdBook/pull/1607)
### Fixed
- Include chapters with no headers in the search index
[#1637](https://github.com/rust-lang/mdBook/pull/1637)
- Switched to the `opener` crate for opening a web browser, which should fix
some issues with blocking.
[#1656](https://github.com/rust-lang/mdBook/pull/1656)
- Fixed clicking the border of the theme switcher breaking the theme selection.
[#1651](https://github.com/rust-lang/mdBook/pull/1651)
## mdBook 0.4.12
[14add9c...8b4e488](https://github.com/rust-lang/mdBook/compare/14add9c...8b4e488)
### Changed
- Reverted the change to update to highlight.js 11, as it broke hidden code lines.
[#1597](https://github.com/rust-lang/mdBook/pull/1621)
## mdBook 0.4.11
[e440094...2cf00d0](https://github.com/rust-lang/mdBook/compare/e440094...2cf00d0)
### Added
- Added support for Rust 2021 edition.
[#1596](https://github.com/rust-lang/mdBook/pull/1596)
- Added `mdbook completions` subcommand which provides shell completions.
[#1425](https://github.com/rust-lang/mdBook/pull/1425)
- Added `--title` and `--ignore` flags to `mdbook init` to avoid the
interactive input.
[#1559](https://github.com/rust-lang/mdBook/pull/1559)
### Changed
- If running a Rust example does not have any output, it now displays the text
"No output" instead of not showing anything.
[#1599](https://github.com/rust-lang/mdBook/pull/1599)
- Code block language tags can now be separated by space or tab (along with
commas) to match the behavior of other sites like GitHub and rustdoc.
[#1469](https://github.com/rust-lang/mdBook/pull/1469)
- Updated `warp` (the web server) to the latest version.
This also updates the minimum supported Rust version to 1.46.
[#1612](https://github.com/rust-lang/mdBook/pull/1612)
- Updated to highlight.js 11. This has various highlighting improvements.
[#1597](https://github.com/rust-lang/mdBook/pull/1597)
### Fixed
- Inline code blocks inside a header are no longer highlighted when
`output.html.playground.editable` is `true`.
[#1613](https://github.com/rust-lang/mdBook/pull/1613)
## mdBook 0.4.10
[2f7293a...dc2062a](https://github.com/rust-lang/mdBook/compare/2f7293a...dc2062a)
### Changed
- Reverted breaking change in 0.4.9 that removed the `__non_exhaustive` marker
on the `Book` struct.
[#1572](https://github.com/rust-lang/mdBook/pull/1572)
- Updated handlebars to 4.0.
[#1550](https://github.com/rust-lang/mdBook/pull/1550)
- Removed the `chapter_begin` id on the print page's chapter separators.
[#1541](https://github.com/rust-lang/mdBook/pull/1541)
## mdBook 0.4.9
[7e01cf9...d325c60](https://github.com/rust-lang/mdBook/compare/7e01cf9...d325c60)
### Changed
- Updated all dependencies and raised the minimum Rust version to 1.42.
[#1528](https://github.com/rust-lang/mdBook/pull/1528)
- Added more detail to error message when a preprocessor fails.
[#1526](https://github.com/rust-lang/mdBook/pull/1526)
- Set max-width of HTML video tags to 100% to match img tags.
[#1542](https://github.com/rust-lang/mdBook/pull/1542)
### Fixed
- Type errors when parsing `book.toml` are no longer ignored.
[#1539](https://github.com/rust-lang/mdBook/pull/1539)
- Better handling if `mdbook serve` fails to start the http server.
[#1555](https://github.com/rust-lang/mdBook/pull/1555)
- Fixed the path for `edit-url-template` if the book used a source directory
other than `src`.
[#1554](https://github.com/rust-lang/mdBook/pull/1554)
## mdBook 0.4.8
[fcceee4...b592b10](https://github.com/rust-lang/mdBook/compare/fcceee4...b592b10)
### Added
- Added the option `output.html.edit-url-template` which can be a URL which is
linked on each page to direct the user to a site (such as GitHub) where the
user can directly suggest an edit for the page they are currently reading.
[#1506](https://github.com/rust-lang/mdBook/pull/1506)
### Changed
- Printed output now includes a page break between chapters.
[#1485](https://github.com/rust-lang/mdBook/pull/1485)
### Fixed
- HTML, such as HTML comments, is now ignored if it appears above the title line
in `SUMMARY.md`.
[#1437](https://github.com/rust-lang/mdBook/pull/1437)
## mdBook 0.4.7
[9a9eb01...c83bbd6](https://github.com/rust-lang/mdBook/compare/9a9eb01...c83bbd6)
### Changed
- Updated shlex parser to fix a minor parsing issue (used by the
preprocessor/backend custom command config).
[#1471](https://github.com/rust-lang/mdBook/pull/1471)
- Enhanced text contrast of `light` theme to improve accessibility.
[#1470](https://github.com/rust-lang/mdBook/pull/1470)
### Fixed
- Fixed some issues with fragment scrolling and linking.
[#1463](https://github.com/rust-lang/mdBook/pull/1463)
## mdBook 0.4.6
[eaa6914...1a0c296](https://github.com/rust-lang/mdBook/compare/eaa6914...1a0c296)
### Changed
- The chapter name is now included in the search breadcrumbs.
[#1389](https://github.com/rust-lang/mdBook/pull/1389)
- Pressing Escape will remove the `?highlight` argument from the URL.
[#1427](https://github.com/rust-lang/mdBook/pull/1427)
- `mdbook init --theme` will now place the theme in the root of the book
directory instead of in the `src` directory.
[#1432](https://github.com/rust-lang/mdBook/pull/1432)
- A custom renderer that sets the `command` to a relative path now interprets
the relative path relative to the book root. Previously it was inconsistent
based on the platform (either relative to the current directory, or relative
to the renderer output directory). Paths relative to the output directory
are still supported with a deprecation warning.
[#1418](https://github.com/rust-lang/mdBook/pull/1418)
- The `theme` directory in the config is now interpreted as relative to the
book root, instead of the current directory.
[#1405](https://github.com/rust-lang/mdBook/pull/1405)
- Handle UTF-8 BOM for chapter sources.
[#1285](https://github.com/rust-lang/mdBook/pull/1285)
- Removed extra whitespace added to `{{#playground}}` snippets.
[#1375](https://github.com/rust-lang/mdBook/pull/1375)
### Fixed
- Clicking on a search result with multiple search words will now correctly
highlight all of the words.
[#1426](https://github.com/rust-lang/mdBook/pull/1426)
- Properly handle `<` and `>` characters in the table of contents.
[#1376](https://github.com/rust-lang/mdBook/pull/1376)
- Fixed to properly serialize the `build` table in the config, which prevented
setting it in the API.
[#1378](https://github.com/rust-lang/mdBook/pull/1378)
## mdBook 0.4.5
[eaa6914...f66df09](https://github.com/rust-lang/mdBook/compare/eaa6914...f66df09)
### Fixed
- Fixed XSS in the search page.
[CVE-2020-26297](https://groups.google.com/g/rustlang-security-announcements/c/3-sO6of29O0)
[648c9ae](https://github.com/rust-lang/mdBook/commit/648c9ae772bec83f0a5954d17b4287d5bb1d6606)
## mdBook 0.4.4
[4df9ec9...01836ba](https://github.com/rust-lang/mdBook/compare/4df9ec9...01836ba)
### Added
- Added the `output.html.print.enable` configuration value to disable the
"print" page.
[#1169](https://github.com/rust-lang/mdBook/pull/1169)
- Added a list of supported languages for syntax-highlighting to the
documentation.
[#1345](https://github.com/rust-lang/mdBook/pull/1345)
### Fixed
- Now supports symbolic links for files in the `src` directory.
[#1323](https://github.com/rust-lang/mdBook/pull/1323)
## mdBook 0.4.3
[9278b83...4df9ec9](https://github.com/rust-lang/mdBook/compare/9278b83...4df9ec9)
### Added
- Added `output.html.cname` option to emit a `CNAME` file which is used by
GitHub Pages to know which domain is being used.
[#1311](https://github.com/rust-lang/mdBook/pull/1311)
### Changed
- `mdbook test` no longer stops on the first test failure, but instead will
run all the tests.
[#1313](https://github.com/rust-lang/mdBook/pull/1313)
- Removed the `local` font source for Source Code Pro, as the locally
installed font may not render properly on FireFox on macOS.
[#1307](https://github.com/rust-lang/mdBook/pull/1307)
### Fixed
- Added newline to end of `.nojekyll` file.
[#1310](https://github.com/rust-lang/mdBook/pull/1310)
- Fixed missing space before draft chapter titles.
[#1309](https://github.com/rust-lang/mdBook/pull/1309)
## mdBook 0.4.2
[649f355...9278b83](https://github.com/rust-lang/mdBook/compare/649f355...9278b83)
### Changed
- The "show hidden lines" icon has changed from the "expand" icon to an "eye".
[#1281](https://github.com/rust-lang/mdBook/pull/1281)
- Updated highlight.js. This adds several languages: c, c-like (effectively
cpp), csharp (replaces cs), kotlin, less, lua, php-template, plaintext,
python-repl, r, scss, typescript.
[#1277](https://github.com/rust-lang/mdBook/pull/1277)
### Fixed
- Fixed SUMMARY links that contained newlines.
[#1291](https://github.com/rust-lang/mdBook/pull/1291)
- Fixed SUMMARY links that contain `%20` spaces.
[#1293](https://github.com/rust-lang/mdBook/pull/1293)
- Fixed favicon so that if only the png or svg is overridden, the other is not
automatically included in the `<link>` tag.
[#1272](https://github.com/rust-lang/mdBook/pull/1272)
## mdBook 0.4.1
[d4df7e7...649f355](https://github.com/rust-lang/mdBook/compare/d4df7e7...649f355)
### Changed
- Removed several outdated dev-dependencies.
[#1267](https://github.com/rust-lang/mdBook/pull/1267)
### Fixed
- Fixed sidebar scrolling if the book includes part titles.
[#1265](https://github.com/rust-lang/mdBook/pull/1265)
- Don't include the default favicon if only one of the PNG or SVG is overridden.
[#1266](https://github.com/rust-lang/mdBook/pull/1266)
## mdBook 0.4.0
[99ecd4f...d4df7e7](https://github.com/rust-lang/mdBook/compare/99ecd4f...d4df7e7)
### Breaking Changes
- Several of the changes in the release have altered the public API of the
mdbook library.
- Many dependencies have been updated or replaced.
This also removes the `--websocket-hostname` and `--websocket-port` from
the `serve` command.
[#1211](https://github.com/rust-lang/mdBook/pull/1211)
- A new "404" page is now automatically rendered. This requires knowledge of
the base URL of your site to work properly. If you decide to use this as
your 404 page, you should set the `site-url` setting in the book
configuration so mdbook can generate the links correctly. Alternatively you
can disable the 404 page generation, or set up your own 404 handling in your
web server.
[#1221](https://github.com/rust-lang/mdBook/pull/1221)
- The `debug` and `output` features have been removed as they were unused.
[#1211](https://github.com/rust-lang/mdBook/pull/1211)
- If you are using customized themes, you may want to consider setting the
`preferred-dark-theme` config setting, as it now defaults to "navy".
[#1199](https://github.com/rust-lang/mdBook/pull/1199)
- "Playpen" has been renamed to "playground". This is generally backwards
compatible for users, but `{{#playpen}}` will now display warnings. This may
impact books that have modified the "playpen" elements in the theme.
[#1241](https://github.com/rust-lang/mdBook/pull/1241)
- If a renderer is not installed, it is now treated as an error. If you want
the old behavior of ignoring missing renderers, set the `optional` setting
for that renderer.
[#1122](https://github.com/rust-lang/mdBook/pull/1122)
- If you have a custom favicon, you may need to look into adding an SVG
version, otherwise the default SVG icon will be displayed.
[#1230](https://github.com/rust-lang/mdBook/pull/1230)
### Added
- Added a new `[rust]` configuration section to `book.toml`, which allows
setting the default edition with `edition = "2018"`.
[#1163](https://github.com/rust-lang/mdBook/pull/1163)
- Renderers can now be marked as `optional`, so that they will be ignored if
the renderer is not installed.
[#1122](https://github.com/rust-lang/mdBook/pull/1122)
- Added `head.hbs` to allow adding content to the `<head>` section in HTML.
[#1206](https://github.com/rust-lang/mdBook/pull/1206)
- Added "draft chapters". These are chapters listed without a link to indicate
content yet to be written.
[#1153](https://github.com/rust-lang/mdBook/pull/1153)
- Added "parts" to split a book into different sections. Headers can be added
to `SUMMARY.md` to signify different sections.
[#1171](https://github.com/rust-lang/mdBook/pull/1171)
- Added generation of a "404" page for handling missing pages and broken links.
[#1221](https://github.com/rust-lang/mdBook/pull/1221)
- Added configuration section for specifying URL redirects.
[#1237](https://github.com/rust-lang/mdBook/pull/1237)
- Added an SVG favicon that works with light and dark colors schemes.
[#1230](https://github.com/rust-lang/mdBook/pull/1230)
### Changed
- Changed default Rust attribute of `allow(unused_variables)` to `allow(unused)`.
[#1195](https://github.com/rust-lang/mdBook/pull/1195)
- Fonts are now served locally instead of from the Google Fonts CDN. The
`copy-fonts` option was added to disable this if you want to supply your own
fonts.
[#1188](https://github.com/rust-lang/mdBook/pull/1188)
- Switched the built-in webserver for the `serve` command to a new
implementation. This results in some internal differences in how websockets
are handled, which removes the separate websocket options. This should also
make it easier to serve multiple books at once.
[#1211](https://github.com/rust-lang/mdBook/pull/1211)
- The default dark theme is now "navy".
[#1199](https://github.com/rust-lang/mdBook/pull/1199)
- "Playpen" has been renamed to "playground", matching the actual name of the
service which was renamed many years ago.
[#1241](https://github.com/rust-lang/mdBook/pull/1241)
### Fixed
- Links with the `+` symbol should now work.
[#1208](https://github.com/rust-lang/mdBook/pull/1208)
- The `MDBOOK_BOOK` environment variable now correctly allows overriding the
entire book configuration.
[#1207](https://github.com/rust-lang/mdBook/pull/1207)
- The sidebar can no longer be dragged outside of the window.
[#1229](https://github.com/rust-lang/mdBook/pull/1229)
- Hide the Rust Playground "play" button for `no_run` code samples.
[#1249](https://github.com/rust-lang/mdBook/pull/1249)
- Fixed the `--dest-dir` command-line option for the `serve` and `watch`
commands.
[#1228](https://github.com/rust-lang/mdBook/pull/1228)
- Hotkey handlers are now disabled in `text` input fields (for example, typing
`S` in a custom text input field).
[#1244](https://github.com/rust-lang/mdBook/pull/1244)
## mdBook 0.3.7
[88684d8...99ecd4f](https://github.com/rust-lang/mdBook/compare/88684d8...99ecd4f)
### Changed
- Code spans in headers are no longer highlighted as code.
[#1162](https://github.com/rust-lang/mdBook/pull/1162)
- The sidebar will now scroll the activate page to the middle instead of the top.
[#1161](https://github.com/rust-lang/mdBook/pull/1161)
- Reverted change to reject build output within the `src` directory, and
instead add a check that prevents infinite copies.
[#1181](https://github.com/rust-lang/mdBook/pull/1181)
[#1026](https://github.com/rust-lang/mdBook/pull/1026)
### Fixed
- Fixed sidebar line-height jumping for collapsed chapters.
[#1182](https://github.com/rust-lang/mdBook/pull/1182)
- Fixed theme selector focus.
[#1170](https://github.com/rust-lang/mdBook/pull/1170)
## mdBook 0.3.6
[efdb832...88684d8](https://github.com/rust-lang/mdBook/compare/efdb832...88684d8)
### Added
- `MDBook::execute_build_process` is now publicly accessible in the API so
that plugins can more easily initiate the build process.
[#1099](https://github.com/rust-lang/mdBook/pull/1099)
### Changed
- Use a different color for Ayu theme's highlighting for Rust attributes (uses
a bright color instead of the comment color).
[#1133](https://github.com/rust-lang/mdBook/pull/1133)
- Adjusted spacing of sidebar entries.
[#1137](https://github.com/rust-lang/mdBook/pull/1137)
- Slightly adjusted line-height of `<p>`, `<ul>`, and `<ol>`.
[#1136](https://github.com/rust-lang/mdBook/pull/1136)
- Handlebars updated to 3.0.
[#1130](https://github.com/rust-lang/mdBook/pull/1130)
### Fixed
- Fix an issue with sidebar scroll position on reload.
[#1108](https://github.com/rust-lang/mdBook/pull/1108)
- `mdbook serve` will retain the current scroll position when the page is reloaded.
[#1097](https://github.com/rust-lang/mdBook/pull/1097)
- Fixed the page name if the book didn't have a title to not be prefixed with ` - `.
[#1145](https://github.com/rust-lang/mdBook/pull/1145)
- HTML attributes `rel=next` and `rel=previous` are now supported in "wide"
mode (previously they were only set in narrow mode).
[#1150](https://github.com/rust-lang/mdBook/pull/1150)
- Prevent recursive copies when the destination directory is contained in the
source directory.
[#1135](https://github.com/rust-lang/mdBook/pull/1135)
- Adjusted the menu bar animation to not immediately obscure the top content.
[#989](https://github.com/rust-lang/mdBook/pull/989)
- Fix for comments in SUMMARY.md that appear between items.
[#1167](https://github.com/rust-lang/mdBook/pull/1167)
## mdBook 0.3.5
[6e0d0fa...efdb832](https://github.com/rust-lang/mdBook/compare/6e0d0fa...efdb832)
### Changed
- The `default-theme` config setting is now case-insensitive.
[#1079](https://github.com/rust-lang/mdBook/pull/1079)
### Fixed
- Fixed `#` hidden Rust code lines not rendering properly.
[#1088](https://github.com/rust-lang/mdBook/pull/1088)
- Updated pulldown-cmark to 0.6.1, fixing several issues.
[#1021](https://github.com/rust-lang/mdBook/pull/1021)
## mdBook 0.3.4
[e5f77aa...6e0d0fa](https://github.com/rust-lang/mdBook/compare/e5f77aa...6e0d0fa)
### Changed
- Switch to relative `rem` font sizes from `px`.
[#894](https://github.com/rust-lang/mdBook/pull/894)
- Migrated repository to https://github.com/rust-lang/mdBook/
[#1083](https://github.com/rust-lang/mdBook/pull/1083)
## mdBook 0.3.3
[2b649fe...e5f77aa](https://github.com/rust-lang/mdBook/compare/2b649fe...e5f77aa)
### Changed
- Improvements to the automatic dark theme selection.
[#1069](https://github.com/rust-lang/mdBook/pull/1069)
- Fragment links now prevent scrolling the header behind the menu bar.
[#1077](https://github.com/rust-lang/mdBook/pull/1077)
### Fixed
- Fixed error when building a book that has a spacer immediately after the
first chapter.
[#1075](https://github.com/rust-lang/mdBook/pull/1075)
## mdBook 0.3.2
[9cd47eb...2b649fe](https://github.com/rust-lang/mdBook/compare/9cd47eb...2b649fe)
### Added
- Added a markdown renderer, which is off by default. This may be useful for
debugging preprocessors.
[#1018](https://github.com/rust-lang/mdBook/pull/1018)
- Code samples may now include line numbers with the
`output.html.playpen.line-numbers` configuration value.
[#1035](https://github.com/rust-lang/mdBook/pull/1035)
- The `watch` and `serve` commands will now ignore files listed in
`.gitignore`.
[#1044](https://github.com/rust-lang/mdBook/pull/1044)
- Added automatic dark-theme detection based on the CSS `prefers-color-scheme`
feature. This may be enabled by setting `output.html.preferred-dark-theme`
to your preferred dark theme.
[#1037](https://github.com/rust-lang/mdBook/pull/1037)
- Added `rustdoc_include` preprocessor. This makes it easier to include
portions of an external Rust source file. The rest of the file is hidden,
but the user may expand it to see the entire file, and will continue to work
with `mdbook test`.
[#1003](https://github.com/rust-lang/mdBook/pull/1003)
- Added Ctrl-Enter shortcut to the playpen editor to automatically run the
sample.
[#1066](https://github.com/rust-lang/mdBook/pull/1066)
- Added `output.html.playpen.copyable` configuration option to disable
the copy button.
[#1050](https://github.com/rust-lang/mdBook/pull/1050)
- Added ability to dynamically expand and fold sections within the sidebar.
See the `output.html.fold` configuration to enable this feature.
[#1027](https://github.com/rust-lang/mdBook/pull/1027)
### Changed
- Use standard `scrollbar-color` CSS along with webkit extension
[#816](https://github.com/rust-lang/mdBook/pull/816)
- The renderer build directory is no longer deleted before the renderer is
run. This allows a backend to cache results between runs.
[#985](https://github.com/rust-lang/mdBook/pull/985)
- Next/prev links now highlight on hover to indicate it is clickable.
[#994](https://github.com/rust-lang/mdBook/pull/994)
- Increase padding of table headers.
[#824](https://github.com/rust-lang/mdBook/pull/824)
- Errors in `[output.html]` config are no longer ignored.
[#1033](https://github.com/rust-lang/mdBook/pull/1033)
- Updated highlight.js for syntax highlighting updates (primarily to add
async/await to Rust highlighting).
[#1041](https://github.com/rust-lang/mdBook/pull/1041)
- Raised minimum supported rust version to 1.35.
[#1003](https://github.com/rust-lang/mdBook/pull/1003)
- Hidden code lines are no longer dynamically removed via JavaScript, but
instead managed with CSS.
[#846](https://github.com/rust-lang/mdBook/pull/846)
[#1065](https://github.com/rust-lang/mdBook/pull/1065)
- Changed the default font set for the ACE editor, giving preference to
"Source Code Pro".
[#1062](https://github.com/rust-lang/mdBook/pull/1062)
- Windows 32-bit releases are no longer published.
[#1071](https://github.com/rust-lang/mdBook/pull/1071)
### Fixed
- Fixed sidebar auto-scrolling.
[#1052](https://github.com/rust-lang/mdBook/pull/1052)
- Fixed error message when running `clean` multiple times.
[#1055](https://github.com/rust-lang/mdBook/pull/1055)
- Actually fix the "next" link on index.html. The previous fix didn't work.
[#1005](https://github.com/rust-lang/mdBook/pull/1005)
- Stop using `inline-block` for `inline code`, fixing selection highlighting
and some rendering issues.
[#1058](https://github.com/rust-lang/mdBook/pull/1058)
- Fix header auto-hide on browsers with momentum scrolling that allows
negative `scrollTop`.
[#1070](https://github.com/rust-lang/mdBook/pull/1070)
## mdBook 0.3.1
[69a08ef...9cd47eb](https://github.com/rust-lang/mdBook/compare/69a08ef...9cd47eb)
### Added
- 🔥 Added ability to include files using anchor points instead of line numbers.
[#851](https://github.com/rust-lang/mdBook/pull/851)
- Added `language` configuration value to set the language of the book, which
will affect things like the `<html lang="en">` tag.
[#941](https://github.com/rust-lang/mdBook/pull/941)
### Changed
- Updated to handlebars 2.0.
[#977](https://github.com/rust-lang/mdBook/pull/977)
### Fixed
- Fixed memory leak warning.
[#967](https://github.com/rust-lang/mdBook/pull/967)
- Fix more print.html links.
[#963](https://github.com/rust-lang/mdBook/pull/963)
- Fixed crash on some unicode input.
[#978](https://github.com/rust-lang/mdBook/pull/978)
## mdBook 0.3.0
[6cbc41d...69a08ef](https://github.com/rust-lang/mdBook/compare/6cbc41d...69a08ef)
### Added
- Added ability to resize the sidebar.
[#849](https://github.com/rust-lang/mdBook/pull/849)
- Added `load_with_config_and_summary` function to `MDBook` to be able to
build a book with a custom `Summary`.
[#883](https://github.com/rust-lang/mdBook/pull/883)
- Set `noindex` on `print.html` page to prevent robots from indexing it.
[#844](https://github.com/rust-lang/mdBook/pull/844)
- Added support for ~~strikethrough~~ and GitHub-style tasklists.
[#952](https://github.com/rust-lang/mdBook/pull/952)
### Changed
- Command-line help output is now colored.
[#861](https://github.com/rust-lang/mdBook/pull/861)
- The build directory is now deleted before rendering starts, instead of after
if finishes.
[#878](https://github.com/rust-lang/mdBook/pull/878)
- Removed dependency on `same-file` crate.
[#903](https://github.com/rust-lang/mdBook/pull/903)
- 💥 Renamed `with_preprecessor` to `with_preprocessor`.
[#906](https://github.com/rust-lang/mdBook/pull/906)
- Updated ACE editor to 1.4.4, should remove a JavaScript console warning.
[#935](https://github.com/rust-lang/mdBook/pull/935)
- Dependencies have been updated.
[#934](https://github.com/rust-lang/mdBook/pull/934)
[#945](https://github.com/rust-lang/mdBook/pull/945)
- Highlight.js has been updated. This fixes some TOML highlighting, and adds
Julia support.
[#942](https://github.com/rust-lang/mdBook/pull/942)
- 🔥 Updated to pulldown-cmark 0.5. This may have significant changes to the
formatting of existing books, as the newer version has more accurate
interpretation of the CommonMark spec and a large number of bug fixes and
changes.
[#898](https://github.com/rust-lang/mdBook/pull/898)
- The `diff` language should now highlight correctly.
[#943](https://github.com/rust-lang/mdBook/pull/943)
- Make the blank region of a header not clickable.
[#948](https://github.com/rust-lang/mdBook/pull/948)
- Rustdoc tests now use the preprocessed content instead of the raw,
unpreprocessed content.
[#891](https://github.com/rust-lang/mdBook/pull/891)
### Fixed
- Fixed file change detection so that `mdbook serve` only reloads once when
multiple files are changed at once.
[#870](https://github.com/rust-lang/mdBook/pull/870)
- Fixed on-hover color highlighting for links in sidebar.
[#834](https://github.com/rust-lang/mdBook/pull/834)
- Fixed loss of focus when clicking the "Copy" button in code blocks.
[#867](https://github.com/rust-lang/mdBook/pull/867)
- Fixed incorrectly stripping the path for `additional-js` files.
[#796](https://github.com/rust-lang/mdBook/pull/796)
- Fixed color of `code spans` that are links.
[#905](https://github.com/rust-lang/mdBook/pull/905)
- Fixed "next" navigation on index.html.
[#916](https://github.com/rust-lang/mdBook/pull/916)
- Fixed keyboard chapter navigation for `file` urls.
[#915](https://github.com/rust-lang/mdBook/pull/915)
- Fixed bad wrapping for inline code on some browsers.
[#818](https://github.com/rust-lang/mdBook/pull/818)
- Properly load an existing `SUMMARY.md` in `mdbook init`.
[#841](https://github.com/rust-lang/mdBook/pull/841)
- Fixed some broken links in `print.html`.
[#871](https://github.com/rust-lang/mdBook/pull/871)
- The Rust Playground link now supports the 2018 edition.
[#946](https://github.com/rust-lang/mdBook/pull/946)
## mdBook 0.2.3 (2018-01-18)
[2c20c99...6cbc41d](https://github.com/rust-lang/mdBook/compare/2c20c99...6cbc41d)
### Added
- Added an optional button to the top of the page which will link to a git
repository. Use the `git-repository-url` and `git-repository-icon` options
in the `[output.html]` section to enable it and set its appearance.
[#802](https://github.com/rust-lang/mdBook/pull/802)
- Added a `default-theme` option to the `[output.html]` section.
[#804](https://github.com/rust-lang/mdBook/pull/804)
### Changed
- 💥 Header ID anchors no longer add an arbitrary `a` character for headers
that start with a non-ascii-alphabetic character.
[#788](https://github.com/rust-lang/mdBook/pull/788)
### Fixed
- Fix websocket hostname usage
[#865](https://github.com/rust-lang/mdBook/pull/865)
- Fixing links in print.html
[#866](https://github.com/rust-lang/mdBook/pull/866)
## mdBook 0.2.2 (2018-10-19)
[7e2e095...2c20c99](https://github.com/rust-lang/mdBook/compare/7e2e095...2c20c99)
### Added
- 🎉 Process-based custom preprocessors. See [the
docs](https://rust-lang.github.io/mdBook/for_developers/preprocessors.html)
for more.
[#792](https://github.com/rust-lang/mdBook/pull/792)
- 🎉 Configurable preprocessors.
Added `build.use-default-preprocessors` boolean TOML key to allow disabling
the built-in `links` and `index` preprocessors.
Added `[preprocessor]` TOML tables to configure each preprocessor.
Specifying `[preprocessor.links]` or `[preprocessor.index]` will enable the
respective built-in preprocessor if `build.use-default-preprocessors` is
`false`.
Added `fn supports_renderer(&self, renderer: &str) -> bool` to the
`Preprocessor` trait to specify if the preprocessor supports the given
renderer. The default implementation always returns `true`.
`Preprocessor::run` now takes a book by value instead of a mutable
reference. It should return a `Book` value with the intended modifications.
Added `PreprocessorContext::renderer` to indicate the renderer being used.
[#658](https://github.com/rust-lang/mdBook/pull/658)
[#787](https://github.com/rust-lang/mdBook/pull/787)
### Fixed
- Fix paths to additional CSS and JavaScript files
[#777](https://github.com/rust-lang/mdBook/pull/777)
- Ensure section numbers are correctly incremented after a horizontal
separator
[#790](https://github.com/rust-lang/mdBook/pull/790)
## mdBook 0.2.1 (2018-08-22)
[91ffca1...7e2e095](https://github.com/rust-lang/mdBook/compare/91ffca1...7e2e095)
### Changed
- Update to handlebars-rs 1.0
[#761](https://github.com/rust-lang/mdBook/pull/761)
### Fixed
- Fix table colors, broken by Stylus -> CSS transition
[#765](https://github.com/rust-lang/mdBook/pull/765)
## mdBook 0.2.0 (2018-08-02)
### Changed
- 💥 This release changes how links are handled in mdBook. Previously, relative
links were interpreted relative to the book's root. In `0.2.0`+ links are
relative to the page they are in, and use the `.md` extension. This has [several
advantages](https://github.com/rust-lang/mdBook/pull/603#issue-166701447),
such as making links work in other markdown viewers like GitHub. You will
likely have to change links in your book to accommodate this change. For
example, a book with this layout:
```
chapter_1/
section_1.md
section_2.md
SUMMARY.md
```
Previously a link in `section_1.md` to `section_2.md` would look like this:
```markdown
[section_2](chapter_1/section_2.html)
```
Now it must be changed to this:
```markdown
[section_2](section_2.md)
```
- 💥 `mdbook test --library-path` now accepts a comma-delimited list of
arguments rather than taking all following arguments. This makes it easier
to handle the trailing book directory argument without always needing to put
` -- ` before it. Multiple instances of the option continue to be accepted:
`mdbook test -L foo -L bar`.
- 💥 `mdbook serve` has some of its options renamed for clarity. See `mdbook
help serve` for details.
- Embedded rust playpens now use the "stable" playground API.
[#754](https://github.com/rust-lang/mdBook/pull/754)
### Fixed
- Escaped includes (`\{{#include file.rs}}`) will now render correctly.
[f30ce01](https://github.com/rust-lang/mdBook/commit/f30ce0184d71e342141145472bf816419d30a2c5)
- `index.html` will now render correctly when the book's first section is
inside a subdirectory.
[#756](https://github.com/rust-lang/mdBook/pull/756)

3
CODE_OF_CONDUCT.md Normal file
View File

@@ -0,0 +1,3 @@
# The Rust Code of Conduct
The Code of Conduct for this repository [can be found online](https://www.rust-lang.org/conduct.html).

155
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,155 @@
# Contributing
Welcome stranger!
If you have come here to learn how to contribute to mdBook, we have some tips for you!
First of all, don't hesitate to ask questions!
Use the [issue tracker](https://github.com/rust-lang/mdBook/issues), no question is too simple.
### Issue assignment
**:warning: Important :warning:**
Before working on pull request, please ping us on the corresponding issue.
The current PR backlog is beyond what we can process at this time.
Only issues that have an [`E-Help-wanted`](https://github.com/rust-lang/mdBook/labels/E-Help-wanted) or [`Feature accepted`](https://github.com/rust-lang/mdBook/labels/Feature%20accepted) label will likely receive reviews.
If there isn't already an open issue for what you want to work on, please open one first to see if it is something we would be available to review.
### Issues to work on
If you are starting out, you might be interested in the
[E-Easy issues](https://github.com/rust-lang/mdBook/issues?q=is%3Aopen+is%3Aissue+label%3AE-Easy).
Those are issues that are considered more straightforward for beginners to Rust or the codebase itself.
These issues can be a good launching pad for more involved issues.
Easy tasks for a first time contribution include documentation improvements, new tests, examples, updating dependencies, etc.
If you come from a web development background, you might be interested in issues related to web technologies tagged
[A-JavaScript](https://github.com/rust-lang/mdBook/issues?q=is%3Aopen+is%3Aissue+label%3AA-JavaScript),
[A-Style](https://github.com/rust-lang/mdBook/issues?q=is%3Aopen+is%3Aissue+label%3AA-Style),
[A-HTML](https://github.com/rust-lang/mdBook/issues?q=is%3Aopen+is%3Aissue+label%3AA-HTML) or
[A-Mobile](https://github.com/rust-lang/mdBook/issues?q=is%3Aopen+is%3Aissue+label%3AA-Mobile).
When you decide you want to work on a specific issue, and it isn't already assigned to someone else, assign the issue to yourself by leaving a comment with the text `@rustbot claim`.
Again, do not hesitate to ask questions. We will gladly mentor anyone that want to tackle an issue.
Issues on the issue tracker are categorized with the following labels:
- **A**-prefixed labels state which area of the project an issue relates to.
- **E**-prefixed labels show an estimate of the experience necessary to fix the issue.
- **M**-prefixed labels are meta-issues regarding the management of the mdBook project itself
- **S**-prefixed labels show the status of the issue
- **C**-prefixed labels show the category of issue
### Building mdBook
mdBook builds on stable Rust, if you want to build mdBook from source, here are the steps to follow:
1. Navigate to the directory of your choice
0. Clone this repository with git.
```
git clone https://github.com/rust-lang/mdBook.git
```
0. Navigate into the newly created `mdBook` directory
0. Run `cargo build`
The resulting binary can be found in `mdBook/target/debug/` under the name `mdbook` or `mdbook.exe`.
### Code Quality
We love code quality and Rust has some excellent tools to assist you with contributions.
#### Formatting Code with rustfmt
Before you make your Pull Request to the project, please run it through the `rustfmt` utility.
This will ensure we have good quality source code that is better for us all to maintain.
[rustfmt](https://github.com/rust-lang/rustfmt) has a lot more information on the project.
The quick guide is
1. Install it (`rustfmt` is usually installed by default via [rustup](https://rustup.rs/)):
```
rustup component add rustfmt
```
1. You can now run `rustfmt` on a single file simply by...
```
rustfmt src/path/to/your/file.rs
```
... or you can format the entire project with
```
cargo fmt
```
When run through `cargo` it will format all bin and lib files in the current package.
For more information, such as running it from your favourite editor, please see the `rustfmt` project. [rustfmt](https://github.com/rust-lang/rustfmt)
#### Finding Issues with Clippy
[Clippy](https://doc.rust-lang.org/clippy/) is a code analyser/linter detecting mistakes, and therefore helps to improve your code.
Like formatting your code with `rustfmt`, running clippy regularly and before your Pull Request will help us maintain awesome code.
1. To install
```
rustup component add clippy
```
2. Running clippy
```
cargo clippy
```
### Change requirements
Please consider the following when making a change:
* Almost all changes that modify the Rust code must be accompanied with a test.
* Almost all features and changes must update the documentation.
mdBook has the [mdBook Guide](https://rust-lang.github.io/mdBook/) whose source is at <https://github.com/rust-lang/mdBook/tree/master/guide>.
* Almost all Rust items should be documented with doc comments.
See the [Rustdoc Book](https://doc.rust-lang.org/rustdoc/) for more information on writing doc comments.
* Breaking the API can only be done in major SemVer releases.
These are done very infrequently, so it is preferred to avoid these when possible.
See [SemVer Compatibility](https://doc.rust-lang.org/cargo/reference/semver.html) for more information on what a SemVer breaking change is.
(Note: At this time, some SemVer breaking changes are inevitable due to the current code structure.
An example is adding new fields to the config structures.
These are intended to be fixed in the next major release.)
* Similarly, the CLI interface is considered to be stable.
Care should be taken to avoid breaking existing workflows.
* Check out the [Rust API Guidelines](https://rust-lang.github.io/api-guidelines/) for guidelines on designing the API.
### Making a pull-request
When you feel comfortable that your changes could be integrated into mdBook, you can create a pull-request on GitHub.
One of the core maintainers will then approve the changes or request some changes before it gets merged.
That's it, happy contributions! :tada: :tada: :tada:
## Browser compatibility and testing
Currently we don't have a strict browser compatibility matrix due to our limited resources.
We generally strive to keep mdBook compatible with a relatively recent browser on all of the most major platforms.
That is, supporting Chrome, Safari, Firefox, Edge on Windows, macOS, Linux, iOS, and Android.
If possible, do your best to avoid breaking older browser releases.
Any change to the HTML or styling is encouraged to manually check on as many browsers and platforms that you can.
Unfortunately at this time we don't have any automated UI or browser testing, so your assistance in testing is appreciated.
## Updating highlight.js
The following are instructions for updating [highlight.js](https://highlightjs.org/).
1. Clone the repository at <https://github.com/highlightjs/highlight.js>
1. Check out a tagged release (like `10.1.1`).
1. Run `npm install`
1. Run `node tools/build.js :common apache armasm coffeescript d handlebars haskell http julia nginx properties r scala x86asm yaml`
1. Compare the language list that it spits out to the one in [`syntax-highlighting.md`](https://github.com/camelid/mdBook/blob/master/guide/src/format/theme/syntax-highlighting.md). If any are missing, add them to the list and rebuild (and update these docs). If any are added to the common set, add them to `syntax-highlighting.md`.
1. Copy `build/highlight.min.js` to mdbook's directory [`highlight.js`](https://github.com/rust-lang/mdBook/blob/master/src/theme/highlight.js).
1. Be sure to check the highlight.js [CHANGES](https://github.com/highlightjs/highlight.js/blob/main/CHANGES.md) for any breaking changes. Breaking changes that would affect users will need to wait until the next major release.
1. Build mdbook with the new file and build some books with the new version and compare the output with a variety of languages to see if anything changes. The [test_book](https://github.com/rust-lang/mdBook/tree/master/test_book) contains a chapter with many languages to examine.

2146
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,44 +1,73 @@
[package]
name = "mdbook"
version = "0.0.8"
authors = ["Mathieu David <mathieudavid@mathieudavid.org>"]
description = "create books from markdown files (like Gitbook)"
documentation = "http://azerupi.github.io/mdBook/index.html"
repository = "https://github.com/azerupi/mdBook"
version = "0.4.26"
authors = [
"Mathieu David <mathieudavid@mathieudavid.org>",
"Michael-F-Bryan <michaelfbryan@gmail.com>",
"Matt Ickstadt <mattico8@gmail.com>"
]
documentation = "https://rust-lang.github.io/mdBook/index.html"
edition = "2021"
exclude = ["/guide/*"]
keywords = ["book", "gitbook", "rustbook", "markdown"]
license = "MPL-2.0"
readme = "README.md"
build = "build.rs"
exclude = [
"book-example/*",
"src/theme/stylus",
]
repository = "https://github.com/rust-lang/mdBook"
description = "Creates a book from markdown files"
rust-version = "1.60"
[dependencies]
clap = "~1.5.3"
handlebars = "~0.12.0"
rustc-serialize = "~0.3.16"
pulldown-cmark = "~0.0.6"
anyhow = "1.0.28"
chrono = { version = "0.4", default-features = false, features = ["clock"] }
clap = { version = "4.0.29", features = ["cargo", "wrap_help"] }
clap_complete = "4.0.6"
once_cell = "1"
env_logger = "0.10.0"
handlebars = "4.0"
log = "0.4"
memchr = "2.0"
opener = "0.5"
pulldown-cmark = { version = "0.9.1", default-features = false }
regex = "1.5.5"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
shlex = "1"
tempfile = "3.0"
toml = "0.7.2"
topological-sort = "0.2.2"
# Watch feature
notify = { version = "~2.4.1", optional = true }
time = { version = "~0.1.33", optional = true }
crossbeam = { version = "~0.2.8", optional = true }
notify = { version = "5.0.0", optional = true }
notify-debouncer-mini = { version = "0.2.1", optional = true }
gitignore = { version = "1.0", optional = true }
# Serve feature
futures-util = { version = "0.3.4", optional = true }
tokio = { version = "1", features = ["macros", "rt-multi-thread"], optional = true }
warp = { version = "0.3.2", default-features = false, features = ["websocket"], optional = true }
# Search feature
elasticlunr-rs = { version = "3.0.0", optional = true }
ammonia = { version = "3", optional = true }
# Tests
[dev-dependencies]
tempdir = "~0.3.4"
assert_cmd = "2.0.7"
predicates = "2"
select = "0.6.0"
semver = "1.0"
pretty_assertions = "1.2.1"
walkdir = "2.0"
[features]
default = ["output", "watch"]
debug = []
output = []
regenerate-css = []
watch = ["notify", "time", "crossbeam"]
default = ["watch", "serve", "search"]
watch = ["notify", "notify-debouncer-mini", "gitignore"]
serve = ["futures-util", "tokio", "warp"]
search = ["elasticlunr-rs", "ammonia"]
[[bin]]
doc = false
name = "mdbook"
path = "src/bin/mdbook.rs"
[[example]]
name = "nop-preprocessor"
test = true

View File

@@ -1,93 +1,20 @@
# mdBook [![Travis-CI](https://travis-ci.org/azerupi/mdBook.svg?branch=master)](https://travis-ci.org/azerupi/mdBook) [![Crates.io version](https://img.shields.io/crates/v/mdbook.svg)](https://crates.io/crates/mdbook) [![License](https://img.shields.io/crates/l/mdbook.svg)](LICENSE)
# mdBook
mdBook is a utility to create modern online books from markdown files.
[![Build Status](https://github.com/rust-lang/mdBook/workflows/CI/badge.svg?event=push)](https://github.com/rust-lang/mdBook/actions?workflow=CI)
[![crates.io](https://img.shields.io/crates/v/mdbook.svg)](https://crates.io/crates/mdbook)
[![LICENSE](https://img.shields.io/github/license/rust-lang/mdBook.svg)](LICENSE)
**This project is still in its early days.**
For more information about what is left on my to-do list, check the issue tracker
mdBook is a utility to create modern online books from Markdown files.
Check out the **[User Guide]** for a list of features and installation and usage information.
The User Guide also serves as a demonstration to showcase what a book looks like.
## What does it look like?
The [**Documentation**](http://azerupi.github.io/mdBook/) for mdBook has been written in markdown and is using mdBook to generate the online book-like website you can read. The documentation uses the latest version on github and showcases the available features.
## Installation
There are 2 ways to install mdBook but both require [Rust and Cargo](https://www.rust-lang.org/) to be installed.
##### Install from Crates.io
Once you have installed Rust, type the following in the terminal:
```
cargo install mdbook
```
This will download and compile mdBook for you, the only thing you that will be left to do is add the Cargo bin directory to your path.
##### Install from git
The version published to Crates.io will ever so slightly be behind the version hosted here on Github. If you need the latest version you can build the git version of mdBook yourself. Cargo makes this ***super easy***!
First, clone the repository on your computer:
```
git clone --depth 1 https://github.com/azerupi/mdBook.git
```
Then `cd` into the directory and run:
```
cargo build --release
```
The executable will be in `./target/release/mdbook`.
## Usage
mdBook will primaraly be used as a command line tool, even though it exposes all its functionality as a Rust crate for integration in other projects.
Here are the main commands you will want to run, for a more exhaustive explanation, check out the [documentation](http://azerupi.github.io/mdBook/).
- `mdbook init`
The init command will create a directory with the minimal boilerplate to start with.
```
book-test/
├── book
└── src
├── chapter_1.md
└── SUMMARY.md
```
`book` and `src` are both directories. `src` contains the markdown files that will be used to render the ouput to the `book` directory.
Please, take a look at the [**Documentation**](http://azerupi.github.io/mdBook/cli/init.html) for more information and some neat tricks.
- `mdbook build`
This is the command you will run to render your book, it reads the `SUMMARY.md` file to understand the structure of your book, takes the markdown files in the source directory as input and outputs static html pages that you can upload to a server.
- `mdbook watch`
When you run this command, mdbook will watch your markdown files to rebuild the book on every change. This avoids having to come back to the terminal to type `mdbook build` over and over again.
### As a library
Aside from the command line interface, this crate can also be used as a library. This means that you could integrate it in an existing project, like a web-app for example. Since the command line interface is just a wrapper around the library functionality, when you use this crate as a library you have full access to all the functionality of the command line interface with and easy to use API and more!
See the [Documentation](http://azerupi.github.io/mdBook/lib/lib.html) and the [API docs](http://azerupi.github.io/mdBook/mdbook/index.html) for more information.
## Contributions
Contributions are highly appreciated and encouraged! Don't hesitate to participate to discussions in the issues, propose new features and ask for help.
People who are not familiar with the code can look at [issues that are tagged **easy**](https://github.com/azerupi/mdBook/labels/Easy). A lot of issues are also related to web development, so people that are not comfortable with Rust can also participate! :wink:
You can pick any issue you want to work on. Usually it's a good idea to ask if someone is already working on it and if not to claim the issue.
If you are interested in contributing to the development of mdBook, check out the [Contribution Guide].
## License
All the code is released under the ***Mozilla Public License v2.0***, for more information take a look at the [LICENSE](LICENSE) file
All the code in this repository is released under the ***Mozilla Public License v2.0***, for more information take a look at the [LICENSE] file.
[User Guide]: https://rust-lang.github.io/mdBook/
[contribution guide]: https://github.com/rust-lang/mdBook/blob/master/CONTRIBUTING.md
[LICENSE]: https://github.com/rust-lang/mdBook/blob/master/LICENSE

View File

@@ -1,4 +0,0 @@
{
"title": "mdBook Documentation",
"author": "Mathieu David"
}

View File

@@ -1,16 +0,0 @@
# mdBook
**mdBook** is a command line tool and Rust crate to create books using Markdown files. It's very similar to Gitbook but written in [Rust](http://www.rust-lang.org).
What you are reading serves as an example of the output of mdBook and at the same time as high-level docs.
mdBook is free and open source, you can find the source code on [Github](https://github.com/azerupi/mdBook). Issues and feature requests can be posted on the [Github Issue tracker](https://github.com/azerupi/mdBook/issues).
## API docs
Alongside this book you can also read the [API docs](mdbook/index.html) generated by Rustdoc if you would like
to use mdBook as a crate or write a new renderer and need a more low-level overview.
## License
mdBook, all the source code, is released under the [Mozilla Public License v2.0](https://www.mozilla.org/MPL/2.0/)

View File

@@ -1,26 +0,0 @@
# The build command
The build command is used to render your book:
```bash
mdbook build
```
It will try to parse your `SUMMARY.md` file to understand the structure of your book
and fetch the corresponding files.
The rendered output will maintain the same directory structure as the source for
convenience. Large books will therefore remain structured when rendered.
#### Specify a directory
Like `init`, the `build` command can take a directory as argument to use instead of the
current working directory.
```bash
mdbook build path/to/book
```
-------------------
***note:*** *make sure to run the build command in the root directory and not in the source directory*

View File

@@ -1,35 +0,0 @@
# Command Line Tool
mdBook can be used either as a command line tool or a [Rust crate](https://crates.io/crates/mdbook).
Let's focus on the command line tool capabilities first.
## Install
### Pre-requisite
mdBook is written in **[Rust](https://www.rust-lang.org/)** and therefore needs to be compiled with **Cargo**, because we don't yet offer ready-to-go binaries. If you haven't already installed Rust, please go ahead and [install it](https://www.rust-lang.org/downloads.html) now.
### Install Crates.io version
Installing mdBook is relatively easy if you already have Rust and Cargo installed. You just have to type this snippet in your terminal:
```bash
cargo install mdbook
```
This will fetch the source code from [Crates.io](https://crates.io/) and compile it. You will have to add Cargo's `bin` directory to your `PATH`.
Run `mdbook help` in your terminal to verify if it works. Congratulations, you have installed mdBook!
### Install Git version
The **[git version](https://github.com/azerupi/mdBook)** contains all the latest bug-fixes and features, that will be released in the next version on **Crates.io**, if you can't wait until the next release. You can build the git version yourself. Open your terminal and navigate to the directory of you choice. We need to clone the git repository and then build it with Cargo.
```bash
git clone --depth=1 https://github.com/azerupi/mdBook.git
cd mdBook
cargo build --release
```
The executable `mdbook` will be in the `./target/release` folder, this should be added to the path.

View File

@@ -1,45 +0,0 @@
# The init command
There is some minimal boilerplate that is the same for every new book. It's for this purpose that mdBook includes an `init` command.
The `init` command is used like this:
```bash
mdbook init
```
When using the `init` command for the first time, a couple of files will be set up for you:
```bash
book-test/
├── book
└── src
├── chapter_1.md
└── SUMMARY.md
```
- The `src` directory is were you write your book in markdown. It contains all the source files,
configuration files, etc.
- The `book` directory is where your book is rendered. All the output is ready to be uploaded
to a server to be seen by your audience.
- The `SUMMARY.md` file is the most important file, it's the skeleton of your book and is discussed in more detail in another [chapter](../format/summary.html).
#### Tip & Trick: Hidden Feature
When a `SUMMARY.md` file already exists, the `init` command will first parse it and generate the missing files according to the paths used in the `SUMMARY.md`. This allows you to think and create the whole structure of your book and then let mdBook generate it for you.
#### Specify a directory
When using the `init` command, you can also specify a directory, instead of using the current working directory,
by appending a path to the command:
```bash
mdbook init path/to/book
```
## --theme
When you use the `--theme` argument, the default theme will be copied into a directory
called `theme` in your source directory so that you can modify it.
The theme is selectively overwritten, this means that if you don't want to overwrite a
specific file, just delete it and the default file will be used.

View File

@@ -1,19 +0,0 @@
# The test command
When writing a book, you sometimes need to automate some tests. For example, [The Rust Programming Book](https://doc.rust-lang.org/stable/book/) uses a lot of code examples that could get outdated.
Therefore it is very important for them to be able to automatically test these code examples.
mdBook supports a `test` command that will run all available tests in mdBook. At the moment, only one test is available:
*"Test Rust code examples using Rustdoc"*, but I hope this will be expanded in the future to include more tests like:
- checking for broken links
- checking for unused files
- ...
In the future I would like the user to be able to enable / disable test from the `book.json` configuration file and support custom tests.
**How to use it:**
```bash
$ mdbook test
[*]: Testing file: "/mdBook/book-example/src/README.md”
```

View File

@@ -1,18 +0,0 @@
# The watch command
The `watch` command is useful when you want your book to be rendered on every file change.
You could repeatedly issue `mdbook build` every time a file is changed. But using `mdbook watch` once will watch your files and will trigger a build automatically whenever you modify a file.
#### Specify a directory
Like `init` and `build`, `watch` can take a directory as argument to use instead of the
current working directory.
```bash
mdbook watch path/to/book
```
-----
***note:*** *the `watch` command has not gotten a lot of testing yet, there could be some rough edges. If you discover a problem, please report it [on Github](https://github.com/azerupi/mdBook/issues)*

View File

@@ -1,21 +0,0 @@
# Configuration
You can configure the parameters for your book in the ***book.json*** file.
Here is an example of what a ***book.json*** file might look like:
```json
{
"title": "Example book",
"author": "Name",
"dest": "output/my-book"
}
```
#### Supported variables
- **title:** title of the book
- **author:** author of the book
- **dest:** path to the directory where you want your book to be rendered. If a relative path is given it will be relative to the parent directory of the source directory
***note:*** *the supported configurable parameters are scarce at the moment, but more will be added in the future*

View File

@@ -1,21 +0,0 @@
# MathJax Support
mdBook supports math equations through [MathJax](https://www.mathjax.org/).
**However the normal method for indication math equations with `$$` does not work (yet?).**
To indicate an inline equation \\( \int x = \frac{x^2}{2} \\) use
```
\\( \int x = \frac{x^2}{2} \\)
```
To indicate a block equation
\\[ \mu = \frac{1}{N} \sum_{i=0} x_i \\]
use
```
\\[ \mu = \frac{1}{N} \sum_{i=0} x_i \\]
```

View File

@@ -1,42 +0,0 @@
# Rust code specific features
## Hiding code lines
There is a feature in mdBook that let's you hide code lines by prepending them with a `#`.
```bash
#fn main() {
let x = 5;
let y = 6;
println!("{}", x + y);
#}
```
Will render as
```rust
#fn main() {
let x = 5;
let y = 7;
println!("{}", x + y);
#}
```
## Inserting runnable Rust files
With the following syntax, you can insert runnable Rust files into your book:
```hbs
\{{#playpen file.rs}}
```
The path to the Rust file has to be relative from the current source file.
When play is clicked, the code snippet will be send to the [Rust Playpen]() to be compiled and run. The result is send back and displayed directly underneath the code.
Here is what a rendered code snippet looks like:
{{#playpen example.rs}}

View File

@@ -1,32 +0,0 @@
# SUMMARY.md
The summary file is used by mdBook to know what chapters to include,
in what order they should appear, what their hierarchy is and where the source files are.
Without this file, there is no book.
Even though `SUMMARY.md` is a markdown file, the formatting is very strict to
allow for easy parsing. Let's see how you should format your `SUMMARY.md` file.
#### Allowed elements
1. ***Title*** It's common practice to begin with a title, generally
<code class="language-markdown"># Summary</code>.
But it is not mandatory, the parser just ignores it. So you can too
if you feel like it.
2. ***Prefix Chapter*** Before the main numbered chapters you can add a couple of elements that will not be numbered. This is useful for
forewords, introductions, etc. There are however some constraints. You can not nest prefix chapters, they should all be on the root level. And you can not add prefix chapters once you have added numbered chapters.
```markdown
[Title of prefix element](relative/path/to/markdown.md)
```
3. ***Numbered Chapter*** Numbered chapters are the main content of the book, they will be numbered and can be nested,
resulting in a nice hierarchy (chapters, sub-chapters, etc.)
```markdown
- [Title of the Chapter](relative/path/to/markdown.md)
```
You can either use `-` or `*` to indicate a numbered chapter.
4. ***Sufix Chapter*** After the numbered chapters you can add a couple of non-numbered chapters. They are the same as prefix chapters but come after the numbered chapters instead of before.
All other elements are unsupported and will be ignored at best or result in an error.

View File

@@ -1,90 +0,0 @@
# index.hbs
`index.hbs` is the handlebars template that is used to render the book.
The markdown files are processed to html and then injected in that template.
If you want to change the layout or style of your book, chances are that you will
have to modify this template a little bit. Here is what you need to know.
## Data
A lot of data is exposed to the handlebars template with the "context".
In the handlebars template you can access this information by using
```handlebars
{{name_of_property}}
```
Here is a list of the properties that are exposed:
- ***language*** Language of the book in the form `en`. To use in <code class="language-html">\<html lang="{{ language }}"></code> for example.
At the moment it is hardcoded.
- ***title*** Title of the book, as specified in `book.json`
- ***path*** Relative path to the original markdown file from the source directory
- ***content*** This is the rendered markdown.
- ***path_to_root*** This is a path containing exclusively `../`'s that points to the root of the book from the current file.
Since the original directory structure is maintained, it is useful to prepend relative links with this `path_to_root`.
- ***chapters*** Is an array of dictionaries of the form
```json
{"section": "1.2.1", "name": "name of this chapter", "path": "dir/markdown.md"}
```
containing all the chapters of the book. It is used for example to construct the table of contents (sidebar).
## Handlebars Helpers
In addition to the properties you can access, there are some handlebars helpers at your disposal.
1. ### toc
The toc helper is used like this
```handlebars
{{#toc}}{{/toc}}
```
and outputs something that looks like this, depending on the structure of your book
```html
<ul class="chapter">
<li><a href="link/to/file.html">Some chapter</a></li>
<li>
<ul class="section">
<li><a href="link/to/other_file.html">Some other Chapter</a></li>
</ul>
</li>
</ul>
```
If you would like to make a toc with another structure, you have access to the chapters property containing all the data.
The only limitation at the moment is that you would have to do it with JavaScript instead of with a handlebars helper.
```html
<script>
var chapters = {{chapters}};
// Processing here
</script>
```
2. ### previous / next
The previous and next helpers expose a `link` and `name` property to the previous and next chapters.
They are used like this
```handlebars
{{#previous}}
<a href="{{link}}" class="nav-chapters previous">
<i class="fa fa-angle-left"></i>
</a>
{{/previous}}
```
The inner html will only be rendered if the previous / next chapter exists.
Of course the inner html can be changed to your liking.
------
*If you would like me to expose other properties or helpers, please [create a new issue](https://github.com/azerupi/mdBook/issues)
and I will consider it.*

View File

@@ -1,60 +0,0 @@
# Syntax Highlighting
For syntax highlighting I use [Highlight.js](https://highlightjs.org) with a custom theme.
Automatic language detection has been turned off, so you will probably want to
specify the programming language you use like this
<pre><code class="language-markdown">```rust
fn main() {
// Some code
}
```</code></pre>
## Custom theme
Like the rest of the theme, the files used for syntax highlighting can be overridden with your own.
- ***highlight.js*** normally you shouldn't have to overwrite this file, unless you want to use a more recent version.
- ***highlight.css*** theme used by highlight.js for syntax highlighting.
If you want to use another theme for `highlight.js` download it from their website, or make it yourself,
rename it to `highlight.css` and put it in `src/theme` (or the equivalent if you changed your source folder)
Now your theme will be used instead of the default theme.
## Hiding code lines
There is a feature in mdBook that let's you hide code lines by prepending them with a `#`.
```bash
#fn main() {
let x = 5;
let y = 6;
println!("{}", x + y);
#}
```
Will render as
```rust
#fn main() {
let x = 5;
let y = 7;
println!("{}", x + y);
#}
```
**At the moment, this only works for code examples that are annotated with `rust`. Because it would collide with semantics of some programming languages. In the future, we want to make this configurable through the `book.json` so that everyone can benefit from it.**
## Improve default theme
If you think the default theme doesn't look quite right for a specific language, or could be improved.
Feel free to [submit a new issue](https://github.com/azerupi/mdBook/issues) explaining what you have in mind and I will take a look at it.
You could also create a pull-request with the proposed improvements.
Overall the theme should be light and sober, without to many flashy colors.

View File

@@ -1,21 +0,0 @@
# Theme
The default renderer uses a [handlebars](http://handlebarsjs.com/) template to render your markdown files and comes with a default theme
included in the mdBook binary.
The theme is totally customizable, you can selectively replace every file from the theme by your own by adding a
`theme` directory in your source folder. Create a new file with the name of the file you want to override
and now that file will be used instead of the default file.
Here are the files you can override:
- ***index.hbs*** is the handlebars template.
- ***book.css*** is the style used in the output. If you want to change the design of your book, this is probably the file you want to modify. Sometimes in conjunction with `index.hbs` when you want to radically change the layout.
- ***book.js*** is mostly used to add client side functionality, like hiding / un-hiding the sidebar, changing the theme, ...
- ***highlight.js*** is the JavaScript that is used to highlight code snippets, you should not need to modify this.
- ***highlight.css*** is the theme used for the code highlighting
Generally, when you want to tweak the theme, you don't need to override all the files. If you only need changes in the stylesheet,
there is no point in overriding all the other files. Because custom files take precedence over built-in ones, they will not get updated with new fixes / features.
**Note:** When you override a file, it is possible that you break some functionality. Therefore I recommend to use the file from the default theme as template and only add / modify what you need. You can copy the default theme into your source directory automatically by using `mdbook init --theme` just remove the files you don't want to override.

View File

@@ -1,22 +0,0 @@
# Rust Library
mdBook is not only a command line tool, it can be used as a crate. You can extend it,
integrate it in current projects. Here is a short example:
```rust,ignore
extern crate mdbook;
use mdbook::MDBook;
use std::path::Path;
fn main() {
let mut book = MDBook::new(Path::new("my-book")) // Path to root
.set_src(Path::new("src")) // Path from root to source directory
.set_dest(Path::new("book")) // Path from root to output directory
.read_config(); // Parse book.json file for configuration
book.build().unwrap(); // Render the book
}
```
Check here for the [API docs](../mdbook/index.html) generated by rustdoc.

View File

@@ -1,13 +0,0 @@
# Contributors
Here is a list of the contributors who have helped improving mdBook. Big shout-out to them!
If you have contributed to mdBook and I forgot to add you, don't hesitate to add yourself to the list. If you are in the list, feel free to add your real name & contact information if you wish.
- [mdinger](https://github.com/mdinger)
- Kevin ([kbknapp](https://github.com/kbknapp))
- Steve Klabnik ([steveklabnik](https://github.com/steveklabnik))
- Adam Solove ([asolove](https://github.com/asolove))
- Wayne Nilsen ([waynenilsen](https://github.com/waynenilsen))
- [funnkill](https://github.com/funkill)
- Fu Gangqiang ([FuGangqiang](https://github.com/FuGangqiang))

View File

@@ -1,29 +0,0 @@
// build.rs
use std::process::Command;
use std::env;
use std::path::Path;
fn main() {
if let Ok(_) = env::var("CARGO_FEATURE_REGENERATE_CSS") {
// Compile stylus stylesheet to css
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let theme_dir = Path::new(&manifest_dir).join("src/theme/");
let stylus_dir = theme_dir.join("stylus/book.styl");
if !Command::new("stylus")
.arg(format!("{}", stylus_dir.to_str().unwrap()))
.arg("--out")
.arg(format!("{}", theme_dir.to_str().unwrap()))
.arg("--use")
.arg("nib")
.status().unwrap()
.success() {
panic!("Stylus encoutered an error");
}
}
}

24
ci/install-hub.sh Executable file
View File

@@ -0,0 +1,24 @@
#!/usr/bin/env bash
# Installs the `hub` executable into hub/bin
set -ex
case $1 in
ubuntu*)
curl -LsSf https://github.com/github/hub/releases/download/v2.12.8/hub-linux-amd64-2.12.8.tgz -o hub.tgz
mkdir hub
tar -xzvf hub.tgz --strip=1 -C hub
;;
macos*)
curl -LsSf https://github.com/github/hub/releases/download/v2.12.8/hub-darwin-amd64-2.12.8.tgz -o hub.tgz
mkdir hub
tar -xzvf hub.tgz --strip=1 -C hub
;;
windows*)
curl -LsSf https://github.com/github/hub/releases/download/v2.12.8/hub-windows-amd64-2.12.8.zip -o hub.zip
7z x hub.zip -ohub
;;
*)
echo "OS should be first parameter, was: $1"
;;
esac
echo "$PWD/hub/bin" >> $GITHUB_PATH

30
ci/install-rust.sh Executable file
View File

@@ -0,0 +1,30 @@
#!/usr/bin/env bash
# Install/update rust.
# The first argument should be the toolchain to install.
set -ex
if [ -z "$1" ]
then
echo "First parameter must be toolchain to install."
exit 1
fi
TOOLCHAIN="$1"
rustup set profile minimal
rustup component remove --toolchain=$TOOLCHAIN rust-docs || echo "already removed"
rustup update --no-self-update $TOOLCHAIN
if [ -n "$2" ]
then
TARGET="$2"
HOST=$(rustc -Vv | grep ^host: | sed -e "s/host: //g")
if [ "$HOST" != "$TARGET" ]
then
rustup component add llvm-tools-preview --toolchain=$TOOLCHAIN
rustup component add rust-std-$TARGET --toolchain=$TOOLCHAIN
fi
fi
rustup default $TOOLCHAIN
rustup -V
rustc -Vv
cargo -V

52
ci/make-release.sh Executable file
View File

@@ -0,0 +1,52 @@
#!/usr/bin/env bash
# Builds the release and creates an archive and optionally deploys to GitHub.
set -ex
if [[ -z "$GITHUB_REF" ]]
then
echo "GITHUB_REF must be set"
exit 1
fi
# Strip mdbook-refs/tags/ from the start of the ref.
TAG=${GITHUB_REF#*/tags/}
host=$(rustc -Vv | grep ^host: | sed -e "s/host: //g")
target=$2
if [ "$host" != "$target" ]
then
export "CARGO_TARGET_$(echo $target | tr a-z- A-Z_)_LINKER"=rust-lld
fi
export CARGO_PROFILE_RELEASE_LTO=true
cargo build --bin mdbook --release --target $target
cd target/$target/release
case $1 in
ubuntu*)
asset="mdbook-$TAG-$target.tar.gz"
tar czf ../../$asset mdbook
;;
macos*)
asset="mdbook-$TAG-$target.tar.gz"
# There is a bug with BSD tar on macOS where the first 8MB of the file are
# sometimes all NUL bytes. See https://github.com/actions/cache/issues/403
# and https://github.com/rust-lang/cargo/issues/8603 for some more
# information. An alternative solution here is to install GNU tar, but
# flushing the disk cache seems to work, too.
sudo /usr/sbin/purge
tar czf ../../$asset mdbook
;;
windows*)
asset="mdbook-$TAG-$target.zip"
7z a ../../$asset mdbook.exe
;;
*)
echo "OS should be first parameter, was: $1"
;;
esac
cd ../..
if [[ -z "$GITHUB_TOKEN" ]]
then
echo "$GITHUB_TOKEN not set, skipping deploy."
else
hub release edit -m "" --attach $asset $TAG
fi

View File

@@ -1,42 +0,0 @@
#!/bin/bash
# Exit on error or variable unset
set -o errexit -o nounset
NC='\033[39m'
CYAN='\033[36m'
GREEN='\033[32m'
rev=$(git rev-parse --short HEAD)
echo -e "${CYAN}Running cargo doc${NC}"
# Run cargo doc
cargo doc
echo -e "${CYAN}Running mdbook build${NC}"
# Run mdbook to generate the book
target/debug/mdbook build book-example/
echo -e "${CYAN}Copying book to target/doc${NC}"
# Copy files from rendered book to doc root
cp -R book-example/book/* target/doc/
cd target/doc
echo -e "${CYAN}Initializing Git${NC}"
git init
git config user.name "Mathieu David"
git config user.email "mathieudavid@mathieudavid.org"
git remote add upstream "https://$GH_TOKEN@github.com/azerupi/mdBook.git"
git fetch upstream
git reset upstream/gh-pages
touch .
echo -e "${CYAN}Pushing changes to gh-pages${NC}"
git add -A .
git commit -m "rebuild pages at ${rev}"
git push -q upstream HEAD:gh-pages
echo -e "${GREEN}Deployement done${NC}"

View File

@@ -0,0 +1,160 @@
use crate::nop_lib::Nop;
use clap::{Arg, ArgMatches, Command};
use mdbook::book::Book;
use mdbook::errors::Error;
use mdbook::preprocess::{CmdPreprocessor, Preprocessor, PreprocessorContext};
use semver::{Version, VersionReq};
use std::io;
use std::process;
pub fn make_app() -> Command {
Command::new("nop-preprocessor")
.about("A mdbook preprocessor which does precisely nothing")
.subcommand(
Command::new("supports")
.arg(Arg::new("renderer").required(true))
.about("Check whether a renderer is supported by this preprocessor"),
)
}
fn main() {
let matches = make_app().get_matches();
// Users will want to construct their own preprocessor here
let preprocessor = Nop::new();
if let Some(sub_args) = matches.subcommand_matches("supports") {
handle_supports(&preprocessor, sub_args);
} else if let Err(e) = handle_preprocessing(&preprocessor) {
eprintln!("{}", e);
process::exit(1);
}
}
fn handle_preprocessing(pre: &dyn Preprocessor) -> Result<(), Error> {
let (ctx, book) = CmdPreprocessor::parse_input(io::stdin())?;
let book_version = Version::parse(&ctx.mdbook_version)?;
let version_req = VersionReq::parse(mdbook::MDBOOK_VERSION)?;
if !version_req.matches(&book_version) {
eprintln!(
"Warning: The {} plugin was built against version {} of mdbook, \
but we're being called from version {}",
pre.name(),
mdbook::MDBOOK_VERSION,
ctx.mdbook_version
);
}
let processed_book = pre.run(&ctx, book)?;
serde_json::to_writer(io::stdout(), &processed_book)?;
Ok(())
}
fn handle_supports(pre: &dyn Preprocessor, sub_args: &ArgMatches) -> ! {
let renderer = sub_args
.get_one::<String>("renderer")
.expect("Required argument");
let supported = pre.supports_renderer(renderer);
// Signal whether the renderer is supported by exiting with 1 or 0.
if supported {
process::exit(0);
} else {
process::exit(1);
}
}
/// The actual implementation of the `Nop` preprocessor. This would usually go
/// in your main `lib.rs` file.
mod nop_lib {
use super::*;
/// A no-op preprocessor.
pub struct Nop;
impl Nop {
pub fn new() -> Nop {
Nop
}
}
impl Preprocessor for Nop {
fn name(&self) -> &str {
"nop-preprocessor"
}
fn run(&self, ctx: &PreprocessorContext, book: Book) -> Result<Book, Error> {
// In testing we want to tell the preprocessor to blow up by setting a
// particular config value
if let Some(nop_cfg) = ctx.config.get_preprocessor(self.name()) {
if nop_cfg.contains_key("blow-up") {
anyhow::bail!("Boom!!1!");
}
}
// we *are* a no-op preprocessor after all
Ok(book)
}
fn supports_renderer(&self, renderer: &str) -> bool {
renderer != "not-supported"
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn nop_preprocessor_run() {
let input_json = r##"[
{
"root": "/path/to/book",
"config": {
"book": {
"authors": ["AUTHOR"],
"language": "en",
"multilingual": false,
"src": "src",
"title": "TITLE"
},
"preprocessor": {
"nop": {}
}
},
"renderer": "html",
"mdbook_version": "0.4.21"
},
{
"sections": [
{
"Chapter": {
"name": "Chapter 1",
"content": "# Chapter 1\n",
"number": [1],
"sub_items": [],
"path": "chapter_1.md",
"source_path": "chapter_1.md",
"parent_names": []
}
}
],
"__non_exhaustive": null
}
]"##;
let input_json = input_json.as_bytes();
let (ctx, book) = mdbook::preprocess::CmdPreprocessor::parse_input(input_json).unwrap();
let expected_book = book.clone();
let result = Nop::new().run(&ctx, book);
assert!(result.is_ok());
// The nop-preprocessor should not have made any changes to the book content.
let actual_book = result.unwrap();
assert_eq!(actual_book, expected_book);
}
}
}

30
guide/book.toml Normal file
View File

@@ -0,0 +1,30 @@
[book]
title = "mdBook Documentation"
description = "Create book from markdown files. Like Gitbook but implemented in Rust"
authors = ["Mathieu David", "Michael-F-Bryan"]
language = "en"
[rust]
edition = "2018"
[output.html]
mathjax-support = true
site-url = "/mdBook/"
git-repository-url = "https://github.com/rust-lang/mdBook/tree/master/guide"
edit-url-template = "https://github.com/rust-lang/mdBook/edit/master/guide/{path}"
[output.html.playground]
editable = true
line-numbers = true
[output.html.search]
limit-results = 20
use-boolean-and = true
boost-title = 2
boost-hierarchy = 2
boost-paragraph = 1
expand = true
heading-split-level = 2
[output.html.redirect]
"/format/config.html" = "configuration/index.html"

3
guide/src/404.md Normal file
View File

@@ -0,0 +1,3 @@
# Document not found (404)
This URL is invalid, sorry. Try the search instead!

41
guide/src/README.md Normal file
View File

@@ -0,0 +1,41 @@
# Introduction
**mdBook** is a command line tool to create books with Markdown.
It is ideal for creating product or API documentation, tutorials, course materials or anything that requires a clean,
easily navigable and customizable presentation.
* Lightweight [Markdown] syntax helps you focus more on your content
* Integrated [search] support
* Color [syntax highlighting] for code blocks for many different languages
* [Theme] files allow customizing the formatting of the output
* [Preprocessors] can provide extensions for custom syntax and modifying content
* [Backends] can render the output to multiple formats
* Written in [Rust] for speed, safety, and simplicity
* Automated testing of [Rust code samples]
This guide is an example of what mdBook produces.
mdBook is used by the Rust programming language project, and [The Rust Programming Language][trpl] book is another fine example of mdBook in action.
[Markdown]: format/markdown.md
[search]: guide/reading.md#search
[syntax highlighting]: format/theme/syntax-highlighting.md
[theme]: format/theme/index.html
[preprocessors]: format/configuration/preprocessors.md
[backends]: format/configuration/renderers.md
[Rust]: https://www.rust-lang.org/
[trpl]: https://doc.rust-lang.org/book/
[Rust code samples]: cli/test.md
## Contributing
mdBook is free and open source. You can find the source code on
[GitHub](https://github.com/rust-lang/mdBook) and issues and feature requests can be posted on
the [GitHub issue tracker](https://github.com/rust-lang/mdBook/issues). mdBook relies on the community to fix bugs and
add features: if you'd like to contribute, please read
the [CONTRIBUTING](https://github.com/rust-lang/mdBook/blob/master/CONTRIBUTING.md) guide and consider opening
a [pull request](https://github.com/rust-lang/mdBook/pulls).
## License
The mdBook source and documentation are released under
the [Mozilla Public License v2.0](https://www.mozilla.org/MPL/2.0/).

43
guide/src/SUMMARY.md Normal file
View File

@@ -0,0 +1,43 @@
# Summary
[Introduction](README.md)
# User Guide
- [Installation](guide/installation.md)
- [Reading Books](guide/reading.md)
- [Creating a Book](guide/creating.md)
# Reference Guide
- [Command Line Tool](cli/README.md)
- [init](cli/init.md)
- [build](cli/build.md)
- [watch](cli/watch.md)
- [serve](cli/serve.md)
- [test](cli/test.md)
- [clean](cli/clean.md)
- [completions](cli/completions.md)
- [Format](format/README.md)
- [SUMMARY.md](format/summary.md)
- [Draft chapter]()
- [Configuration](format/configuration/README.md)
- [General](format/configuration/general.md)
- [Preprocessors](format/configuration/preprocessors.md)
- [Renderers](format/configuration/renderers.md)
- [Environment Variables](format/configuration/environment-variables.md)
- [Theme](format/theme/README.md)
- [index.hbs](format/theme/index-hbs.md)
- [Syntax highlighting](format/theme/syntax-highlighting.md)
- [Editor](format/theme/editor.md)
- [MathJax Support](format/mathjax.md)
- [mdBook-specific features](format/mdbook.md)
- [Markdown](format/markdown.md)
- [Continuous Integration](continuous-integration.md)
- [For Developers](for_developers/README.md)
- [Preprocessors](for_developers/preprocessors.md)
- [Alternative Backends](for_developers/backends.md)
-----------
[Contributors](misc/contributors.md)

14
guide/src/cli/README.md Normal file
View File

@@ -0,0 +1,14 @@
# Command Line Tool
The `mdbook` command-line tool is used to create and build books.
After you have [installed](../guide/installation.md) `mdbook`, you can run the `mdbook help` command in your terminal to view the available commands.
This following sections provide in-depth information on the different commands available.
* [`mdbook init <directory>`](init.md) — Creates a new book with minimal boilerplate to start with.
* [`mdbook build`](build.md) — Renders the book.
* [`mdbook watch`](watch.md) — Rebuilds the book any time a source file changes.
* [`mdbook serve`](serve.md) — Runs a web server to view the book, and rebuilds on changes.
* [`mdbook test`](test.md) — Tests Rust code samples.
* [`mdbook clean`](clean.md) — Deletes the rendered output.
* [`mdbook completions`](completions.md) — Support for shell auto-completion.

40
guide/src/cli/build.md Normal file
View File

@@ -0,0 +1,40 @@
# The build command
The build command is used to render your book:
```bash
mdbook build
```
It will try to parse your `SUMMARY.md` file to understand the structure of your
book and fetch the corresponding files. Note that files mentioned in `SUMMARY.md`
but not present will be created.
The rendered output will maintain the same directory structure as the source for
convenience. Large books will therefore remain structured when rendered.
#### Specify a directory
The `build` command can take a directory as an argument to use as the book's
root instead of the current working directory.
```bash
mdbook build path/to/book
```
#### --open
When you use the `--open` (`-o`) flag, mdbook will open the rendered book in
your default web browser after building it.
#### --dest-dir
The `--dest-dir` (`-d`) option allows you to change the output directory for the
book. Relative paths are interpreted relative to the book's root directory. If
not specified it will default to the value of the `build.build-dir` key in
`book.toml`, or to `./book`.
-------------------
***Note:*** *The build command copies all files (excluding files with `.md` extension) from the source directory
into the build directory.*

30
guide/src/cli/clean.md Normal file
View File

@@ -0,0 +1,30 @@
# The clean command
The clean command is used to delete the generated book and any other build
artifacts.
```bash
mdbook clean
```
#### Specify a directory
The `clean` command can take a directory as an argument to use as the book's
root instead of the current working directory.
```bash
mdbook clean path/to/book
```
#### --dest-dir
The `--dest-dir` (`-d`) option allows you to override the book's output
directory, which will be deleted by this command. Relative paths are interpreted
relative to the book's root directory. If not specified it will default to the
value of the `build.build-dir` key in `book.toml`, or to `./book`.
```bash
mdbook clean --dest-dir=path/to/book
```
`path/to/book` could be absolute or relative.

View File

@@ -0,0 +1,16 @@
# The completions command
The completions command is used to generate auto-completions for some common shells.
This means when you type `mdbook` in your shell, you can then press your shell's auto-complete key (usually the Tab key) and it may display what the valid options are, or finish partial input.
The completions first need to be installed for your shell:
```bash
mdbook completions bash > ~/.local/share/bash-completion/completions/mdbook
```
The command prints a completion script for the given shell.
Run `mdbook completions --help` for a list of supported shells.
Where to place the completions depend on which shell you are using and your operating system.
Consult your shell's documentation for more information one where to place the script.

70
guide/src/cli/init.md Normal file
View File

@@ -0,0 +1,70 @@
# The init command
There is some minimal boilerplate that is the same for every new book. It's for
this purpose that mdBook includes an `init` command.
The `init` command is used like this:
```bash
mdbook init
```
When using the `init` command for the first time, a couple of files will be set
up for you:
```bash
book-test/
├── book
└── src
├── chapter_1.md
└── SUMMARY.md
```
- The `src` directory is where you write your book in markdown. It contains all
the source files, configuration files, etc.
- The `book` directory is where your book is rendered. All the output is ready
to be uploaded to a server to be seen by your audience.
- The `SUMMARY.md` is the skeleton of your
book, and is discussed in more detail [in another
chapter](../format/summary.md).
#### Tip: Generate chapters from SUMMARY.md
When a `SUMMARY.md` file already exists, the `init` command will first parse it
and generate the missing files according to the paths used in the `SUMMARY.md`.
This allows you to think and create the whole structure of your book and then
let mdBook generate it for you.
#### Specify a directory
The `init` command can take a directory as an argument to use as the book's root
instead of the current working directory.
```bash
mdbook init path/to/book
```
#### --theme
When you use the `--theme` flag, the default theme will be copied into a
directory called `theme` in your source directory so that you can modify it.
The theme is selectively overwritten, this means that if you don't want to
overwrite a specific file, just delete it and the default file will be used.
#### --title
Specify a title for the book. If not supplied, an interactive prompt will ask for
a title.
```bash
mdbook init --title="my amazing book"
```
#### --ignore
Create a `.gitignore` file configured to ignore the `book` directory created when [building] a book.
If not supplied, an interactive prompt will ask whether it should be created.
[building]: build.md

56
guide/src/cli/serve.md Normal file
View File

@@ -0,0 +1,56 @@
# The serve command
The serve command is used to preview a book by serving it via HTTP at
`localhost:3000` by default:
```bash
mdbook serve
```
The `serve` command watches the book's `src` directory for
changes, rebuilding the book and refreshing clients for each change; this includes
re-creating deleted files still mentioned in `SUMMARY.md`! A websocket
connection is used to trigger the client-side refresh.
***Note:*** *The `serve` command is for testing a book's HTML output, and is not
intended to be a complete HTTP server for a website.*
#### Specify a directory
The `serve` command can take a directory as an argument to use as the book's
root instead of the current working directory.
```bash
mdbook serve path/to/book
```
### Server options
The `serve` hostname defaults to `localhost`, and the port defaults to `3000`. Either option can be specified on the command line:
```bash
mdbook serve path/to/book -p 8000 -n 127.0.0.1
```
#### --open
When you use the `--open` (`-o`) flag, mdbook will open the book in your
default web browser after starting the server.
#### --dest-dir
The `--dest-dir` (`-d`) option allows you to change the output directory for the
book. Relative paths are interpreted relative to the book's root directory. If
not specified it will default to the value of the `build.build-dir` key in
`book.toml`, or to `./book`.
#### Specify exclude patterns
The `serve` command will not automatically trigger a build for files listed in
the `.gitignore` file in the book root directory. The `.gitignore` file may
contain file patterns described in the [gitignore
documentation](https://git-scm.com/docs/gitignore). This can be useful for
ignoring temporary files created by some editors.
***Note:*** *Only the `.gitignore` from the book root directory is used. Global
`$HOME/.gitignore` or `.gitignore` files in parent directories are not used.*

68
guide/src/cli/test.md Normal file
View File

@@ -0,0 +1,68 @@
# The test command
When writing a book, you sometimes need to automate some tests. For example,
[The Rust Programming Book](https://doc.rust-lang.org/stable/book/) uses a lot
of code examples that could get outdated. Therefore it is very important for
them to be able to automatically test these code examples.
mdBook supports a `test` command that will run all available tests in a book. At
the moment, only rustdoc tests are supported, but this may be expanded upon in
the future.
#### Disable tests on a code block
rustdoc doesn't test code blocks which contain the `ignore` attribute:
```rust,ignore
fn main() {}
```
rustdoc also doesn't test code blocks which specify a language other than Rust:
```markdown
**Foo**: _bar_
```
rustdoc *does* test code blocks which have no language specified:
```
This is going to cause an error!
```
#### Specify a directory
The `test` command can take a directory as an argument to use as the book's root
instead of the current working directory.
```bash
mdbook test path/to/book
```
#### --library-path
The `--library-path` (`-L`) option allows you to add directories to the library
search path used by `rustdoc` when it builds and tests the examples. Multiple
directories can be specified with multiple options (`-L foo -L bar`) or with a
comma-delimited list (`-L foo,bar`). The path should point to the Cargo
[build cache](https://doc.rust-lang.org/cargo/guide/build-cache.html) `deps` directory that
contains the build output of your project. For example, if your Rust project's book is in a directory
named `my-book`, the following command would include the crate's dependencies when running `test`:
```shell
mdbook test my-book -L target/debug/deps/
```
See the `rustdoc` command-line [documentation](https://doc.rust-lang.org/rustdoc/command-line-arguments.html#-l--library-path-where-to-look-for-dependencies)
for more information.
#### --dest-dir
The `--dest-dir` (`-d`) option allows you to change the output directory for the
book. Relative paths are interpreted relative to the book's root directory. If
not specified it will default to the value of the `build.build-dir` key in
`book.toml`, or to `./book`.
#### --chapter
The `--chapter` (`-c`) option allows you to test a specific chapter of the
book using the chapter name or the relative path to the chapter.

40
guide/src/cli/watch.md Normal file
View File

@@ -0,0 +1,40 @@
# The watch command
The `watch` command is useful when you want your book to be rendered on every
file change. You could repeatedly issue `mdbook build` every time a file is
changed. But using `mdbook watch` once will watch your files and will trigger a
build automatically whenever you modify a file; this includes re-creating
deleted files still mentioned in `SUMMARY.md`!
#### Specify a directory
The `watch` command can take a directory as an argument to use as the book's
root instead of the current working directory.
```bash
mdbook watch path/to/book
```
#### --open
When you use the `--open` (`-o`) option, mdbook will open the rendered book in
your default web browser.
#### --dest-dir
The `--dest-dir` (`-d`) option allows you to change the output directory for the
book. Relative paths are interpreted relative to the book's root directory. If
not specified it will default to the value of the `build.build-dir` key in
`book.toml`, or to `./book`.
#### Specify exclude patterns
The `watch` command will not automatically trigger a build for files listed in
the `.gitignore` file in the book root directory. The `.gitignore` file may
contain file patterns described in the [gitignore
documentation](https://git-scm.com/docs/gitignore). This can be useful for
ignoring temporary files created by some editors.
_Note: Only `.gitignore` from book root directory is used. Global
`$HOME/.gitignore` or `.gitignore` files in parent directories are not used._

View File

@@ -0,0 +1,121 @@
# Running `mdbook` in Continuous Integration
There are a variety of services such as [GitHub Actions] or [GitLab CI/CD] which can be used to test and deploy your book automatically.
The following provides some general guidelines on how to configure your service to run mdBook.
Specific recipes can be found at the [Automated Deployment] wiki page.
[GitHub Actions]: https://docs.github.com/en/actions
[GitLab CI/CD]: https://docs.gitlab.com/ee/ci/
[Automated Deployment]: https://github.com/rust-lang/mdBook/wiki/Automated-Deployment
## Installing mdBook
There are several different strategies for installing mdBook.
The particular method depends on your needs and preferences.
### Pre-compiled binaries
Perhaps the easiest method is to use the pre-compiled binaries found on the [GitHub Releases page][releases].
A simple approach would be to use the popular `curl` CLI tool to download the executable:
```sh
mkdir bin
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.26/mdbook-v0.4.26-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
bin/mdbook build
```
Some considerations for this approach:
* This is relatively fast, and does not necessarily require dealing with caching.
* This does not require installing Rust.
* Specifying a specific URL means you have to manually update your script to get a new version.
This may be a benefit if you want to lock to a specific version.
However, some users prefer to automatically get a newer version when they are published.
* You are reliant on the GitHub CDN being available.
[releases]: https://github.com/rust-lang/mdBook/releases
### Building from source
Building from source will require having Rust installed.
Some services have Rust pre-installed, but if your service does not, you will need to add a step to install it.
After Rust is installed, `cargo install` can be used to build and install mdBook.
We recommend using a SemVer version specifier so that you get the latest **non-breaking** version of mdBook.
For example:
```sh
cargo install mdbook --no-default-features --features search --vers "^0.4" --locked
```
This includes several recommended options:
* `--no-default-features` — Disables features like the HTTP server used by `mdbook serve` that is likely not needed on CI.
This will speed up the build time significantly.
* `--features search` — Disabling default features means you should then manually enable features that you want, such as the built-in [search] capability.
* `--vers "^0.4"` — This will install the most recent version of the `0.4` series.
However, versions after like `0.5.0` won't be installed, as they may break your build.
Cargo will automatically upgrade mdBook if you have an older version already installed.
* `--locked` — This will use the dependencies that were used when mdBook was released.
Without `--locked`, it will use the latest version of all dependencies, which may include some fixes since the last release, but may also (rarely) cause build problems.
You will likely want to investigate caching options, as building mdBook can be somewhat slow.
[search]: guide/reading.md#search
## Running tests
You may want to run tests using [`mdbook test`] every time you push a change or create a pull request.
This can be used to validate Rust code examples in the book.
This will require having Rust installed.
Some services have Rust pre-installed, but if your service does not, you will need to add a step to install it.
Other than making sure the appropriate version of Rust is installed, there's not much more than just running `mdbook test` from the book directory.
You may also want to consider running other kinds of tests, like [mdbook-linkcheck] which will check for broken links.
Or if you have your own style checks, spell checker, or any other tests it might be good to run them in CI.
[`mdbook test`]: cli/test.md
[mdbook-linkcheck]: https://github.com/Michael-F-Bryan/mdbook-linkcheck#continuous-integration
## Deploying
You may want to automatically deploy your book.
Some may want to do this with every time a change is pushed, and others may want to only deploy when a specific release is tagged.
You'll also need to understand the specifics on how to push a change to your web service.
For example, [GitHub Pages] just requires committing the output onto a specific git branch.
Other services may require using something like SSH to connect to a remote server.
The basic outline is that you need to run `mdbook build` to generate the output, and then transfer the files (which are in the `book` directory) to the correct location.
You may then want to consider if you need to invalidate any caches on your web service.
See the [Automated Deployment] wiki page for examples of various different services.
[GitHub Pages]: https://docs.github.com/en/pages
### 404 handling
mdBook automatically generates a 404 page to be used for broken links.
The default output is a file named `404.html` at the root of the book.
Some services like [GitHub Pages] will automatically use this page for broken links.
For other services, you may want to consider configuring the web server to use this page as it will provide the reader navigation to get back to the book.
If your book is not deployed at the root of the domain, then you should set the [`output.html.site-url`] setting so that the 404 page works correctly.
It needs to know where the book is deployed in order to load the static files (like CSS) correctly.
For example, this guide is deployed at <https://rust-lang.github.io/mdBook/>, and the `site-url` setting is configured like this:
```toml
# book.toml
[output.html]
site-url = "/mdBook/"
```
You can customize the look of the 404 page by creating a file named `src/404.md` in your book.
If you want to use a different filename, you can set [`output.html.input-404`] to a different filename.
[`output.html.site-url`]: format/configuration/renderers.md#html-renderer-options
[`output.html.input-404`]: format/configuration/renderers.md#html-renderer-options

View File

@@ -0,0 +1,47 @@
# For Developers
While `mdbook` is mainly used as a command line tool, you can also import the
underlying library directly and use that to manage a book. It also has a fairly
flexible plugin mechanism, allowing you to create your own custom tooling and
consumers (often referred to as *backends*) if you need to do some analysis of
the book or render it in a different format.
The *For Developers* chapters are here to show you the more advanced usage of
`mdbook`.
The two main ways a developer can hook into the book's build process is via,
- [Preprocessors](preprocessors.md)
- [Alternative Backends](backends.md)
## The Build Process
The process of rendering a book project goes through several steps.
1. Load the book
- Parse the `book.toml`, falling back to the default `Config` if it doesn't
exist
- Load the book chapters into memory
- Discover which preprocessors/backends should be used
2. For each backend:
1. Run all the preprocessors.
2. Call the backend to render the processed result.
## Using `mdbook` as a Library
The `mdbook` binary is just a wrapper around the `mdbook` crate, exposing its
functionality as a command-line program. As such it is quite easy to create your
own programs which use `mdbook` internally, adding your own functionality (e.g.
a custom preprocessor) or tweaking the build process.
The easiest way to find out how to use the `mdbook` crate is by looking at the
[API Docs]. The top level documentation explains how one would use the
[`MDBook`] type to load and build a book, while the [config] module gives a good
explanation on the configuration system.
[`MDBook`]: https://docs.rs/mdbook/*/mdbook/book/struct.MDBook.html
[API Docs]: https://docs.rs/mdbook/*/mdbook/
[config]: https://docs.rs/mdbook/*/mdbook/config/index.html

View File

@@ -0,0 +1,346 @@
# Alternative Backends
A "backend" is simply a program which `mdbook` will invoke during the book
rendering process. This program is passed a JSON representation of the book and
configuration information via `stdin`. Once the backend receives this
information it is free to do whatever it wants.
See [Configuring Renderers](../format/configuration/renderers.md) for more information about using backends.
The community has developed several backends.
See the [Third Party Plugins] wiki page for a list of available backends.
## Setting Up
This page will step you through creating your own alternative backend in the form
of a simple word counting program. Although it will be written in Rust, there's
no reason why it couldn't be accomplished using something like Python or Ruby.
First you'll want to create a new binary program and add `mdbook` as a
dependency.
```shell
$ cargo new --bin mdbook-wordcount
$ cd mdbook-wordcount
$ cargo add mdbook
```
When our `mdbook-wordcount` plugin is invoked, `mdbook` will send it a JSON
version of [`RenderContext`] via our plugin's `stdin`. For convenience, there's
a [`RenderContext::from_json()`] constructor which will load a `RenderContext`.
This is all the boilerplate necessary for our backend to load the book.
```rust
// src/main.rs
extern crate mdbook;
use std::io;
use mdbook::renderer::RenderContext;
fn main() {
let mut stdin = io::stdin();
let ctx = RenderContext::from_json(&mut stdin).unwrap();
}
```
> **Note:** The `RenderContext` contains a `version` field. This lets backends
figure out whether they are compatible with the version of `mdbook` it's being
called by. This `version` comes directly from the corresponding field in
`mdbook`'s `Cargo.toml`.
It is recommended that backends use the [`semver`] crate to inspect this field
and emit a warning if there may be a compatibility issue.
## Inspecting the Book
Now our backend has a copy of the book, lets count how many words are in each
chapter!
Because the `RenderContext` contains a [`Book`] field (`book`), and a `Book` has
the [`Book::iter()`] method for iterating over all items in a `Book`, this step
turns out to be just as easy as the first.
```rust
fn main() {
let mut stdin = io::stdin();
let ctx = RenderContext::from_json(&mut stdin).unwrap();
for item in ctx.book.iter() {
if let BookItem::Chapter(ref ch) = *item {
let num_words = count_words(ch);
println!("{}: {}", ch.name, num_words);
}
}
}
fn count_words(ch: &Chapter) -> usize {
ch.content.split_whitespace().count()
}
```
## Enabling the Backend
Now we've got the basics running, we want to actually use it. First, install the
program.
```shell
$ cargo install --path .
```
Then `cd` to the particular book you'd like to count the words of and update its
`book.toml` file.
```diff
[book]
title = "mdBook Documentation"
description = "Create book from markdown files. Like Gitbook but implemented in Rust"
authors = ["Mathieu David", "Michael-F-Bryan"]
+ [output.html]
+ [output.wordcount]
```
When it loads a book into memory, `mdbook` will inspect your `book.toml` file to
try and figure out which backends to use by looking for all `output.*` tables.
If none are provided it'll fall back to using the default HTML renderer.
Notably, this means if you want to add your own custom backend you'll also need
to make sure to add the HTML backend, even if its table just stays empty.
Now you just need to build your book like normal, and everything should *Just
Work*.
```shell
$ mdbook build
...
2018-01-16 07:31:15 [INFO] (mdbook::renderer): Invoking the "mdbook-wordcount" renderer
mdBook: 126
Command Line Tool: 224
init: 283
build: 145
watch: 146
serve: 292
test: 139
Format: 30
SUMMARY.md: 259
Configuration: 784
Theme: 304
index.hbs: 447
Syntax highlighting: 314
MathJax Support: 153
Rust code specific features: 148
For Developers: 788
Alternative Backends: 710
Contributors: 85
```
The reason we didn't need to specify the full name/path of our `wordcount`
backend is because `mdbook` will try to *infer* the program's name via
convention. The executable for the `foo` backend is typically called
`mdbook-foo`, with an associated `[output.foo]` entry in the `book.toml`. To
explicitly tell `mdbook` what command to invoke (it may require command-line
arguments or be an interpreted script), you can use the `command` field.
```diff
[book]
title = "mdBook Documentation"
description = "Create book from markdown files. Like Gitbook but implemented in Rust"
authors = ["Mathieu David", "Michael-F-Bryan"]
[output.html]
[output.wordcount]
+ command = "python /path/to/wordcount.py"
```
## Configuration
Now imagine you don't want to count the number of words on a particular chapter
(it might be generated text/code, etc). The canonical way to do this is via the
usual `book.toml` configuration file by adding items to your `[output.foo]`
table.
The `Config` can be treated roughly as a nested hashmap which lets you call
methods like `get()` to access the config's contents, with a
`get_deserialized()` convenience method for retrieving a value and automatically
deserializing to some arbitrary type `T`.
To implement this, we'll create our own serializable `WordcountConfig` struct
which will encapsulate all configuration for this backend.
First add `serde` and `serde_derive` to your `Cargo.toml`,
```
$ cargo add serde serde_derive
```
And then you can create the config struct,
```rust
extern crate serde;
#[macro_use]
extern crate serde_derive;
...
#[derive(Debug, Default, Serialize, Deserialize)]
#[serde(default, rename_all = "kebab-case")]
pub struct WordcountConfig {
pub ignores: Vec<String>,
}
```
Now we just need to deserialize the `WordcountConfig` from our `RenderContext`
and then add a check to make sure we skip ignored chapters.
```diff
fn main() {
let mut stdin = io::stdin();
let ctx = RenderContext::from_json(&mut stdin).unwrap();
+ let cfg: WordcountConfig = ctx.config
+ .get_deserialized("output.wordcount")
+ .unwrap_or_default();
for item in ctx.book.iter() {
if let BookItem::Chapter(ref ch) = *item {
+ if cfg.ignores.contains(&ch.name) {
+ continue;
+ }
+
let num_words = count_words(ch);
println!("{}: {}", ch.name, num_words);
}
}
}
```
## Output and Signalling Failure
While it's nice to print word counts to the terminal when a book is built, it
might also be a good idea to output them to a file somewhere. `mdbook` tells a
backend where it should place any generated output via the `destination` field
in [`RenderContext`].
```diff
+ use std::fs::{self, File};
+ use std::io::{self, Write};
- use std::io;
use mdbook::renderer::RenderContext;
use mdbook::book::{BookItem, Chapter};
fn main() {
...
+ let _ = fs::create_dir_all(&ctx.destination);
+ let mut f = File::create(ctx.destination.join("wordcounts.txt")).unwrap();
+
for item in ctx.book.iter() {
if let BookItem::Chapter(ref ch) = *item {
...
let num_words = count_words(ch);
println!("{}: {}", ch.name, num_words);
+ writeln!(f, "{}: {}", ch.name, num_words).unwrap();
}
}
}
```
> **Note:** There is no guarantee that the destination directory exists or is
> empty (`mdbook` may leave the previous contents to let backends do caching),
> so it's always a good idea to create it with `fs::create_dir_all()`.
>
> If the destination directory already exists, don't assume it will be empty.
> To allow backends to cache the results from previous runs, `mdbook` may leave
> old content in the directory.
There's always the possibility that an error will occur while processing a book
(just look at all the `unwrap()`'s we've written already), so `mdbook` will
interpret a non-zero exit code as a rendering failure.
For example, if we wanted to make sure all chapters have an *even* number of
words, erroring out if an odd number is encountered, then you may do something
like this:
```diff
+ use std::process;
...
fn main() {
...
for item in ctx.book.iter() {
if let BookItem::Chapter(ref ch) = *item {
...
let num_words = count_words(ch);
println!("{}: {}", ch.name, num_words);
writeln!(f, "{}: {}", ch.name, num_words).unwrap();
+ if cfg.deny_odds && num_words % 2 == 1 {
+ eprintln!("{} has an odd number of words!", ch.name);
+ process::exit(1);
}
}
}
}
#[derive(Debug, Default, Serialize, Deserialize)]
#[serde(default, rename_all = "kebab-case")]
pub struct WordcountConfig {
pub ignores: Vec<String>,
+ pub deny_odds: bool,
}
```
Now, if we reinstall the backend and build a book,
```shell
$ cargo install --path . --force
$ mdbook build /path/to/book
...
2018-01-16 21:21:39 [INFO] (mdbook::renderer): Invoking the "wordcount" renderer
mdBook: 126
Command Line Tool: 224
init: 283
init has an odd number of words!
2018-01-16 21:21:39 [ERROR] (mdbook::renderer): Renderer exited with non-zero return code.
2018-01-16 21:21:39 [ERROR] (mdbook::utils): Error: Rendering failed
2018-01-16 21:21:39 [ERROR] (mdbook::utils): Caused By: The "mdbook-wordcount" renderer failed
```
As you've probably already noticed, output from the plugin's subprocess is
immediately passed through to the user. It is encouraged for plugins to follow
the "rule of silence" and only generate output when necessary (e.g. an error in
generation or a warning).
All environment variables are passed through to the backend, allowing you to use
the usual `RUST_LOG` to control logging verbosity.
## Wrapping Up
Although contrived, hopefully this example was enough to show how you'd create
an alternative backend for `mdbook`. If you feel it's missing something, don't
hesitate to create an issue in the [issue tracker] so we can improve the user
guide.
The existing backends mentioned towards the start of this chapter should serve
as a good example of how it's done in real life, so feel free to skim through
the source code or ask questions.
[Third Party Plugins]: https://github.com/rust-lang/mdBook/wiki/Third-party-plugins
[`RenderContext`]: https://docs.rs/mdbook/*/mdbook/renderer/struct.RenderContext.html
[`RenderContext::from_json()`]: https://docs.rs/mdbook/*/mdbook/renderer/struct.RenderContext.html#method.from_json
[`semver`]: https://crates.io/crates/semver
[`Book`]: https://docs.rs/mdbook/*/mdbook/book/struct.Book.html
[`Book::iter()`]: https://docs.rs/mdbook/*/mdbook/book/struct.Book.html#method.iter
[`Config`]: https://docs.rs/mdbook/*/mdbook/config/struct.Config.html
[issue tracker]: https://github.com/rust-lang/mdBook/issues

View File

@@ -0,0 +1,9 @@
[package]
name = "mdbook-wordcount"
version = "0.1.0"
authors = ["Michael Bryan <michaelfbryan@gmail.com>"]
[dependencies]
mdbook = { path = "../../../..", version = "*" }
serde = "1.0"
serde_derive = "1.0"

View File

@@ -0,0 +1,49 @@
extern crate mdbook;
extern crate serde;
#[macro_use]
extern crate serde_derive;
use std::process;
use std::fs::{self, File};
use std::io::{self, Write};
use mdbook::renderer::RenderContext;
use mdbook::book::{BookItem, Chapter};
fn main() {
let mut stdin = io::stdin();
let ctx = RenderContext::from_json(&mut stdin).unwrap();
let cfg: WordcountConfig = ctx.config
.get_deserialized("output.wordcount")
.unwrap_or_default();
let _ = fs::create_dir_all(&ctx.destination);
let mut f = File::create(ctx.destination.join("wordcounts.txt")).unwrap();
for item in ctx.book.iter() {
if let BookItem::Chapter(ref ch) = *item {
if cfg.ignores.contains(&ch.name) {
continue;
}
let num_words = count_words(ch);
println!("{}: {}", ch.name, num_words);
writeln!(f, "{}: {}", ch.name, num_words).unwrap();
if cfg.deny_odds && num_words % 2 == 1 {
eprintln!("{} has an odd number of words!", ch.name);
process::exit(1);
}
}
}
}
fn count_words(ch: &Chapter) -> usize {
ch.content.split_whitespace().count()
}
#[derive(Debug, Default, Serialize, Deserialize)]
#[serde(default, rename_all = "kebab-case")]
pub struct WordcountConfig {
pub ignores: Vec<String>,
pub deny_odds: bool,
}

View File

@@ -0,0 +1,134 @@
# Preprocessors
A *preprocessor* is simply a bit of code which gets run immediately after the
book is loaded and before it gets rendered, allowing you to update and mutate
the book. Possible use cases are:
- Creating custom helpers like `\{{#include /path/to/file.md}}`
- Substituting in latex-style expressions (`$$ \frac{1}{3} $$`) with their
mathjax equivalents
See [Configuring Preprocessors](../format/configuration/preprocessors.md) for more information about using preprocessors.
## Hooking Into MDBook
MDBook uses a fairly simple mechanism for discovering third party plugins.
A new table is added to `book.toml` (e.g. `[preprocessor.foo]` for the `foo`
preprocessor) and then `mdbook` will try to invoke the `mdbook-foo` program as
part of the build process.
Once the preprocessor has been defined and the build process starts, mdBook executes the command defined in the `preprocessor.foo.command` key twice.
The first time it runs the preprocessor to determine if it supports the given renderer.
mdBook passes two arguments to the process: the first argument is the string `supports` and the second argument is the renderer name.
The preprocessor should exit with a status code 0 if it supports the given renderer, or return a non-zero exit code if it does not.
If the preprocessor supports the renderer, then mdbook runs it a second time, passing JSON data into stdin.
The JSON consists of an array of `[context, book]` where `context` is the serialized object [`PreprocessorContext`] and `book` is a [`Book`] object containing the content of the book.
The preprocessor should return the JSON format of the [`Book`] object to stdout, with any modifications it wishes to perform.
The easiest way to get started is by creating your own implementation of the
`Preprocessor` trait (e.g. in `lib.rs`) and then creating a shell binary which
translates inputs to the correct `Preprocessor` method. For convenience, there
is [an example no-op preprocessor] in the `examples/` directory which can easily
be adapted for other preprocessors.
<details>
<summary>Example no-op preprocessor</summary>
```rust
// nop-preprocessors.rs
{{#include ../../../examples/nop-preprocessor.rs}}
```
</details>
## Hints For Implementing A Preprocessor
By pulling in `mdbook` as a library, preprocessors can have access to the
existing infrastructure for dealing with books.
For example, a custom preprocessor could use the
[`CmdPreprocessor::parse_input()`] function to deserialize the JSON written to
`stdin`. Then each chapter of the `Book` can be mutated in-place via
[`Book::for_each_mut()`], and then written to `stdout` with the `serde_json`
crate.
Chapters can be accessed either directly (by recursively iterating over
chapters) or via the `Book::for_each_mut()` convenience method.
The `chapter.content` is just a string which happens to be markdown. While it's
entirely possible to use regular expressions or do a manual find & replace,
you'll probably want to process the input into something more computer-friendly.
The [`pulldown-cmark`][pc] crate implements a production-quality event-based
Markdown parser, with the [`pulldown-cmark-to-cmark`][pctc] crate allowing you to
translate events back into markdown text.
The following code block shows how to remove all emphasis from markdown,
without accidentally breaking the document.
```rust
fn remove_emphasis(
num_removed_items: &mut usize,
chapter: &mut Chapter,
) -> Result<String> {
let mut buf = String::with_capacity(chapter.content.len());
let events = Parser::new(&chapter.content).filter(|e| {
let should_keep = match *e {
Event::Start(Tag::Emphasis)
| Event::Start(Tag::Strong)
| Event::End(Tag::Emphasis)
| Event::End(Tag::Strong) => false,
_ => true,
};
if !should_keep {
*num_removed_items += 1;
}
should_keep
});
cmark(events, &mut buf, None).map(|_| buf).map_err(|err| {
Error::from(format!("Markdown serialization failed: {}", err))
})
}
```
For everything else, have a look [at the complete example][example].
## Implementing a preprocessor with a different language
The fact that mdBook utilizes stdin and stdout to communicate with the preprocessors makes it easy to implement them in a language other than Rust.
The following code shows how to implement a simple preprocessor in Python, which will modify the content of the first chapter.
The example below follows the configuration shown above with `preprocessor.foo.command` actually pointing to a Python script.
```python
import json
import sys
if __name__ == '__main__':
if len(sys.argv) > 1: # we check if we received any argument
if sys.argv[1] == "supports":
# then we are good to return an exit status code of 0, since the other argument will just be the renderer's name
sys.exit(0)
# load both the context and the book representations from stdin
context, book = json.load(sys.stdin)
# and now, we can just modify the content of the first chapter
book['sections'][0]['Chapter']['content'] = '# Hello'
# we are done with the book's modification, we can just print it to stdout,
print(json.dumps(book))
```
[preprocessor-docs]: https://docs.rs/mdbook/latest/mdbook/preprocess/trait.Preprocessor.html
[pc]: https://crates.io/crates/pulldown-cmark
[pctc]: https://crates.io/crates/pulldown-cmark-to-cmark
[example]: https://github.com/rust-lang/mdBook/blob/master/examples/nop-preprocessor.rs
[an example no-op preprocessor]: https://github.com/rust-lang/mdBook/blob/master/examples/nop-preprocessor.rs
[`CmdPreprocessor::parse_input()`]: https://docs.rs/mdbook/latest/mdbook/preprocess/trait.Preprocessor.html#method.parse_input
[`Book::for_each_mut()`]: https://docs.rs/mdbook/latest/mdbook/book/struct.Book.html#method.for_each_mut
[`PreprocessorContext`]: https://docs.rs/mdbook/latest/mdbook/preprocess/struct.PreprocessorContext.html
[`Book`]: https://docs.rs/mdbook/latest/mdbook/book/struct.Book.html

View File

@@ -4,5 +4,5 @@ In this section you will learn how to:
- Structure your book correctly
- Format your `SUMMARY.md` file
- Configure your book using `book.json`
- Configure your book using `book.toml`
- Customize your theme

View File

@@ -0,0 +1,12 @@
# Configuration
This section details the configuration options available in the ***book.toml***:
- **[General]** configuration including the `book`, `rust`, `build` sections
- **[Preprocessor]** configuration for default and custom book preprocessors
- **[Renderer]** configuration for the HTML, Markdown and custom renderers
- **[Environment Variable]** configuration for overriding configuration options in your environment
[General]: general.md
[Preprocessor]: preprocessors.md
[Renderer]: renderers.md
[Environment Variable]: environment-variables.md

View File

@@ -0,0 +1,38 @@
# Environment Variables
All configuration values can be overridden from the command line by setting the
corresponding environment variable. Because many operating systems restrict
environment variables to be alphanumeric characters or `_`, the configuration
key needs to be formatted slightly differently to the normal `foo.bar.baz` form.
Variables starting with `MDBOOK_` are used for configuration. The key is created
by removing the `MDBOOK_` prefix and turning the resulting string into
`kebab-case`. Double underscores (`__`) separate nested keys, while a single
underscore (`_`) is replaced with a dash (`-`).
For example:
- `MDBOOK_foo` -> `foo`
- `MDBOOK_FOO` -> `foo`
- `MDBOOK_FOO__BAR` -> `foo.bar`
- `MDBOOK_FOO_BAR` -> `foo-bar`
- `MDBOOK_FOO_bar__baz` -> `foo-bar.baz`
So by setting the `MDBOOK_BOOK__TITLE` environment variable you can override the
book's title without needing to touch your `book.toml`.
> **Note:** To facilitate setting more complex config items, the value of an
> environment variable is first parsed as JSON, falling back to a string if the
> parse fails.
>
> This means, if you so desired, you could override all book metadata when
> building the book with something like
>
> ```shell
> $ export MDBOOK_BOOK='{"title": "My Awesome Book", "authors": ["Michael-F-Bryan"]}'
> $ mdbook build
> ```
The latter case may be useful in situations where `mdbook` is invoked from a
script or CI, where it sometimes isn't possible to update the `book.toml` before
building.

View File

@@ -0,0 +1,114 @@
# General Configuration
You can configure the parameters for your book in the ***book.toml*** file.
Here is an example of what a ***book.toml*** file might look like:
```toml
[book]
title = "Example book"
authors = ["John Doe"]
description = "The example book covers examples."
[rust]
edition = "2018"
[build]
build-dir = "my-example-book"
create-missing = false
[preprocessor.index]
[preprocessor.links]
[output.html]
additional-css = ["custom.css"]
[output.html.search]
limit-results = 15
```
## Supported configuration options
It is important to note that **any** relative path specified in the
configuration will always be taken relative from the root of the book where the
configuration file is located.
### General metadata
This is general information about your book.
- **title:** The title of the book
- **authors:** The author(s) of the book
- **description:** A description for the book, which is added as meta
information in the html `<head>` of each page
- **src:** By default, the source directory is found in the directory named
`src` directly under the root folder. But this is configurable with the `src`
key in the configuration file.
- **language:** The main language of the book, which is used as a language attribute `<html lang="en">` for example.
**book.toml**
```toml
[book]
title = "Example book"
authors = ["John Doe", "Jane Doe"]
description = "The example book covers examples."
src = "my-src" # the source files will be found in `root/my-src` instead of `root/src`
language = "en"
```
### Rust options
Options for the Rust language, relevant to running tests and playground
integration.
```toml
[rust]
edition = "2015" # the default edition for code blocks
```
- **edition**: Rust edition to use by default for the code snippets. Default
is "2015". Individual code blocks can be controlled with the `edition2015`,
`edition2018` or `edition2021` annotations, such as:
~~~text
```rust,edition2015
// This only works in 2015.
let try = true;
```
~~~
### Build options
This controls the build process of your book.
```toml
[build]
build-dir = "book" # the directory where the output is placed
create-missing = true # whether or not to create missing pages
use-default-preprocessors = true # use the default preprocessors
extra-watch-dirs = [] # directories to watch for triggering builds
```
- **build-dir:** The directory to put the rendered book in. By default this is
`book/` in the book's root directory.
This can overridden with the `--dest-dir` CLI option.
- **create-missing:** By default, any missing files specified in `SUMMARY.md`
will be created when the book is built (i.e. `create-missing = true`). If this
is `false` then the build process will instead exit with an error if any files
do not exist.
- **use-default-preprocessors:** Disable the default preprocessors of (`links` &
`index`) by setting this option to `false`.
If you have the same, and/or other preprocessors declared via their table
of configuration, they will run instead.
- For clarity, with no preprocessor configuration, the default `links` and
`index` will run.
- Setting `use-default-preprocessors = false` will disable these
default preprocessors from running.
- Adding `[preprocessor.links]`, for example, will ensure, regardless of
`use-default-preprocessors` that `links` it will run.
- **extra-watch-dirs**: A list of paths to directories that will be watched in
the `watch` and `serve` commands. Changes to files under these directories will
trigger rebuilds. Useful if your book depends on files outside its `src` directory.

View File

@@ -0,0 +1,87 @@
# Configuring Preprocessors
Preprocessors are extensions that can modify the raw Markdown source before it gets sent to the renderer.
The following preprocessors are built-in and included by default:
- `links`: Expands the `{{ #playground }}`, `{{ #include }}`, and `{{ #rustdoc_include }}` handlebars
helpers in a chapter to include the contents of a file.
See [Including files] for more.
- `index`: Convert all chapter files named `README.md` into `index.md`. That is
to say, all `README.md` would be rendered to an index file `index.html` in the
rendered book.
The built-in preprocessors can be disabled with the [`build.use-default-preprocessors`] config option.
The community has developed several preprocessors.
See the [Third Party Plugins] wiki page for a list of available preprocessors.
For information on how to create a new preprocessor, see the [Preprocessors for Developers] chapter.
[Including files]: ../mdbook.md#including-files
[`build.use-default-preprocessors`]: general.md#build-options
[Third Party Plugins]: https://github.com/rust-lang/mdBook/wiki/Third-party-plugins
[Preprocessors for Developers]: ../../for_developers/preprocessors.md
## Custom Preprocessor Configuration
Preprocessors can be added by including a `preprocessor` table in `book.toml` with the name of the preprocessor.
For example, if you have a preprocessor called `mdbook-example`, then you can include it with:
```toml
[preprocessor.example]
```
With this table, mdBook will execute the `mdbook-example` preprocessor.
This table can include additional key-value pairs that are specific to the preprocessor.
For example, if our example prepocessor needed some extra configuration options:
```toml
[preprocessor.example]
some-extra-feature = true
```
## Locking a Preprocessor dependency to a renderer
You can explicitly specify that a preprocessor should run for a renderer by
binding the two together.
```toml
[preprocessor.example]
renderers = ["html"] # example preprocessor only runs with the HTML renderer
```
## Provide Your Own Command
By default when you add a `[preprocessor.foo]` table to your `book.toml` file,
`mdbook` will try to invoke the `mdbook-foo` executable. If you want to use a
different program name or pass in command-line arguments, this behaviour can
be overridden by adding a `command` field.
```toml
[preprocessor.random]
command = "python random.py"
```
## Require A Certain Order
The order in which preprocessors are run can be controlled with the `before` and `after` fields.
For example, suppose you want your `linenos` preprocessor to process lines that may have been `{{#include}}`d; then you want it to run after the built-in `links` preprocessor, which you can require using either the `before` or `after` field:
```toml
[preprocessor.linenos]
after = [ "links" ]
```
or
```toml
[preprocessor.links]
before = [ "linenos" ]
```
It would also be possible, though redundant, to specify both of the above in the same config file.
Preprocessors having the same priority specified through `before` and `after` are sorted by name.
Any infinite loops will be detected and produce an error.

View File

@@ -0,0 +1,303 @@
# Configuring Renderers
Renderers (also called "backends") are responsible for creating the output of the book.
The following backends are built-in:
* [`html`](#html-renderer-options) — This renders the book to HTML.
This is enabled by default if no other `[output]` tables are defined in `book.toml`.
* [`markdown`](#markdown-renderer) — This outputs the book as markdown after running the preprocessors.
This is useful for debugging preprocessors.
The community has developed several backends.
See the [Third Party Plugins] wiki page for a list of available backends.
For information on how to create a new backend, see the [Backends for Developers] chapter.
[Third Party Plugins]: https://github.com/rust-lang/mdBook/wiki/Third-party-plugins
[Backends for Developers]: ../../for_developers/backends.md
## Output tables
Backends can be added by including a `output` table in `book.toml` with the name of the backend.
For example, if you have a backend called `mdbook-wordcount`, then you can include it with:
```toml
[output.wordcount]
```
With this table, mdBook will execute the `mdbook-wordcount` backend.
This table can include additional key-value pairs that are specific to the backend.
For example, if our example backend needed some extra configuration options:
```toml
[output.wordcount]
ignores = ["Example Chapter"]
```
If you define any `[output]` tables, then the `html` backend is not enabled by default.
If you want to keep the `html` backend running, then just include it in the `book.toml` file.
For example:
```toml
[book]
title = "My Awesome Book"
[output.wordcount]
[output.html]
```
If more than one `output` table is included, this changes the behavior for the layout of the output directory.
If there is only one backend, then it places its output directly in the `book` directory (see [`build.build-dir`] to override this location).
If there is more than one backend, then each backend is placed in a separate directory underneath `book`.
For example, the above would have directories `book/html` and `book/wordcount`.
[`build.build-dir`]: general.md#build-options
### Custom backend commands
By default when you add an `[output.foo]` table to your `book.toml` file,
`mdbook` will try to invoke the `mdbook-foo` executable.
If you want to use a different program name or pass in command-line arguments,
this behaviour can be overridden by adding a `command` field.
```toml
[output.random]
command = "python random.py"
```
### Optional backends
If you enable a backend that isn't installed, the default behavior is to throw an error.
This behavior can be changed by marking the backend as optional:
```toml
[output.wordcount]
optional = true
```
This demotes the error to a warning.
## HTML renderer options
The HTML renderer has a variety of options detailed below.
They should be specified in the `[output.html]` table of the `book.toml` file.
```toml
# Example book.toml file with all output options.
[book]
title = "Example book"
authors = ["John Doe", "Jane Doe"]
description = "The example book covers examples."
[output.html]
theme = "my-theme"
default-theme = "light"
preferred-dark-theme = "navy"
curly-quotes = true
mathjax-support = false
copy-fonts = true
additional-css = ["custom.css", "custom2.css"]
additional-js = ["custom.js"]
no-section-label = false
git-repository-url = "https://github.com/rust-lang/mdBook"
git-repository-icon = "fa-github"
edit-url-template = "https://github.com/rust-lang/mdBook/edit/master/guide/{path}"
site-url = "/example-book/"
cname = "myproject.rs"
input-404 = "not-found.md"
```
The following configuration options are available:
- **theme:** mdBook comes with a default theme and all the resource files needed
for it. But if this option is set, mdBook will selectively overwrite the theme
files with the ones found in the specified folder.
- **default-theme:** The theme color scheme to select by default in the
'Change Theme' dropdown. Defaults to `light`.
- **preferred-dark-theme:** The default dark theme. This theme will be used if
the browser requests the dark version of the site via the
['prefers-color-scheme'](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme)
CSS media query. Defaults to `navy`.
- **curly-quotes:** Convert straight quotes to curly quotes, except for those
that occur in code blocks and code spans. Defaults to `false`.
- **mathjax-support:** Adds support for [MathJax](../mathjax.md). Defaults to
`false`.
- **copy-fonts:** (**Deprecated**) If `true` (the default), mdBook uses its built-in fonts which are copied to the output directory.
If `false`, the built-in fonts will not be used.
This option is deprecated. If you want to define your own custom fonts,
create a `theme/fonts/fonts.css` file and store the fonts in the `theme/fonts/` directory.
- **google-analytics:** This field has been deprecated and will be removed in a future release.
Use the `theme/head.hbs` file to add the appropriate Google Analytics code instead.
- **additional-css:** If you need to slightly change the appearance of your book
without overwriting the whole style, you can specify a set of stylesheets that
will be loaded after the default ones where you can surgically change the
style.
- **additional-js:** If you need to add some behaviour to your book without
removing the current behaviour, you can specify a set of JavaScript files that
will be loaded alongside the default one.
- **no-section-label:** mdBook by defaults adds numeric section labels in the table of
contents column. For example, "1.", "2.1". Set this option to true to disable
those labels. Defaults to `false`.
- **git-repository-url:** A url to the git repository for the book. If provided
an icon link will be output in the menu bar of the book.
- **git-repository-icon:** The FontAwesome icon class to use for the git
repository link. Defaults to `fa-github` which looks like <i class="fa fa-github"></i>.
If you are not using GitHub, another option to consider is `fa-code-fork` which looks like <i class="fa fa-code-fork"></i>.
- **edit-url-template:** Edit url template, when provided shows a
"Suggest an edit" button (which looks like <i class="fa fa-edit"></i>) for directly jumping to editing the currently
viewed page. For e.g. GitHub projects set this to
`https://github.com/<owner>/<repo>/edit/master/{path}` or for
Bitbucket projects set it to
`https://bitbucket.org/<owner>/<repo>/src/master/{path}?mode=edit`
where {path} will be replaced with the full path of the file in the
repository.
- **input-404:** The name of the markdown file used for missing files.
The corresponding output file will be the same, with the extension replaced with `html`.
Defaults to `404.md`.
- **site-url:** The url where the book will be hosted. This is required to ensure
navigation links and script/css imports in the 404 file work correctly, even when accessing
urls in subdirectories. Defaults to `/`. If `site-url` is set,
make sure to use document relative links for your assets, meaning they should not start with `/`.
- **cname:** The DNS subdomain or apex domain at which your book will be hosted.
This string will be written to a file named CNAME in the root of your site, as
required by GitHub Pages (see [*Managing a custom domain for your GitHub Pages
site*][custom domain]).
[custom domain]: https://docs.github.com/en/github/working-with-github-pages/managing-a-custom-domain-for-your-github-pages-site
### `[output.html.print]`
The `[output.html.print]` table provides options for controlling the printable output.
By default, mdBook will include an icon on the top right of the book (which looks like <i class="fa fa-print"></i>) that will print the book as a single page.
```toml
[output.html.print]
enable = true # include support for printable output
page-break = true # insert page-break after each chapter
```
- **enable:** Enable print support. When `false`, all print support will not be
rendered. Defaults to `true`.
- **page-break** Insert page breaks between chapters. Defaults to `true`.
### `[output.html.fold]`
The `[output.html.fold]` table provides options for controlling folding of the chapter listing in the navigation sidebar.
```toml
[output.html.fold]
enable = false # whether or not to enable section folding
level = 0 # the depth to start folding
```
- **enable:** Enable section-folding. When off, all folds are open.
Defaults to `false`.
- **level:** The higher the more folded regions are open. When level is 0, all
folds are closed. Defaults to `0`.
### `[output.html.playground]`
The `[output.html.playground]` table provides options for controlling Rust sample code blocks, and their integration with the [Rust Playground].
[Rust Playground]: https://play.rust-lang.org/
```toml
[output.html.playground]
editable = false # allows editing the source code
copyable = true # include the copy button for copying code snippets
copy-js = true # includes the JavaScript for the code editor
line-numbers = false # displays line numbers for editable code
runnable = true # displays a run button for rust code
```
- **editable:** Allow editing the source code. Defaults to `false`.
- **copyable:** Display the copy button on code snippets. Defaults to `true`.
- **copy-js:** Copy JavaScript files for the editor to the output directory.
Defaults to `true`.
- **line-numbers** Display line numbers on editable sections of code. Requires both `editable` and `copy-js` to be `true`. Defaults to `false`.
- **runnable** Displays a run button for rust code snippets. Changing this to `false` will disable the run in playground feature globally. Defaults to `true`.
[Ace]: https://ace.c9.io/
### `[output.html.search]`
The `[output.html.search]` table provides options for controlling the built-in text [search].
mdBook must be compiled with the `search` feature enabled (on by default).
[search]: ../../guide/reading.md#search
```toml
[output.html.search]
enable = true # enables the search feature
limit-results = 30 # maximum number of search results
teaser-word-count = 30 # number of words used for a search result teaser
use-boolean-and = true # multiple search terms must all match
boost-title = 2 # ranking boost factor for matches in headers
boost-hierarchy = 1 # ranking boost factor for matches in page names
boost-paragraph = 1 # ranking boost factor for matches in text
expand = true # partial words will match longer terms
heading-split-level = 3 # link results to heading levels
copy-js = true # include Javascript code for search
```
- **enable:** Enables the search feature. Defaults to `true`.
- **limit-results:** The maximum number of search results. Defaults to `30`.
- **teaser-word-count:** The number of words used for a search result teaser.
Defaults to `30`.
- **use-boolean-and:** Define the logical link between multiple search words. If
true, all search words must appear in each result. Defaults to `false`.
- **boost-title:** Boost factor for the search result score if a search word
appears in the header. Defaults to `2`.
- **boost-hierarchy:** Boost factor for the search result score if a search word
appears in the hierarchy. The hierarchy contains all titles of the parent
documents and all parent headings. Defaults to `1`.
- **boost-paragraph:** Boost factor for the search result score if a search word
appears in the text. Defaults to `1`.
- **expand:** True if search should match longer results e.g. search `micro`
should match `microwave`. Defaults to `true`.
- **heading-split-level:** Search results will link to a section of the document
which contains the result. Documents are split into sections by headings this
level or less. Defaults to `3`. (`### This is a level 3 heading`)
- **copy-js:** Copy JavaScript files for the search implementation to the output
directory. Defaults to `true`.
### `[output.html.redirect]`
The `[output.html.redirect]` table provides a way to add redirects.
This is useful when you move, rename, or remove a page to ensure that links to the old URL will go to the new location.
```toml
[output.html.redirect]
"/appendices/bibliography.html" = "https://rustc-dev-guide.rust-lang.org/appendix/bibliography.html"
"/other-installation-methods.html" = "../infra/other-installation-methods.html"
```
The table contains key-value pairs where the key is where the redirect file needs to be created, as an absolute path from the build directory, (e.g. `/appendices/bibliography.html`).
The value can be any valid URI the browser should navigate to (e.g. `https://rust-lang.org/`, `/overview.html`, or `../bibliography.html`).
This will generate an HTML page which will automatically redirect to the given location.
Note that the source location does not support `#` anchor redirects.
## Markdown Renderer
The Markdown renderer will run preprocessors and then output the resulting
Markdown. This is mostly useful for debugging preprocessors, especially in
conjunction with `mdbook test` to see the Markdown that `mdbook` is passing
to `rustdoc`.
The Markdown renderer is included with `mdbook` but disabled by default.
Enable it by adding an empty table to your `book.toml` as follows:
```toml
[output.markdown]
```
There are no configuration options for the Markdown renderer at this time;
only whether it is enabled or disabled.
See [the preprocessors documentation](preprocessors.md) for how to
specify which preprocessors should run before the Markdown renderer.

View File

@@ -0,0 +1,6 @@
fn main() {
println!("Hello World!");
#
# // You can even hide lines! :D
# println!("I am hidden! Expand the code snippet to see me");
}

View File

@@ -0,0 +1 @@
<svg height="144" width="144" xmlns="http://www.w3.org/2000/svg"><path d="m71.05 23.68c-26.06 0-47.27 21.22-47.27 47.27s21.22 47.27 47.27 47.27 47.27-21.22 47.27-47.27-21.22-47.27-47.27-47.27zm-.07 4.2a3.1 3.11 0 0 1 3.02 3.11 3.11 3.11 0 0 1 -6.22 0 3.11 3.11 0 0 1 3.2-3.11zm7.12 5.12a38.27 38.27 0 0 1 26.2 18.66l-3.67 8.28c-.63 1.43.02 3.11 1.44 3.75l7.06 3.13a38.27 38.27 0 0 1 .08 6.64h-3.93c-.39 0-.55.26-.55.64v1.8c0 4.24-2.39 5.17-4.49 5.4-2 .23-4.21-.84-4.49-2.06-1.18-6.63-3.14-8.04-6.24-10.49 3.85-2.44 7.85-6.05 7.85-10.87 0-5.21-3.57-8.49-6-10.1-3.42-2.25-7.2-2.7-8.22-2.7h-40.6a38.27 38.27 0 0 1 21.41-12.08l4.79 5.02c1.08 1.13 2.87 1.18 4 .09zm-44.2 23.02a3.11 3.11 0 0 1 3.02 3.11 3.11 3.11 0 0 1 -6.22 0 3.11 3.11 0 0 1 3.2-3.11zm74.15.14a3.11 3.11 0 0 1 3.02 3.11 3.11 3.11 0 0 1 -6.22 0 3.11 3.11 0 0 1 3.2-3.11zm-68.29.5h5.42v24.44h-10.94a38.27 38.27 0 0 1 -1.24-14.61l6.7-2.98c1.43-.64 2.08-2.31 1.44-3.74zm22.62.26h12.91c.67 0 4.71.77 4.71 3.8 0 2.51-3.1 3.41-5.65 3.41h-11.98zm0 17.56h9.89c.9 0 4.83.26 6.08 5.28.39 1.54 1.26 6.56 1.85 8.17.59 1.8 2.98 5.4 5.53 5.4h16.14a38.27 38.27 0 0 1 -3.54 4.1l-6.57-1.41c-1.53-.33-3.04.65-3.37 2.18l-1.56 7.28a38.27 38.27 0 0 1 -31.91-.15l-1.56-7.28c-.33-1.53-1.83-2.51-3.36-2.18l-6.43 1.38a38.27 38.27 0 0 1 -3.32-3.92h31.27c.35 0 .59-.06.59-.39v-11.06c0-.32-.24-.39-.59-.39h-9.15zm-14.43 25.33a3.11 3.11 0 0 1 3.02 3.11 3.11 3.11 0 0 1 -6.22 0 3.11 3.11 0 0 1 3.2-3.11zm46.05.14a3.11 3.11 0 0 1 3.02 3.11 3.11 3.11 0 0 1 -6.22 0 3.11 3.11 0 0 1 3.2-3.11z"/><path d="m115.68 70.95a44.63 44.63 0 0 1 -44.63 44.63 44.63 44.63 0 0 1 -44.63-44.63 44.63 44.63 0 0 1 44.63-44.63 44.63 44.63 0 0 1 44.63 44.63zm-.84-4.31 6.96 4.31-6.96 4.31 5.98 5.59-7.66 2.87 4.78 6.65-8.09 1.32 3.4 7.46-8.19-.29 1.88 7.98-7.98-1.88.29 8.19-7.46-3.4-1.32 8.09-6.65-4.78-2.87 7.66-5.59-5.98-4.31 6.96-4.31-6.96-5.59 5.98-2.87-7.66-6.65 4.78-1.32-8.09-7.46 3.4.29-8.19-7.98 1.88 1.88-7.98-8.19.29 3.4-7.46-8.09-1.32 4.78-6.65-7.66-2.87 5.98-5.59-6.96-4.31 6.96-4.31-5.98-5.59 7.66-2.87-4.78-6.65 8.09-1.32-3.4-7.46 8.19.29-1.88-7.98 7.98 1.88-.29-8.19 7.46 3.4 1.32-8.09 6.65 4.78 2.87-7.66 5.59 5.98 4.31-6.96 4.31 6.96 5.59-5.98 2.87 7.66 6.65-4.78 1.32 8.09 7.46-3.4-.29 8.19 7.98-1.88-1.88 7.98 8.19-.29-3.4 7.46 8.09 1.32-4.78 6.65 7.66 2.87z" fill-rule="evenodd" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="3"/></svg>

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@@ -0,0 +1,222 @@
# Markdown
mdBook's [parser](https://github.com/raphlinus/pulldown-cmark) adheres to the [CommonMark](https://commonmark.org/) specification with some extensions described below.
You can take a quick [tutorial](https://commonmark.org/help/tutorial/),
or [try out](https://spec.commonmark.org/dingus/) CommonMark in real time. A complete Markdown overview is out of scope for
this documentation, but below is a high level overview of some of the basics. For a more in-depth experience, check out the
[Markdown Guide](https://www.markdownguide.org).
## Text and Paragraphs
Text is rendered relatively predictably:
```markdown
Here is a line of text.
This is a new line.
```
Will look like you might expect:
Here is a line of text.
This is a new line.
## Headings
Headings use the `#` marker and should be on a line by themselves. More `#` mean smaller headings:
```markdown
### A heading
Some text.
#### A smaller heading
More text.
```
### A heading
Some text.
#### A smaller heading
More text.
## Lists
Lists can be unordered or ordered. Ordered lists will order automatically:
```markdown
* milk
* eggs
* butter
1. carrots
1. celery
1. radishes
```
* milk
* eggs
* butter
1. carrots
1. celery
1. radishes
## Links
Linking to a URL or local file is easy:
```markdown
Use [mdBook](https://github.com/rust-lang/mdBook).
Read about [mdBook](mdBook.md).
A bare url: <https://www.rust-lang.org>.
```
Use [mdBook](https://github.com/rust-lang/mdBook).
Read about [mdBook](mdBook.md).
A bare url: <https://www.rust-lang.org>.
----
Relative links that end with `.md` will be converted to the `.html` extension.
It is recommended to use `.md` links when possible.
This is useful when viewing the Markdown file outside of mdBook, for example on GitHub or GitLab which render Markdown automatically.
Links to `README.md` will be converted to `index.html`.
This is done since some services like GitHub render README files automatically, but web servers typically expect the root file to be called `index.html`.
You can link to individual headings with `#` fragments.
For example, `mdbook.md#text-and-paragraphs` would link to the [Text and Paragraphs](#text-and-paragraphs) section above.
The ID is created by transforming the heading such as converting to lowercase and replacing spaces with dashes.
You can click on any heading and look at the URL in your browser to see what the fragment looks like.
## Images
Including images is simply a matter of including a link to them, much like in the _Links_ section above. The following markdown
includes the Rust logo SVG image found in the `images` directory at the same level as this file:
```markdown
![The Rust Logo](images/rust-logo-blk.svg)
```
Produces the following HTML when built with mdBook:
```html
<p><img src="images/rust-logo-blk.svg" alt="The Rust Logo" /></p>
```
Which, of course displays the image like so:
![The Rust Logo](images/rust-logo-blk.svg)
## Extensions
mdBook has several extensions beyond the standard CommonMark specification.
### Strikethrough
Text may be rendered with a horizontal line through the center by wrapping the
text with two tilde characters on each side:
```text
An example of ~~strikethrough text~~.
```
This example will render as:
> An example of ~~strikethrough text~~.
This follows the [GitHub Strikethrough extension][strikethrough].
### Footnotes
A footnote generates a small numbered link in the text which when clicked
takes the reader to the footnote text at the bottom of the item. The footnote
label is written similarly to a link reference with a caret at the front. The
footnote text is written like a link reference definition, with the text
following the label. Example:
```text
This is an example of a footnote[^note].
[^note]: This text is the contents of the footnote, which will be rendered
towards the bottom.
```
This example will render as:
> This is an example of a footnote[^note].
>
> [^note]: This text is the contents of the footnote, which will be rendered
> towards the bottom.
The footnotes are automatically numbered based on the order the footnotes are
written.
### Tables
Tables can be written using pipes and dashes to draw the rows and columns of
the table. These will be translated to HTML table matching the shape. Example:
```text
| Header1 | Header2 |
|---------|---------|
| abc | def |
```
This example will render similarly to this:
| Header1 | Header2 |
|---------|---------|
| abc | def |
See the specification for the [GitHub Tables extension][tables] for more
details on the exact syntax supported.
### Task lists
Task lists can be used as a checklist of items that have been completed.
Example:
```md
- [x] Complete task
- [ ] Incomplete task
```
This will render as:
> - [x] Complete task
> - [ ] Incomplete task
See the specification for the [task list extension] for more details.
### Smart punctuation
Some ASCII punctuation sequences will be automatically turned into fancy Unicode
characters:
| ASCII sequence | Unicode |
|----------------|---------|
| `--` | |
| `---` | — |
| `...` | … |
| `"` | “ or ”, depending on context |
| `'` | or , depending on context |
So, no need to manually enter those Unicode characters!
This feature is disabled by default.
To enable it, see the [`output.html.curly-quotes`] config option.
[strikethrough]: https://github.github.com/gfm/#strikethrough-extension-
[tables]: https://github.github.com/gfm/#tables-extension-
[task list extension]: https://github.github.com/gfm/#task-list-items-extension-
[`output.html.curly-quotes`]: configuration/renderers.md#html-renderer-options

View File

@@ -0,0 +1,43 @@
# MathJax Support
mdBook has optional support for math equations through
[MathJax](https://www.mathjax.org/).
To enable MathJax, you need to add the `mathjax-support` key to your `book.toml`
under the `output.html` section.
```toml
[output.html]
mathjax-support = true
```
>**Note:** The usual delimiters MathJax uses are not yet supported. You can't
currently use `$$ ... $$` as delimiters and the `\[ ... \]` delimiters need an
extra backslash to work. Hopefully this limitation will be lifted soon.
>**Note:** When you use double backslashes in MathJax blocks (for example in
> commands such as `\begin{cases} \frac 1 2 \\ \frac 3 4 \end{cases}`) you need
> to add _two extra_ backslashes (e.g., `\begin{cases} \frac 1 2 \\\\ \frac 3 4
> \end{cases}`).
### Inline equations
Inline equations are delimited by `\\(` and `\\)`. So for example, to render the
following inline equation \\( \int x dx = \frac{x^2}{2} + C \\) you would write
the following:
```
\\( \int x dx = \frac{x^2}{2} + C \\)
```
### Block equations
Block equations are delimited by `\\[` and `\\]`. To render the following
equation
\\[ \mu = \frac{1}{N} \sum_{i=0} x_i \\]
you would write:
```bash
\\[ \mu = \frac{1}{N} \sum_{i=0} x_i \\]
```

276
guide/src/format/mdbook.md Normal file
View File

@@ -0,0 +1,276 @@
# mdBook-specific features
## Hiding code lines
There is a feature in mdBook that lets you hide code lines by prepending them
with a `#` [like you would with Rustdoc][rustdoc-hide].
This currently only works with Rust language code blocks.
[rustdoc-hide]: https://doc.rust-lang.org/stable/rustdoc/documentation-tests.html#hiding-portions-of-the-example
```bash
# fn main() {
let x = 5;
let y = 6;
println!("{}", x + y);
# }
```
Will render as
```rust
# fn main() {
let x = 5;
let y = 6;
println!("{}", x + y);
# }
```
The code block has an eyeball icon (<i class="fa fa-eye"></i>) which will toggle the visibility of the hidden lines.
## Rust Playground
Rust language code blocks will automatically get a play button (<i class="fa fa-play"></i>) which will execute the code and display the output just below the code block.
This works by sending the code to the [Rust Playground].
```rust
println!("Hello, World!");
```
If there is no `main` function, then the code is automatically wrapped inside one.
If you wish to disable the play button for a code block, you can include the `noplayground` option on the code block like this:
~~~markdown
```rust,noplayground
let mut name = String::new();
std::io::stdin().read_line(&mut name).expect("failed to read line");
println!("Hello {}!", name);
```
~~~
Or, if you wish to disable the play button for all code blocks in your book, you can write the config to the `book.toml` like this.
```toml
[output.html.playground]
runnable = false
```
## Rust code block attributes
Additional attributes can be included in Rust code blocks with comma, space, or tab-separated terms just after the language term. For example:
~~~markdown
```rust,ignore
# This example won't be tested.
panic!("oops!");
```
~~~
These are particularly important when using [`mdbook test`] to test Rust examples.
These use the same attributes as [rustdoc attributes], with a few additions:
* `editable` — Enables the [editor].
* `noplayground` — Removes the play button, but will still be tested.
* `mdbook-runnable` — Forces the play button to be displayed.
This is intended to be combined with the `ignore` attribute for examples that should not be tested, but you want to allow the reader to run.
* `ignore` — Will not be tested and no play button is shown, but it is still highlighted as Rust syntax.
* `should_panic` — When executed, it should produce a panic.
* `no_run` — The code is compiled when tested, but it is not run.
The play button is also not shown.
* `compile_fail` — The code should fail to compile.
* `edition2015`, `edition2018`, `edition2021` — Forces the use of a specific Rust edition.
See [`rust.edition`] to set this globally.
[`mdbook test`]: ../cli/test.md
[rustdoc attributes]: https://doc.rust-lang.org/rustdoc/documentation-tests.html#attributes
[editor]: theme/editor.md
[`rust.edition`]: configuration/general.md#rust-options
## Including files
With the following syntax, you can include files into your book:
```hbs
\{{#include file.rs}}
```
The path to the file has to be relative from the current source file.
mdBook will interpret included files as Markdown. Since the include command
is usually used for inserting code snippets and examples, you will often
wrap the command with ```` ``` ```` to display the file contents without
interpreting them.
````hbs
```
\{{#include file.rs}}
```
````
## Including portions of a file
Often you only need a specific part of the file, e.g. relevant lines for an
example. We support four different modes of partial includes:
```hbs
\{{#include file.rs:2}}
\{{#include file.rs::10}}
\{{#include file.rs:2:}}
\{{#include file.rs:2:10}}
```
The first command only includes the second line from file `file.rs`. The second
command includes all lines up to line 10, i.e. the lines from 11 till the end of
the file are omitted. The third command includes all lines from line 2, i.e. the
first line is omitted. The last command includes the excerpt of `file.rs`
consisting of lines 2 to 10.
To avoid breaking your book when modifying included files, you can also
include a specific section using anchors instead of line numbers.
An anchor is a pair of matching lines. The line beginning an anchor must
match the regex `ANCHOR:\s*[\w_-]+` and similarly the ending line must match
the regex `ANCHOR_END:\s*[\w_-]+`. This allows you to put anchors in
any kind of commented line.
Consider the following file to include:
```rs
/* ANCHOR: all */
// ANCHOR: component
struct Paddle {
hello: f32,
}
// ANCHOR_END: component
////////// ANCHOR: system
impl System for MySystem { ... }
////////// ANCHOR_END: system
/* ANCHOR_END: all */
```
Then in the book, all you have to do is:
````hbs
Here is a component:
```rust,no_run,noplayground
\{{#include file.rs:component}}
```
Here is a system:
```rust,no_run,noplayground
\{{#include file.rs:system}}
```
This is the full file.
```rust,no_run,noplayground
\{{#include file.rs:all}}
```
````
Lines containing anchor patterns inside the included anchor are ignored.
## Including a file but initially hiding all except specified lines
The `rustdoc_include` helper is for including code from external Rust files that contain complete
examples, but only initially showing particular lines specified with line numbers or anchors in the
same way as with `include`.
The lines not in the line number range or between the anchors will still be included, but they will
be prefaced with `#`. This way, a reader can expand the snippet to see the complete example, and
Rustdoc will use the complete example when you run `mdbook test`.
For example, consider a file named `file.rs` that contains this Rust program:
```rust
fn main() {
let x = add_one(2);
assert_eq!(x, 3);
}
fn add_one(num: i32) -> i32 {
num + 1
}
```
We can include a snippet that initially shows only line 2 by using this syntax:
````hbs
To call the `add_one` function, we pass it an `i32` and bind the returned value to `x`:
```rust
\{{#rustdoc_include file.rs:2}}
```
````
This would have the same effect as if we had manually inserted the code and hidden all but line 2
using `#`:
````hbs
To call the `add_one` function, we pass it an `i32` and bind the returned value to `x`:
```rust
# fn main() {
let x = add_one(2);
# assert_eq!(x, 3);
# }
#
# fn add_one(num: i32) -> i32 {
# num + 1
# }
```
````
That is, it looks like this (click the "expand" icon to see the rest of the file):
```rust
# fn main() {
let x = add_one(2);
# assert_eq!(x, 3);
# }
#
# fn add_one(num: i32) -> i32 {
# num + 1
# }
```
## Inserting runnable Rust files
With the following syntax, you can insert runnable Rust files into your book:
```hbs
\{{#playground file.rs}}
```
The path to the Rust file has to be relative from the current source file.
When play is clicked, the code snippet will be sent to the [Rust Playground] to be
compiled and run. The result is sent back and displayed directly underneath the
code.
Here is what a rendered code snippet looks like:
{{#playground example.rs}}
Any additional values passed after the filename will be included as attributes of the code block.
For example `\{{#playground example.rs editable}}` will create the code block like the following:
~~~markdown
```rust,editable
# Contents of example.rs here.
```
~~~
And the `editable` attribute will enable the [editor] as described at [Rust code block attributes](#rust-code-block-attributes).
[Rust Playground]: https://play.rust-lang.org/
## Controlling page \<title\>
A chapter can set a \<title\> that is different from its entry in the table of
contents (sidebar) by including a `\{{#title ...}}` near the top of the page.
```hbs
\{{#title My Title}}
```

View File

@@ -0,0 +1,99 @@
# SUMMARY.md
The summary file is used by mdBook to know what chapters to include, in what
order they should appear, what their hierarchy is and where the source files
are. Without this file, there is no book.
This markdown file must be named `SUMMARY.md`. Its formatting
is very strict and must follow the structure outlined below to allow for easy
parsing. Any element not specified below, be it formatting or textual, is likely
to be ignored at best, or may cause an error when attempting to build the book.
### Structure
1. ***Title*** - While optional, it's common practice to begin with a title, generally <code
class="language-markdown"># Summary</code>. This is ignored by the parser however, and
can be omitted.
```markdown
# Summary
```
1. ***Prefix Chapter*** - Before the main numbered chapters, prefix chapters can be added
that will not be numbered. This is useful for forewords,
introductions, etc. There are, however, some constraints. Prefix chapters cannot be
nested; they should all be on the root level. And you cannot add
prefix chapters once you have added numbered chapters.
```markdown
[A Prefix Chapter](relative/path/to/markdown.md)
- [First Chapter](relative/path/to/markdown2.md)
```
1. ***Part Title*** - Headers can be used as a title for the following numbered
chapters. This can be used to logically separate different sections
of the book. The title is rendered as unclickable text.
Titles are optional, and the numbered chapters can be broken into as many
parts as desired.
```markdown
# My Part Title
- [First Chapter](relative/path/to/markdown.md)
```
1. ***Numbered Chapter*** - Numbered chapters outline the main content of the book
and can be nested, resulting in a nice hierarchy
(chapters, sub-chapters, etc.).
```markdown
# Title of Part
- [First Chapter](relative/path/to/markdown.md)
- [Second Chapter](relative/path/to/markdown2.md)
- [Sub Chapter](relative/path/to/markdown3.md)
# Title of Another Part
- [Another Chapter](relative/path/to/markdown4.md)
```
Numbered chapters can be denoted with either `-` or `*` (do not mix delimiters).
1. ***Suffix Chapter*** - Like prefix chapters, suffix chapters are unnumbered, but they come after
numbered chapters.
```markdown
- [Last Chapter](relative/path/to/markdown.md)
[Title of Suffix Chapter](relative/path/to/markdown2.md)
```
1. ***Draft chapters*** - Draft chapters are chapters without a file and thus content.
The purpose of a draft chapter is to signal future chapters still to be written.
Or when still laying out the structure of the book to avoid creating the files
while you are still changing the structure of the book a lot.
Draft chapters will be rendered in the HTML renderer as disabled links in the table
of contents, as you can see for the next chapter in the table of contents on the left.
Draft chapters are written like normal chapters but without writing the path to the file.
```markdown
- [Draft Chapter]()
```
1. ***Separators*** - Separators can be added before, in between, and after any other element. They result
in an HTML rendered line in the built table of contents. A separator is
a line containing exclusively dashes and at least three of them: `---`.
```markdown
# My Part Title
[A Prefix Chapter](relative/path/to/markdown.md)
---
- [First Chapter](relative/path/to/markdown2.md)
```
### Example
Below is the markdown source for the `SUMMARY.md` for this guide, with the resulting table
of contents as rendered to the left.
```markdown
{{#include ../SUMMARY.md}}
```

View File

@@ -0,0 +1,52 @@
# Theme
The default renderer uses a [handlebars](http://handlebarsjs.com/) template to
render your markdown files and comes with a default theme included in the mdBook
binary.
The theme is totally customizable, you can selectively replace every file from
the theme by your own by adding a `theme` directory next to `src` folder in your
project root. Create a new file with the name of the file you want to override
and now that file will be used instead of the default file.
Here are the files you can override:
- **_index.hbs_** is the handlebars template.
- **_head.hbs_** is appended to the HTML `<head>` section.
- **_header.hbs_** content is appended on top of every book page.
- **_css/_** contains the CSS files for styling the book.
- **_css/chrome.css_** is for UI elements.
- **_css/general.css_** is the base styles.
- **_css/print.css_** is the style for printer output.
- **_css/variables.css_** contains variables used in other CSS files.
- **_book.js_** is mostly used to add client side functionality, like hiding /
un-hiding the sidebar, changing the theme, ...
- **_highlight.js_** is the JavaScript that is used to highlight code snippets,
you should not need to modify this.
- **_highlight.css_** is the theme used for the code highlighting.
- **_favicon.svg_** and **_favicon.png_** the favicon that will be used. The SVG
version is used by [newer browsers].
- **fonts/fonts.css** contains the definition of which fonts to load.
Custom fonts can be included in the `fonts` directory.
Generally, when you want to tweak the theme, you don't need to override all the
files. If you only need changes in the stylesheet, there is no point in
overriding all the other files. Because custom files take precedence over
built-in ones, they will not get updated with new fixes / features.
**Note:** When you override a file, it is possible that you break some
functionality. Therefore I recommend to use the file from the default theme as
template and only add / modify what you need. You can copy the default theme
into your source directory automatically by using `mdbook init --theme` and just
remove the files you don't want to override.
`mdbook init --theme` will not create every file listed above.
Some files, such as `head.hbs`, do not have built-in equivalents.
Just create the file if you need it.
If you completely replace all built-in themes, be sure to also set
[`output.html.preferred-dark-theme`] in the config, which defaults to the
built-in `navy` theme.
[`output.html.preferred-dark-theme`]: ../configuration/renderers.md#html-renderer-options
[newer browsers]: https://caniuse.com/#feat=link-icon-svg

View File

@@ -0,0 +1,48 @@
# Editor
In addition to providing runnable code playgrounds, mdBook optionally allows them
to be editable. In order to enable editable code blocks, the following needs to
be added to the ***book.toml***:
```toml
[output.html.playground]
editable = true
```
To make a specific block available for editing, the attribute `editable` needs
to be added to it:
~~~markdown
```rust,editable
fn main() {
let number = 5;
print!("{}", number);
}
```
~~~
The above will result in this editable playground:
```rust,editable
fn main() {
let number = 5;
print!("{}", number);
}
```
Note the new `Undo Changes` button in the editable playgrounds.
## Customizing the Editor
By default, the editor is the [Ace](https://ace.c9.io/) editor, but, if desired,
the functionality may be overridden by providing a different folder:
```toml
[output.html.playground]
editable = true
editor = "/path/to/editor"
```
Note that for the editor changes to function correctly, the `book.js` inside of
the `theme` folder will need to be overridden as it has some couplings with the
default Ace editor.

View File

@@ -0,0 +1,101 @@
# index.hbs
`index.hbs` is the handlebars template that is used to render the book. The
markdown files are processed to html and then injected in that template.
If you want to change the layout or style of your book, chances are that you
will have to modify this template a little bit. Here is what you need to know.
## Data
A lot of data is exposed to the handlebars template with the "context". In the
handlebars template you can access this information by using
```handlebars
{{name_of_property}}
```
Here is a list of the properties that are exposed:
- ***language*** Language of the book in the form `en`, as specified in `book.toml` (if not specified, defaults to `en`). To use in <code
class="language-html">\<html lang="{{ language }}"></code> for example.
- ***title*** Title used for the current page. This is identical to `{{ chapter_title }} - {{ book_title }}` unless `book_title` is not set in which case it just defaults to the `chapter_title`.
- ***book_title*** Title of the book, as specified in `book.toml`
- ***chapter_title*** Title of the current chapter, as listed in `SUMMARY.md`
- ***path*** Relative path to the original markdown file from the source
directory
- ***content*** This is the rendered markdown.
- ***path_to_root*** This is a path containing exclusively `../`'s that points
to the root of the book from the current file. Since the original directory
structure is maintained, it is useful to prepend relative links with this
`path_to_root`.
- ***chapters*** Is an array of dictionaries of the form
```json
{"section": "1.2.1", "name": "name of this chapter", "path": "dir/markdown.md"}
```
containing all the chapters of the book. It is used for example to construct
the table of contents (sidebar).
## Handlebars Helpers
In addition to the properties you can access, there are some handlebars helpers
at your disposal.
### 1. toc
The toc helper is used like this
```handlebars
{{#toc}}{{/toc}}
```
and outputs something that looks like this, depending on the structure of your
book
```html
<ul class="chapter">
<li><a href="link/to/file.html">Some chapter</a></li>
<li>
<ul class="section">
<li><a href="link/to/other_file.html">Some other Chapter</a></li>
</ul>
</li>
</ul>
```
If you would like to make a toc with another structure, you have access to the
chapters property containing all the data. The only limitation at the moment
is that you would have to do it with JavaScript instead of with a handlebars
helper.
```html
<script>
var chapters = {{chapters}};
// Processing here
</script>
```
### 2. previous / next
The previous and next helpers expose a `link` and `name` property to the
previous and next chapters.
They are used like this
```handlebars
{{#previous}}
<a href="{{link}}" class="nav-chapters previous">
<i class="fa fa-angle-left"></i>
</a>
{{/previous}}
```
The inner html will only be rendered if the previous / next chapter exists.
Of course the inner html can be changed to your liking.
------
*If you would like other properties or helpers exposed, please [create a new
issue](https://github.com/rust-lang/mdBook/issues)*

View File

@@ -0,0 +1,121 @@
# Syntax Highlighting
mdBook uses [Highlight.js](https://highlightjs.org) with a custom theme
for syntax highlighting.
Automatic language detection has been turned off, so you will probably want to
specify the programming language you use like this:
~~~markdown
```rust
fn main() {
// Some code
}
```
~~~
## Supported languages
These languages are supported by default, but you can add more by supplying
your own `highlight.js` file:
- apache
- armasm
- bash
- c
- coffeescript
- cpp
- csharp
- css
- d
- diff
- go
- handlebars
- haskell
- http
- ini
- java
- javascript
- json
- julia
- kotlin
- less
- lua
- makefile
- markdown
- nginx
- objectivec
- perl
- php
- plaintext
- properties
- python
- r
- ruby
- rust
- scala
- scss
- shell
- sql
- swift
- typescript
- x86asm
- xml
- yaml
## Custom theme
Like the rest of the theme, the files used for syntax highlighting can be
overridden with your own.
- ***highlight.js*** normally you shouldn't have to overwrite this file, unless
you want to use a more recent version.
- ***highlight.css*** theme used by highlight.js for syntax highlighting.
If you want to use another theme for `highlight.js` download it from their
website, or make it yourself, rename it to `highlight.css` and put it in
the `theme` folder of your book.
Now your theme will be used instead of the default theme.
## Hiding code lines
There is a feature in mdBook that lets you hide code lines by prepending them
with a `#`.
```bash
# fn main() {
let x = 5;
let y = 6;
println!("{}", x + y);
# }
```
Will render as
```rust
# fn main() {
let x = 5;
let y = 7;
println!("{}", x + y);
# }
```
**At the moment, this only works for code examples that are annotated with
`rust`. Because it would collide with semantics of some programming languages.
In the future, we want to make this configurable through the `book.toml` so that
everyone can benefit from it.**
## Improve default theme
If you think the default theme doesn't look quite right for a specific language,
or could be improved, feel free to [submit a new
issue](https://github.com/rust-lang/mdBook/issues) explaining what you
have in mind and I will take a look at it.
You could also create a pull-request with the proposed improvements.
Overall the theme should be light and sober, without too many flashy colors.

View File

@@ -0,0 +1,7 @@
# User Guide
This user guide provides an introduction to basic concepts of using mdBook.
- [Installation](installation.md)
- [Reading Books](reading.md)
- [Creating a Book](creating.md)

109
guide/src/guide/creating.md Normal file
View File

@@ -0,0 +1,109 @@
# Creating a Book
Once you have the `mdbook` CLI tool installed, you can use it to create and render a book.
## Initializing a book
The `mdbook init` command will create a new directory containing an empty book for you to get started.
Give it the name of the directory that you want to create:
```sh
mdbook init my-first-book
```
It will ask a few questions before generating the book.
After answering the questions, you can change the current directory into the new book:
```sh
cd my-first-book
```
There are several ways to render a book, but one of the easiest methods is to use the `serve` command, which will build your book and start a local webserver:
```sh
mdbook serve --open
```
The `--open` option will open your default web browser to view your new book.
You can leave the server running even while you edit the content of the book, and `mdbook` will automatically rebuild the output *and* automatically refresh your web browser.
Check out the [CLI Guide](../cli/index.html) for more information about other `mdbook` commands and CLI options.
## Anatomy of a book
A book is built from several files which define the settings and layout of the book.
### `book.toml`
In the root of your book, there is a `book.toml` file which contains settings for describing how to build your book.
This is written in the [TOML markup language](https://toml.io/).
The default settings are usually good enough to get you started.
When you are interested in exploring more features and options that mdBook provides, check out the [Configuration chapter](../format/configuration/index.html) for more details.
A very basic `book.toml` can be as simple as this:
```toml
[book]
title = "My First Book"
```
### `SUMMARY.md`
The next major part of a book is the summary file located at `src/SUMMARY.md`.
This file contains a list of all the chapters in the book.
Before a chapter can be viewed, it must be added to this list.
Here's a basic summary file with a few chapters:
```md
# Summary
[Introduction](README.md)
- [My First Chapter](my-first-chapter.md)
- [Nested example](nested/README.md)
- [Sub-chapter](nested/sub-chapter.md)
```
Try opening up `src/SUMMARY.md` in your editor and adding a few chapters.
If any of the chapter files do not exist, `mdbook` will automatically create them for you.
For more details on other formatting options for the summary file, check out the [Summary chapter](../format/summary.md).
### Source files
The content of your book is all contained in the `src` directory.
Each chapter is a separate Markdown file.
Typically, each chapter starts with a level 1 heading with the title of the chapter.
```md
# My First Chapter
Fill out your content here.
```
The precise layout of the files is up to you.
The organization of the files will correspond to the HTML files generated, so keep in mind that the file layout is part of the URL of each chapter.
While the `mdbook serve` command is running, you can open any of the chapter files and start editing them.
Each time you save the file, `mdbook` will rebuild the book and refresh your web browser.
Check out the [Markdown chapter](../format/markdown.md) for more information on formatting the content of your chapters.
All other files in the `src` directory will be included in the output.
So if you have images or other static files, just include them somewhere in the `src` directory.
## Publishing a book
Once you've written your book, you may want to host it somewhere for others to view.
The first step is to build the output of the book.
This can be done with the `mdbook build` command in the same directory where the `book.toml` file is located:
```sh
mdbook build
```
This will generate a directory named `book` which contains the HTML content of your book.
You can then place this directory on any web server to host it.
For more information about publishing and deploying, check out the [Continuous Integration chapter](../continuous-integration.md) for more.

View File

@@ -0,0 +1,52 @@
# Installation
There are multiple ways to install the mdBook CLI tool.
Choose any one of the methods below that best suit your needs.
If you are installing mdBook for automatic deployment, check out the [continuous integration] chapter for more examples on how to install.
[continuous integration]: ../continuous-integration.md
## Pre-compiled binaries
Executable binaries are available for download on the [GitHub Releases page][releases].
Download the binary for your platform (Windows, macOS, or Linux) and extract the archive.
The archive contains an `mdbook` executable which you can run to build your books.
To make it easier to run, put the path to the binary into your `PATH`.
[releases]: https://github.com/rust-lang/mdBook/releases
## Build from source using Rust
To build the `mdbook` executable from source, you will first need to install Rust and Cargo.
Follow the instructions on the [Rust installation page].
mdBook currently requires at least Rust version 1.60.
Once you have installed Rust, the following command can be used to build and install mdBook:
```sh
cargo install mdbook
```
This will automatically download mdBook from [crates.io], build it, and install it in Cargo's global binary directory (`~/.cargo/bin/` by default).
To uninstall, run the command `cargo uninstall mdbook`.
[Rust installation page]: https://www.rust-lang.org/tools/install
[crates.io]: https://crates.io/
### Installing the latest master version
The version published to crates.io will ever so slightly be behind the version hosted on GitHub.
If you need the latest version you can build the git version of mdBook yourself.
Cargo makes this ***super easy***!
```sh
cargo install --git https://github.com/rust-lang/mdBook.git mdbook
```
Again, make sure to add the Cargo bin directory to your `PATH`.
If you are interested in making modifications to mdBook itself, check out the [Contributing Guide] for more information.
[Contributing Guide]: https://github.com/rust-lang/mdBook/blob/master/CONTRIBUTING.md

View File

@@ -0,0 +1,74 @@
# Reading Books
This chapter gives an introduction on how to interact with a book produced by mdBook.
This assumes you are reading an HTML book.
The options and formatting will be different for other output formats such as PDF.
A book is organized into *chapters*.
Each chapter is a separate page.
Chapters can be nested into a hierarchy of sub-chapters.
Typically, each chapter will be organized into a series of *headings* to subdivide a chapter.
## Navigation
There are several methods for navigating through the chapters of a book.
The **sidebar** on the left provides a list of all chapters.
Clicking on any of the chapter titles will load that page.
The sidebar may not automatically appear if the window is too narrow, particularly on mobile displays.
In that situation, the menu icon (three horizontal bars) at the top-left of the page can be pressed to open and close the sidebar.
The **arrow buttons** at the bottom of the page can be used to navigate to the previous or the next chapter.
The **left and right arrow keys** on the keyboard can be used to navigate to the previous or the next chapter.
## Top menu bar
The menu bar at the top of the page provides some icons for interacting with the book.
The icons displayed will depend on the settings of how the book was generated.
| Icon | Description |
|------|-------------|
| <i class="fa fa-bars"></i> | Opens and closes the chapter listing sidebar. |
| <i class="fa fa-paint-brush"></i> | Opens a picker to choose a different color theme. |
| <i class="fa fa-search"></i> | Opens a search bar for searching within the book. |
| <i class="fa fa-print"></i> | Instructs the web browser to print the entire book. |
| <i class="fa fa-github"></i> | Opens a link to the website that hosts the source code of the book. |
| <i class="fa fa-edit"></i> | Opens a page to directly edit the source of the page you are currently reading. |
Tapping the menu bar will scroll the page to the top.
## Search
Each book has a built-in search system.
Pressing the search icon (<i class="fa fa-search"></i>) in the menu bar, or pressing the `S` key on the keyboard will open an input box for entering search terms.
Typing some terms will show matching chapters and sections in real time.
Clicking any of the results will jump to that section.
The up and down arrow keys can be used to navigate the results, and enter will open the highlighted section.
After loading a search result, the matching search terms will be highlighted in the text.
Clicking a highlighted word or pressing the `Esc` key will remove the highlighting.
## Code blocks
mdBook books are often used for programming projects, and thus support highlighting code blocks and samples.
Code blocks may contain several different icons for interacting with them:
| Icon | Description |
|------|-------------|
| <i class="fa fa-copy"></i> | Copies the code block into your local clipboard, to allow pasting into another application. |
| <i class="fa fa-play"></i> | For Rust code examples, this will execute the sample code and display the compiler output just below the example (see [playground]). |
| <i class="fa fa-eye"></i> | For Rust code examples, this will toggle visibility of "hidden" lines. Sometimes, larger examples will hide lines which are not particularly relevant to what is being illustrated (see [hiding code lines]). |
| <i class="fa fa-history"></i> | For [editable code examples][editor], this will undo any changes you have made. |
Here's an example:
```rust
println!("Hello, World!");
```
[editor]: ../format/theme/editor.md
[playground]: ../format/mdbook.md#rust-playground
[hiding code lines]: ../format/mdbook.md#hiding-code-lines

View File

@@ -0,0 +1,24 @@
# Contributors
Here is a list of the contributors who have helped improving mdBook. Big
shout-out to them!
- [mdinger](https://github.com/mdinger)
- Kevin ([kbknapp](https://github.com/kbknapp))
- Steve Klabnik ([steveklabnik](https://github.com/steveklabnik))
- Adam Solove ([asolove](https://github.com/asolove))
- Wayne Nilsen ([waynenilsen](https://github.com/waynenilsen))
- [funnkill](https://github.com/funkill)
- Fu Gangqiang ([FuGangqiang](https://github.com/FuGangqiang))
- [Michael-F-Bryan](https://github.com/Michael-F-Bryan)
- Chris Spiegel ([cspiegel](https://github.com/cspiegel))
- [projektir](https://github.com/projektir)
- [Phaiax](https://github.com/Phaiax)
- Matt Ickstadt ([mattico](https://github.com/mattico))
- Weihang Lo ([weihanglo](https://github.com/weihanglo))
- Avision Ho ([avisionh](https://github.com/avisionh))
- Vivek Akupatni ([apatniv](https://github.com/apatniv))
- Eric Huss ([ehuss](https://github.com/ehuss))
- Josh Rotenberg ([joshrotenberg](https://github.com/joshrotenberg))
If you feel you're missing from this list, feel free to add yourself in a PR.

3
release.toml Normal file
View File

@@ -0,0 +1,3 @@
sign-commit = true
push-remote = "origin"
tag-prefix = "v"

View File

@@ -1,228 +0,0 @@
#[macro_use]
extern crate mdbook;
#[macro_use]
extern crate clap;
extern crate crossbeam;
// Dependencies for the Watch feature
#[cfg(feature = "watch")]
extern crate notify;
#[cfg(feature = "watch")]
extern crate time;
use std::env;
use std::error::Error;
use std::io::{self, Write};
use std::path::{Path, PathBuf};
use clap::{App, ArgMatches, SubCommand};
// Uses for the Watch feature
#[cfg(feature = "watch")]
use notify::Watcher;
#[cfg(feature = "watch")]
use std::sync::mpsc::channel;
use mdbook::MDBook;
const NAME: &'static str = "mdbook";
fn main() {
// Create a list of valid arguments and sub-commands
let matches = App::new(NAME)
.about("Create a book in form of a static website from markdown files")
.author("Mathieu David <mathieudavid@mathieudavid.org>")
// Get the version from our Cargo.toml using clap's crate_version!() macro
.version(&*format!("v{}", crate_version!()))
.subcommand_required(true)
.after_help("For more information about a specific command, try `mdbook <command> --help`")
.subcommand(SubCommand::with_name("init")
.about("Create boilerplate structure and files in the directory")
// the {n} denotes a newline which will properly aligned in all help messages
.arg_from_usage("[dir] 'A directory for your book{n}(Defaults to Current Directory when ommitted)'")
.arg_from_usage("--theme 'Copies the default theme into your source folder'")
.arg_from_usage("--force 'skip confirmation prompts'"))
.subcommand(SubCommand::with_name("build")
.about("Build the book from the markdown files")
.arg_from_usage("[dir] 'A directory for your book{n}(Defaults to Current Directory when ommitted)'"))
.subcommand(SubCommand::with_name("watch")
.about("Watch the files for changes")
.arg_from_usage("[dir] 'A directory for your book{n}(Defaults to Current Directory when ommitted)'"))
.subcommand(SubCommand::with_name("test")
.about("Test that code samples compile"))
.get_matches();
// Check which subcomamnd the user ran...
let res = match matches.subcommand() {
("init", Some(sub_matches)) => init(sub_matches),
("build", Some(sub_matches)) => build(sub_matches),
#[cfg(feature = "watch")]
("watch", Some(sub_matches)) => watch(sub_matches),
("test", Some(sub_matches)) => test(sub_matches),
(_, _) => unreachable!()
};
if let Err(e) = res {
writeln!(&mut io::stderr(), "An error occured:\n{}", e).ok();
}
}
// Simple function that user comfirmation
fn confirm() -> bool {
io::stdout().flush().unwrap();
let mut s = String::new();
io::stdin().read_line(&mut s).ok();
match &*s.trim() {
"Y" | "y" | "yes" | "Yes" => true,
_ => false
}
}
// Init command implementation
fn init(args: &ArgMatches) -> Result<(), Box<Error>> {
let book_dir = get_book_dir(args);
let mut book = MDBook::new(&book_dir);
// Call the function that does the initialization
try!(book.init());
// If flag `--theme` is present, copy theme to src
if args.is_present("theme") {
// Skip this id `--force` is present
if !args.is_present("force") {
// Print warning
print!("\nCopying the default theme to {:?}", book.get_src());
println!("could potentially overwrite files already present in that directory.");
print!("\nAre you sure you want to continue? (y/n) ");
// Read answer from user and exit if it's not 'yes'
if !confirm() {
println!("\nSkipping...\n");
println!("All done, no errors...");
::std::process::exit(0);
}
}
// Call the function that copies the theme
try!(book.copy_theme());
println!("\nTheme copied.");
}
println!("\nAll done, no errors...");
Ok(())
}
// Build command implementation
fn build(args: &ArgMatches) -> Result<(), Box<Error>> {
let book_dir = get_book_dir(args);
let mut book = MDBook::new(&book_dir).read_config();
try!(book.build());
Ok(())
}
// Watch command implementation
#[cfg(feature = "watch")]
fn watch(args: &ArgMatches) -> Result<(), Box<Error>> {
let book_dir = get_book_dir(args);
let book = MDBook::new(&book_dir).read_config();
// Create a channel to receive the events.
let (tx, rx) = channel();
let w: Result<notify::RecommendedWatcher, notify::Error> = notify::Watcher::new(tx);
match w {
Ok(mut watcher) => {
// Add the source directory to the watcher
if let Err(e) = watcher.watch(book.get_src()) {
println!("Error while watching {:?}:\n {:?}", book.get_src(), e);
::std::process::exit(0);
};
// Add the book.json file to the watcher if it exists, because it's not
// located in the source directory
if let Err(_) = watcher.watch(book_dir.join("book.json")) {
// do nothing if book.json is not found
}
let previous_time = time::get_time().sec;
crossbeam::scope(|scope| {
loop {
match rx.recv() {
Ok(event) => {
// Skip the event if an event has already been issued in the last second
if time::get_time().sec - previous_time < 1 { continue }
if let Some(path) = event.path {
// Trigger the build process in a new thread (to keep receiving events)
scope.spawn(move || {
println!("File changed: {:?}\nBuilding book...\n", path);
match build(args) {
Err(e) => println!("Error while building: {:?}", e),
_ => {}
}
println!("");
});
} else {
continue;
}
},
Err(e) => {
println!("An error occured: {:?}", e);
}
}
}
});
},
Err(e) => {
println!("Error while trying to watch the files:\n\n\t{:?}", e);
::std::process::exit(0);
}
}
Ok(())
}
fn test(args: &ArgMatches) -> Result<(), Box<Error>> {
let book_dir = get_book_dir(args);
let mut book = MDBook::new(&book_dir).read_config();
try!(book.test());
Ok(())
}
fn get_book_dir(args: &ArgMatches) -> PathBuf {
if let Some(dir) = args.value_of("dir") {
// Check if path is relative from current dir, or absolute...
let p = Path::new(dir);
if p.is_relative() {
env::current_dir().unwrap().join(dir)
} else {
p.to_path_buf()
}
} else {
env::current_dir().unwrap()
}
}

640
src/book/book.rs Normal file
View File

@@ -0,0 +1,640 @@
use std::collections::VecDeque;
use std::fmt::{self, Display, Formatter};
use std::fs::{self, File};
use std::io::{Read, Write};
use std::path::{Path, PathBuf};
use super::summary::{parse_summary, Link, SectionNumber, Summary, SummaryItem};
use crate::config::BuildConfig;
use crate::errors::*;
use crate::utils::bracket_escape;
use log::debug;
use serde::{Deserialize, Serialize};
/// Load a book into memory from its `src/` directory.
pub fn load_book<P: AsRef<Path>>(src_dir: P, cfg: &BuildConfig) -> Result<Book> {
let src_dir = src_dir.as_ref();
let summary_md = src_dir.join("SUMMARY.md");
let mut summary_content = String::new();
File::open(&summary_md)
.with_context(|| format!("Couldn't open SUMMARY.md in {:?} directory", src_dir))?
.read_to_string(&mut summary_content)?;
let summary = parse_summary(&summary_content)
.with_context(|| format!("Summary parsing failed for file={:?}", summary_md))?;
if cfg.create_missing {
create_missing(src_dir, &summary).with_context(|| "Unable to create missing chapters")?;
}
load_book_from_disk(&summary, src_dir)
}
fn create_missing(src_dir: &Path, summary: &Summary) -> Result<()> {
let mut items: Vec<_> = summary
.prefix_chapters
.iter()
.chain(summary.numbered_chapters.iter())
.chain(summary.suffix_chapters.iter())
.collect();
while !items.is_empty() {
let next = items.pop().expect("already checked");
if let SummaryItem::Link(ref link) = *next {
if let Some(ref location) = link.location {
let filename = src_dir.join(location);
if !filename.exists() {
if let Some(parent) = filename.parent() {
if !parent.exists() {
fs::create_dir_all(parent)?;
}
}
debug!("Creating missing file {}", filename.display());
let mut f = File::create(&filename).with_context(|| {
format!("Unable to create missing file: {}", filename.display())
})?;
writeln!(f, "# {}", bracket_escape(&link.name))?;
}
}
items.extend(&link.nested_items);
}
}
Ok(())
}
/// A dumb tree structure representing a book.
///
/// For the moment a book is just a collection of [`BookItems`] which are
/// accessible by either iterating (immutably) over the book with [`iter()`], or
/// recursively applying a closure to each section to mutate the chapters, using
/// [`for_each_mut()`].
///
/// [`iter()`]: #method.iter
/// [`for_each_mut()`]: #method.for_each_mut
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct Book {
/// The sections in this book.
pub sections: Vec<BookItem>,
__non_exhaustive: (),
}
impl Book {
/// Create an empty book.
pub fn new() -> Self {
Default::default()
}
/// Get a depth-first iterator over the items in the book.
pub fn iter(&self) -> BookItems<'_> {
BookItems {
items: self.sections.iter().collect(),
}
}
/// Recursively apply a closure to each item in the book, allowing you to
/// mutate them.
///
/// # Note
///
/// Unlike the `iter()` method, this requires a closure instead of returning
/// an iterator. This is because using iterators can possibly allow you
/// to have iterator invalidation errors.
pub fn for_each_mut<F>(&mut self, mut func: F)
where
F: FnMut(&mut BookItem),
{
for_each_mut(&mut func, &mut self.sections);
}
/// Append a `BookItem` to the `Book`.
pub fn push_item<I: Into<BookItem>>(&mut self, item: I) -> &mut Self {
self.sections.push(item.into());
self
}
}
pub fn for_each_mut<'a, F, I>(func: &mut F, items: I)
where
F: FnMut(&mut BookItem),
I: IntoIterator<Item = &'a mut BookItem>,
{
for item in items {
if let BookItem::Chapter(ch) = item {
for_each_mut(func, &mut ch.sub_items);
}
func(item);
}
}
/// Enum representing any type of item which can be added to a book.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum BookItem {
/// A nested chapter.
Chapter(Chapter),
/// A section separator.
Separator,
/// A part title.
PartTitle(String),
}
impl From<Chapter> for BookItem {
fn from(other: Chapter) -> BookItem {
BookItem::Chapter(other)
}
}
/// The representation of a "chapter", usually mapping to a single file on
/// disk however it may contain multiple sub-chapters.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct Chapter {
/// The chapter's name.
pub name: String,
/// The chapter's contents.
pub content: String,
/// The chapter's section number, if it has one.
pub number: Option<SectionNumber>,
/// Nested items.
pub sub_items: Vec<BookItem>,
/// The chapter's location, relative to the `SUMMARY.md` file.
pub path: Option<PathBuf>,
/// The chapter's source file, relative to the `SUMMARY.md` file.
pub source_path: Option<PathBuf>,
/// An ordered list of the names of each chapter above this one in the hierarchy.
pub parent_names: Vec<String>,
}
impl Chapter {
/// Create a new chapter with the provided content.
pub fn new<P: Into<PathBuf>>(
name: &str,
content: String,
p: P,
parent_names: Vec<String>,
) -> Chapter {
let path: PathBuf = p.into();
Chapter {
name: name.to_string(),
content,
path: Some(path.clone()),
source_path: Some(path),
parent_names,
..Default::default()
}
}
/// Create a new draft chapter that is not attached to a source markdown file (and thus
/// has no content).
pub fn new_draft(name: &str, parent_names: Vec<String>) -> Self {
Chapter {
name: name.to_string(),
content: String::new(),
path: None,
source_path: None,
parent_names,
..Default::default()
}
}
/// Check if the chapter is a draft chapter, meaning it has no path to a source markdown file.
pub fn is_draft_chapter(&self) -> bool {
self.path.is_none()
}
}
/// Use the provided `Summary` to load a `Book` from disk.
///
/// You need to pass in the book's source directory because all the links in
/// `SUMMARY.md` give the chapter locations relative to it.
pub(crate) fn load_book_from_disk<P: AsRef<Path>>(summary: &Summary, src_dir: P) -> Result<Book> {
debug!("Loading the book from disk");
let src_dir = src_dir.as_ref();
let prefix = summary.prefix_chapters.iter();
let numbered = summary.numbered_chapters.iter();
let suffix = summary.suffix_chapters.iter();
let summary_items = prefix.chain(numbered).chain(suffix);
let mut chapters = Vec::new();
for summary_item in summary_items {
let chapter = load_summary_item(summary_item, src_dir, Vec::new())?;
chapters.push(chapter);
}
Ok(Book {
sections: chapters,
__non_exhaustive: (),
})
}
fn load_summary_item<P: AsRef<Path> + Clone>(
item: &SummaryItem,
src_dir: P,
parent_names: Vec<String>,
) -> Result<BookItem> {
match item {
SummaryItem::Separator => Ok(BookItem::Separator),
SummaryItem::Link(ref link) => {
load_chapter(link, src_dir, parent_names).map(BookItem::Chapter)
}
SummaryItem::PartTitle(title) => Ok(BookItem::PartTitle(title.clone())),
}
}
fn load_chapter<P: AsRef<Path>>(
link: &Link,
src_dir: P,
parent_names: Vec<String>,
) -> Result<Chapter> {
let src_dir = src_dir.as_ref();
let mut ch = if let Some(ref link_location) = link.location {
debug!("Loading {} ({})", link.name, link_location.display());
let location = if link_location.is_absolute() {
link_location.clone()
} else {
src_dir.join(link_location)
};
let mut f = File::open(&location)
.with_context(|| format!("Chapter file not found, {}", link_location.display()))?;
let mut content = String::new();
f.read_to_string(&mut content).with_context(|| {
format!("Unable to read \"{}\" ({})", link.name, location.display())
})?;
if content.as_bytes().starts_with(b"\xef\xbb\xbf") {
content.replace_range(..3, "");
}
let stripped = location
.strip_prefix(&src_dir)
.expect("Chapters are always inside a book");
Chapter::new(&link.name, content, stripped, parent_names.clone())
} else {
Chapter::new_draft(&link.name, parent_names.clone())
};
let mut sub_item_parents = parent_names;
ch.number = link.number.clone();
sub_item_parents.push(link.name.clone());
let sub_items = link
.nested_items
.iter()
.map(|i| load_summary_item(i, src_dir, sub_item_parents.clone()))
.collect::<Result<Vec<_>>>()?;
ch.sub_items = sub_items;
Ok(ch)
}
/// A depth-first iterator over the items in a book.
///
/// # Note
///
/// This struct shouldn't be created directly, instead prefer the
/// [`Book::iter()`] method.
pub struct BookItems<'a> {
items: VecDeque<&'a BookItem>,
}
impl<'a> Iterator for BookItems<'a> {
type Item = &'a BookItem;
fn next(&mut self) -> Option<Self::Item> {
let item = self.items.pop_front();
if let Some(&BookItem::Chapter(ref ch)) = item {
// if we wanted a breadth-first iterator we'd `extend()` here
for sub_item in ch.sub_items.iter().rev() {
self.items.push_front(sub_item);
}
}
item
}
}
impl Display for Chapter {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
if let Some(ref section_number) = self.number {
write!(f, "{} ", section_number)?;
}
write!(f, "{}", self.name)
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::io::Write;
use tempfile::{Builder as TempFileBuilder, TempDir};
const DUMMY_SRC: &str = "
# Dummy Chapter
this is some dummy text.
And here is some \
more text.
";
/// Create a dummy `Link` in a temporary directory.
fn dummy_link() -> (Link, TempDir) {
let temp = TempFileBuilder::new().prefix("book").tempdir().unwrap();
let chapter_path = temp.path().join("chapter_1.md");
File::create(&chapter_path)
.unwrap()
.write_all(DUMMY_SRC.as_bytes())
.unwrap();
let link = Link::new("Chapter 1", chapter_path);
(link, temp)
}
/// Create a nested `Link` written to a temporary directory.
fn nested_links() -> (Link, TempDir) {
let (mut root, temp_dir) = dummy_link();
let second_path = temp_dir.path().join("second.md");
File::create(&second_path)
.unwrap()
.write_all(b"Hello World!")
.unwrap();
let mut second = Link::new("Nested Chapter 1", &second_path);
second.number = Some(SectionNumber(vec![1, 2]));
root.nested_items.push(second.clone().into());
root.nested_items.push(SummaryItem::Separator);
root.nested_items.push(second.into());
(root, temp_dir)
}
#[test]
fn load_a_single_chapter_from_disk() {
let (link, temp_dir) = dummy_link();
let should_be = Chapter::new(
"Chapter 1",
DUMMY_SRC.to_string(),
"chapter_1.md",
Vec::new(),
);
let got = load_chapter(&link, temp_dir.path(), Vec::new()).unwrap();
assert_eq!(got, should_be);
}
#[test]
fn load_a_single_chapter_with_utf8_bom_from_disk() {
let temp_dir = TempFileBuilder::new().prefix("book").tempdir().unwrap();
let chapter_path = temp_dir.path().join("chapter_1.md");
File::create(&chapter_path)
.unwrap()
.write_all(("\u{feff}".to_owned() + DUMMY_SRC).as_bytes())
.unwrap();
let link = Link::new("Chapter 1", chapter_path);
let should_be = Chapter::new(
"Chapter 1",
DUMMY_SRC.to_string(),
"chapter_1.md",
Vec::new(),
);
let got = load_chapter(&link, temp_dir.path(), Vec::new()).unwrap();
assert_eq!(got, should_be);
}
#[test]
fn cant_load_a_nonexistent_chapter() {
let link = Link::new("Chapter 1", "/foo/bar/baz.md");
let got = load_chapter(&link, "", Vec::new());
assert!(got.is_err());
}
#[test]
fn load_recursive_link_with_separators() {
let (root, temp) = nested_links();
let nested = Chapter {
name: String::from("Nested Chapter 1"),
content: String::from("Hello World!"),
number: Some(SectionNumber(vec![1, 2])),
path: Some(PathBuf::from("second.md")),
source_path: Some(PathBuf::from("second.md")),
parent_names: vec![String::from("Chapter 1")],
sub_items: Vec::new(),
};
let should_be = BookItem::Chapter(Chapter {
name: String::from("Chapter 1"),
content: String::from(DUMMY_SRC),
number: None,
path: Some(PathBuf::from("chapter_1.md")),
source_path: Some(PathBuf::from("chapter_1.md")),
parent_names: Vec::new(),
sub_items: vec![
BookItem::Chapter(nested.clone()),
BookItem::Separator,
BookItem::Chapter(nested),
],
});
let got = load_summary_item(&SummaryItem::Link(root), temp.path(), Vec::new()).unwrap();
assert_eq!(got, should_be);
}
#[test]
fn load_a_book_with_a_single_chapter() {
let (link, temp) = dummy_link();
let summary = Summary {
numbered_chapters: vec![SummaryItem::Link(link)],
..Default::default()
};
let should_be = Book {
sections: vec![BookItem::Chapter(Chapter {
name: String::from("Chapter 1"),
content: String::from(DUMMY_SRC),
path: Some(PathBuf::from("chapter_1.md")),
source_path: Some(PathBuf::from("chapter_1.md")),
..Default::default()
})],
..Default::default()
};
let got = load_book_from_disk(&summary, temp.path()).unwrap();
assert_eq!(got, should_be);
}
#[test]
fn book_iter_iterates_over_sequential_items() {
let book = Book {
sections: vec![
BookItem::Chapter(Chapter {
name: String::from("Chapter 1"),
content: String::from(DUMMY_SRC),
..Default::default()
}),
BookItem::Separator,
],
..Default::default()
};
let should_be: Vec<_> = book.sections.iter().collect();
let got: Vec<_> = book.iter().collect();
assert_eq!(got, should_be);
}
#[test]
fn iterate_over_nested_book_items() {
let book = Book {
sections: vec![
BookItem::Chapter(Chapter {
name: String::from("Chapter 1"),
content: String::from(DUMMY_SRC),
number: None,
path: Some(PathBuf::from("Chapter_1/index.md")),
source_path: Some(PathBuf::from("Chapter_1/index.md")),
parent_names: Vec::new(),
sub_items: vec![
BookItem::Chapter(Chapter::new(
"Hello World",
String::new(),
"Chapter_1/hello.md",
Vec::new(),
)),
BookItem::Separator,
BookItem::Chapter(Chapter::new(
"Goodbye World",
String::new(),
"Chapter_1/goodbye.md",
Vec::new(),
)),
],
}),
BookItem::Separator,
],
..Default::default()
};
let got: Vec<_> = book.iter().collect();
assert_eq!(got.len(), 5);
// checking the chapter names are in the order should be sufficient here...
let chapter_names: Vec<String> = got
.into_iter()
.filter_map(|i| match *i {
BookItem::Chapter(ref ch) => Some(ch.name.clone()),
_ => None,
})
.collect();
let should_be: Vec<_> = vec![
String::from("Chapter 1"),
String::from("Hello World"),
String::from("Goodbye World"),
];
assert_eq!(chapter_names, should_be);
}
#[test]
fn for_each_mut_visits_all_items() {
let mut book = Book {
sections: vec![
BookItem::Chapter(Chapter {
name: String::from("Chapter 1"),
content: String::from(DUMMY_SRC),
number: None,
path: Some(PathBuf::from("Chapter_1/index.md")),
source_path: Some(PathBuf::from("Chapter_1/index.md")),
parent_names: Vec::new(),
sub_items: vec![
BookItem::Chapter(Chapter::new(
"Hello World",
String::new(),
"Chapter_1/hello.md",
Vec::new(),
)),
BookItem::Separator,
BookItem::Chapter(Chapter::new(
"Goodbye World",
String::new(),
"Chapter_1/goodbye.md",
Vec::new(),
)),
],
}),
BookItem::Separator,
],
..Default::default()
};
let num_items = book.iter().count();
let mut visited = 0;
book.for_each_mut(|_| visited += 1);
assert_eq!(visited, num_items);
}
#[test]
fn cant_load_chapters_with_an_empty_path() {
let (_, temp) = dummy_link();
let summary = Summary {
numbered_chapters: vec![SummaryItem::Link(Link {
name: String::from("Empty"),
location: Some(PathBuf::from("")),
..Default::default()
})],
..Default::default()
};
let got = load_book_from_disk(&summary, temp.path());
assert!(got.is_err());
}
#[test]
fn cant_load_chapters_when_the_link_is_a_directory() {
let (_, temp) = dummy_link();
let dir = temp.path().join("nested");
fs::create_dir(&dir).unwrap();
let summary = Summary {
numbered_chapters: vec![SummaryItem::Link(Link {
name: String::from("nested"),
location: Some(dir),
..Default::default()
})],
..Default::default()
};
let got = load_book_from_disk(&summary, temp.path());
assert!(got.is_err());
}
}

View File

@@ -1,106 +0,0 @@
extern crate rustc_serialize;
use self::rustc_serialize::json::Json;
use std::fs::File;
use std::io::Read;
use std::path::{Path, PathBuf};
#[derive(Debug, Clone)]
pub struct BookConfig {
pub title: String,
pub author: String,
root: PathBuf,
dest: PathBuf,
src: PathBuf,
pub indent_spaces: i32,
multilingual: bool,
}
impl BookConfig {
pub fn new(root: &Path) -> Self {
BookConfig {
title: String::new(),
author: String::new(),
root: root.to_owned(),
dest: PathBuf::from("book"),
src: PathBuf::from("src"),
indent_spaces: 4, // indentation used for SUMMARY.md
multilingual: false,
}
}
pub fn read_config(&mut self, root: &Path) -> &mut Self {
debug!("[fn]: read_config");
// If the file does not exist, return early
let mut config_file = match File::open(root.join("book.json")) {
Ok(f) => f,
Err(_) => {
debug!("[*]: Failed to open {:?}", root.join("book.json"));
return self
},
};
debug!("[*]: Reading config");
let mut data = String::new();
// Just return if an error occured.
// I would like to propagate the error, but I have to return `&self`
if let Err(_) = config_file.read_to_string(&mut data) { return self }
// Convert to JSON
if let Ok(config) = Json::from_str(&data) {
// Extract data
debug!("[*]: Extracting data from config");
// Title & author
if let Some(a) = config.find_path(&["title"]) { self.title = a.to_string().replace("\"", "") }
if let Some(a) = config.find_path(&["author"]) { self.author = a.to_string().replace("\"", "") }
// Destination
if let Some(a) = config.find_path(&["dest"]) {
let dest = PathBuf::from(&a.to_string().replace("\"", ""));
// If path is relative make it absolute from the parent directory of src
match dest.is_relative() {
true => {
let dest = self.get_root().join(&dest).to_owned();
self.set_dest(&dest);
},
false => { self.set_dest(&dest); },
}
}
}
self
}
pub fn get_root(&self) -> &Path {
&self.root
}
pub fn set_root(&mut self, root: &Path) -> &mut Self {
self.root = root.to_owned();
self
}
pub fn get_dest(&self) -> &Path {
&self.dest
}
pub fn set_dest(&mut self, dest: &Path) -> &mut Self {
self.dest = dest.to_owned();
self
}
pub fn get_src(&self) -> &Path {
&self.src
}
pub fn set_src(&mut self, src: &Path) -> &mut Self {
self.src = src.to_owned();
self
}
}

View File

@@ -1,89 +0,0 @@
extern crate rustc_serialize;
use self::rustc_serialize::json::{Json, ToJson};
use std::path::PathBuf;
use std::collections::BTreeMap;
#[derive(Debug, Clone)]
pub enum BookItem {
Chapter(String, Chapter), // String = section
Affix(Chapter),
Spacer,
}
#[derive(Debug, Clone)]
pub struct Chapter {
pub name: String,
pub path: PathBuf,
pub sub_items: Vec<BookItem>,
}
#[derive(Debug, Clone)]
pub struct BookItems<'a> {
pub items: &'a [BookItem],
pub current_index: usize,
pub stack: Vec<(&'a [BookItem], usize)>,
}
impl Chapter {
pub fn new(name: String, path: PathBuf) -> Self {
Chapter {
name: name,
path: path,
sub_items: vec![],
}
}
}
impl ToJson for Chapter {
fn to_json(&self) -> Json {
let mut m: BTreeMap<String, Json> = BTreeMap::new();
m.insert("name".to_owned(), self.name.to_json());
m.insert("path".to_owned(),self.path.to_str()
.expect("Json conversion failed for path").to_json()
);
m.to_json()
}
}
// Shamelessly copied from Rustbook
// (https://github.com/rust-lang/rust/blob/master/src/rustbook/book.rs)
impl<'a> Iterator for BookItems<'a> {
type Item = &'a BookItem;
fn next(&mut self) -> Option<&'a BookItem> {
loop {
if self.current_index >= self.items.len() {
match self.stack.pop() {
None => return None,
Some((parent_items, parent_idx)) => {
self.items = parent_items;
self.current_index = parent_idx + 1;
}
}
} else {
let cur = self.items.get(self.current_index).unwrap();
match *cur {
BookItem::Chapter(_, ref ch) | BookItem::Affix(ref ch) => {
self.stack.push((self.items, self.current_index));
self.items = &ch.sub_items[..];
self.current_index = 0;
},
BookItem::Spacer => {
self.current_index += 1;
}
}
return Some(cur)
}
}
}
}

224
src/book/init.rs Normal file
View File

@@ -0,0 +1,224 @@
use std::fs::{self, File};
use std::io::Write;
use std::path::PathBuf;
use super::MDBook;
use crate::config::Config;
use crate::errors::*;
use crate::theme;
use crate::utils::fs::write_file;
use log::{debug, error, info, trace};
/// A helper for setting up a new book and its directory structure.
#[derive(Debug, Clone, PartialEq)]
pub struct BookBuilder {
root: PathBuf,
create_gitignore: bool,
config: Config,
copy_theme: bool,
}
impl BookBuilder {
/// Create a new `BookBuilder` which will generate a book in the provided
/// root directory.
pub fn new<P: Into<PathBuf>>(root: P) -> BookBuilder {
BookBuilder {
root: root.into(),
create_gitignore: false,
config: Config::default(),
copy_theme: false,
}
}
/// Set the [`Config`] to be used.
pub fn with_config(&mut self, cfg: Config) -> &mut BookBuilder {
self.config = cfg;
self
}
/// Get the config used by the `BookBuilder`.
pub fn config(&self) -> &Config {
&self.config
}
/// Should the theme be copied into the generated book (so users can tweak
/// it)?
pub fn copy_theme(&mut self, copy: bool) -> &mut BookBuilder {
self.copy_theme = copy;
self
}
/// Should we create a `.gitignore` file?
pub fn create_gitignore(&mut self, create: bool) -> &mut BookBuilder {
self.create_gitignore = create;
self
}
/// Generate the actual book. This will:
///
/// - Create the directory structure.
/// - Stub out some dummy chapters and the `SUMMARY.md`.
/// - Create a `.gitignore` (if applicable)
/// - Create a themes directory and populate it (if applicable)
/// - Generate a `book.toml` file,
/// - Then load the book so we can build it or run tests.
pub fn build(&self) -> Result<MDBook> {
info!("Creating a new book with stub content");
self.create_directory_structure()
.with_context(|| "Unable to create directory structure")?;
self.create_stub_files()
.with_context(|| "Unable to create stub files")?;
if self.create_gitignore {
self.build_gitignore()
.with_context(|| "Unable to create .gitignore")?;
}
if self.copy_theme {
self.copy_across_theme()
.with_context(|| "Unable to copy across the theme")?;
}
self.write_book_toml()?;
match MDBook::load(&self.root) {
Ok(book) => Ok(book),
Err(e) => {
error!("{}", e);
panic!(
"The BookBuilder should always create a valid book. If you are seeing this it \
is a bug and should be reported."
);
}
}
}
fn write_book_toml(&self) -> Result<()> {
debug!("Writing book.toml");
let book_toml = self.root.join("book.toml");
let cfg = toml::to_string(&self.config)
.with_context(|| "Unable to serialize the config")?
.into_bytes();
File::create(book_toml)
.with_context(|| "Couldn't create book.toml")?
.write_all(&cfg)
.with_context(|| "Unable to write config to book.toml")?;
Ok(())
}
fn copy_across_theme(&self) -> Result<()> {
debug!("Copying theme");
let html_config = self.config.html_config().unwrap_or_default();
let themedir = html_config.theme_dir(&self.root);
if !themedir.exists() {
debug!(
"{} does not exist, creating the directory",
themedir.display()
);
fs::create_dir(&themedir)?;
}
let mut index = File::create(themedir.join("index.hbs"))?;
index.write_all(theme::INDEX)?;
let cssdir = themedir.join("css");
if !cssdir.exists() {
fs::create_dir(&cssdir)?;
}
let mut general_css = File::create(cssdir.join("general.css"))?;
general_css.write_all(theme::GENERAL_CSS)?;
let mut chrome_css = File::create(cssdir.join("chrome.css"))?;
chrome_css.write_all(theme::CHROME_CSS)?;
if html_config.print.enable {
let mut print_css = File::create(cssdir.join("print.css"))?;
print_css.write_all(theme::PRINT_CSS)?;
}
let mut variables_css = File::create(cssdir.join("variables.css"))?;
variables_css.write_all(theme::VARIABLES_CSS)?;
let mut favicon = File::create(themedir.join("favicon.png"))?;
favicon.write_all(theme::FAVICON_PNG)?;
let mut favicon = File::create(themedir.join("favicon.svg"))?;
favicon.write_all(theme::FAVICON_SVG)?;
let mut js = File::create(themedir.join("book.js"))?;
js.write_all(theme::JS)?;
let mut highlight_css = File::create(themedir.join("highlight.css"))?;
highlight_css.write_all(theme::HIGHLIGHT_CSS)?;
let mut highlight_js = File::create(themedir.join("highlight.js"))?;
highlight_js.write_all(theme::HIGHLIGHT_JS)?;
write_file(&themedir.join("fonts"), "fonts.css", theme::fonts::CSS)?;
for (file_name, contents) in theme::fonts::LICENSES {
write_file(&themedir, file_name, contents)?;
}
for (file_name, contents) in theme::fonts::OPEN_SANS.iter() {
write_file(&themedir, file_name, contents)?;
}
write_file(
&themedir,
theme::fonts::SOURCE_CODE_PRO.0,
theme::fonts::SOURCE_CODE_PRO.1,
)?;
Ok(())
}
fn build_gitignore(&self) -> Result<()> {
debug!("Creating .gitignore");
let mut f = File::create(self.root.join(".gitignore"))?;
writeln!(f, "{}", self.config.build.build_dir.display())?;
Ok(())
}
fn create_stub_files(&self) -> Result<()> {
debug!("Creating example book contents");
let src_dir = self.root.join(&self.config.book.src);
let summary = src_dir.join("SUMMARY.md");
if !summary.exists() {
trace!("No summary found creating stub summary and chapter_1.md.");
let mut f = File::create(&summary).with_context(|| "Unable to create SUMMARY.md")?;
writeln!(f, "# Summary")?;
writeln!(f)?;
writeln!(f, "- [Chapter 1](./chapter_1.md)")?;
let chapter_1 = src_dir.join("chapter_1.md");
let mut f =
File::create(&chapter_1).with_context(|| "Unable to create chapter_1.md")?;
writeln!(f, "# Chapter 1")?;
} else {
trace!("Existing summary found, no need to create stub files.");
}
Ok(())
}
fn create_directory_structure(&self) -> Result<()> {
debug!("Creating directory tree");
fs::create_dir_all(&self.root)?;
let src = self.root.join(&self.config.book.src);
fs::create_dir_all(&src)?;
let build = self.root.join(&self.config.build.build_dir);
fs::create_dir_all(&build)?;
Ok(())
}
}

View File

@@ -1,357 +0,0 @@
use std::path::{Path, PathBuf};
use std::fs::{self, File};
use std::error::Error;
use std::io;
use std::io::Write;
use std::io::ErrorKind;
use std::process::Command;
use {BookConfig, BookItem, theme, parse, utils};
use book::BookItems;
use renderer::{Renderer, HtmlHandlebars};
pub struct MDBook {
config: BookConfig,
pub content: Vec<BookItem>,
renderer: Box<Renderer>,
}
impl MDBook {
/// Create a new `MDBook` struct with root directory `root`
///
/// - The default source directory is set to `root/src`
/// - The default output directory is set to `root/book`
///
/// They can both be changed by using [`set_src()`](#method.set_src) and [`set_dest()`](#method.set_dest)
pub fn new(root: &Path) -> MDBook {
if !root.exists() || !root.is_dir() {
output!("{:?} No directory with that name", root);
}
MDBook {
content: vec![],
config: BookConfig::new(root)
.set_src(&root.join("src"))
.set_dest(&root.join("book"))
.to_owned(),
renderer: Box::new(HtmlHandlebars::new()),
}
}
/// Returns a flat depth-first iterator over the elements of the book, it returns an [BookItem enum](bookitem.html):
/// `(section: String, bookitem: &BookItem)`
///
/// ```no_run
/// # extern crate mdbook;
/// # use mdbook::MDBook;
/// # use mdbook::BookItem;
/// # use std::path::Path;
/// # fn main() {
/// # let mut book = MDBook::new(Path::new("mybook"));
/// for item in book.iter() {
/// match item {
/// &BookItem::Chapter(ref section, ref chapter) => {},
/// &BookItem::Affix(ref chapter) => {},
/// &BookItem::Spacer => {},
/// }
/// }
///
/// // would print something like this:
/// // 1. Chapter 1
/// // 1.1 Sub Chapter
/// // 1.2 Sub Chapter
/// // 2. Chapter 2
/// //
/// // etc.
/// # }
/// ```
pub fn iter(&self) -> BookItems {
BookItems {
items: &self.content[..],
current_index: 0,
stack: Vec::new(),
}
}
/// `init()` creates some boilerplate files and directories to get you started with your book.
///
/// ```text
/// book-test/
/// ├── book
/// └── src
/// ├── chapter_1.md
/// └── SUMMARY.md
/// ```
///
/// It uses the paths given as source and output directories and adds a `SUMMARY.md` and a
/// `chapter_1.md` to the source directory.
pub fn init(&mut self) -> Result<(), Box<Error>> {
debug!("[fn]: init");
if !self.config.get_root().exists() {
fs::create_dir_all(self.config.get_root()).unwrap();
output!("{:?} created", self.config.get_root());
}
{
let dest = self.config.get_dest();
let src = self.config.get_src();
if !dest.exists() {
debug!("[*]: {:?} does not exist, trying to create directory", dest);
try!(fs::create_dir(&dest));
}
if !src.exists() {
debug!("[*]: {:?} does not exist, trying to create directory", src);
try!(fs::create_dir(&src));
}
let summary = src.join("SUMMARY.md");
if !summary.exists() {
// Summary does not exist, create it
debug!("[*]: {:?} does not exist, trying to create SUMMARY.md", src.join("SUMMARY.md"));
let mut f = try!(File::create(&src.join("SUMMARY.md")));
debug!("[*]: Writing to SUMMARY.md");
try!(writeln!(f, "# Summary"));
try!(writeln!(f, ""));
try!(writeln!(f, "- [Chapter 1](./chapter_1.md)"));
}
}
// parse SUMMARY.md, and create the missing item related file
try!(self.parse_summary());
debug!("[*]: constructing paths for missing files");
for item in self.iter() {
debug!("[*]: item: {:?}", item);
match *item {
BookItem::Spacer => continue,
BookItem::Chapter(_, ref ch) | BookItem::Affix(ref ch) => {
if ch.path != PathBuf::new() {
let path = self.config.get_src().join(&ch.path);
if !path.exists() {
debug!("[*]: {:?} does not exist, trying to create file", path);
try!(::std::fs::create_dir_all(path.parent().unwrap()));
let mut f = try!(File::create(path));
//debug!("[*]: Writing to {:?}", path);
try!(writeln!(f, "# {}", ch.name));
}
}
}
}
}
debug!("[*]: init done");
Ok(())
}
/// The `build()` method is the one where everything happens. First it parses `SUMMARY.md` to
/// construct the book's structure in the form of a `Vec<BookItem>` and then calls `render()`
/// method of the current renderer.
///
/// It is the renderer who generates all the output files.
pub fn build(&mut self) -> Result<(), Box<Error>> {
debug!("[fn]: build");
try!(self.init());
// Clean output directory
try!(utils::remove_dir_content(&self.config.get_dest()));
try!(self.renderer.render(&self));
Ok(())
}
pub fn copy_theme(&self) -> Result<(), Box<Error>> {
debug!("[fn]: copy_theme");
let theme_dir = self.config.get_src().join("theme");
if !theme_dir.exists() {
debug!("[*]: {:?} does not exist, trying to create directory", theme_dir);
try!(fs::create_dir(&theme_dir));
}
// index.hbs
let mut index = try!(File::create(&theme_dir.join("index.hbs")));
try!(index.write_all(theme::INDEX));
// book.css
let mut css = try!(File::create(&theme_dir.join("book.css")));
try!(css.write_all(theme::CSS));
// book.js
let mut js = try!(File::create(&theme_dir.join("book.js")));
try!(js.write_all(theme::JS));
// highlight.css
let mut highlight_css = try!(File::create(&theme_dir.join("highlight.css")));
try!(highlight_css.write_all(theme::HIGHLIGHT_CSS));
// highlight.js
let mut highlight_js = try!(File::create(&theme_dir.join("highlight.js")));
try!(highlight_js.write_all(theme::HIGHLIGHT_JS));
Ok(())
}
/// Parses the `book.json` file (if it exists) to extract the configuration parameters.
/// The `book.json` file should be in the root directory of the book.
/// The root directory is the one specified when creating a new `MDBook`
///
/// ```no_run
/// # extern crate mdbook;
/// # use mdbook::MDBook;
/// # use std::path::Path;
/// # fn main() {
/// let mut book = MDBook::new(Path::new("root_dir"));
/// # }
/// ```
///
/// In this example, `root_dir` will be the root directory of our book and is specified in function
/// of the current working directory by using a relative path instead of an absolute path.
pub fn read_config(mut self) -> Self {
let root = self.config.get_root().to_owned();
self.config.read_config(&root);
self
}
/// You can change the default renderer to another one by using this method. The only requirement
/// is for your renderer to implement the [Renderer trait](../../renderer/renderer/trait.Renderer.html)
///
/// ```no_run
/// extern crate mdbook;
/// use mdbook::MDBook;
/// use mdbook::renderer::HtmlHandlebars;
/// # use std::path::Path;
///
/// fn main() {
/// let mut book = MDBook::new(Path::new("mybook"))
/// .set_renderer(Box::new(HtmlHandlebars::new()));
///
/// // In this example we replace the default renderer by the default renderer...
/// // Don't forget to put your renderer in a Box
/// }
/// ```
///
/// **note:** Don't forget to put your renderer in a `Box` before passing it to `set_renderer()`
pub fn set_renderer(mut self, renderer: Box<Renderer>) -> Self {
self.renderer = renderer;
self
}
pub fn test(&mut self) -> Result<(), Box<Error>> {
// read in the chapters
try!(self.parse_summary());
for item in self.iter() {
match *item {
BookItem::Chapter(_, ref ch) => {
if ch.path != PathBuf::new() {
let path = self.get_src().join(&ch.path);
println!("[*]: Testing file: {:?}", path);
let output_result = Command::new("rustdoc")
.arg(&path)
.arg("--test")
.output();
let output = try!(output_result);
if !output.status.success() {
return Err(Box::new(io::Error::new(ErrorKind::Other, format!(
"{}\n{}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)))) as Box<Error>);
}
}
}
_ => {}
}
}
Ok(())
}
pub fn set_dest(mut self, dest: &Path) -> Self {
// Handle absolute and relative paths
match dest.is_absolute() {
true => { self.config.set_dest(dest); },
false => {
let dest = self.config.get_root().join(dest).to_owned();
self.config.set_dest(&dest);
}
}
self
}
pub fn get_dest(&self) -> &Path {
self.config.get_dest()
}
pub fn set_src(mut self, src: &Path) -> Self {
// Handle absolute and relative paths
match src.is_absolute() {
true => { self.config.set_src(src); },
false => {
let src = self.config.get_root().join(src).to_owned();
self.config.set_src(&src);
}
}
self
}
pub fn get_src(&self) -> &Path {
self.config.get_src()
}
pub fn set_title(mut self, title: &str) -> Self {
self.config.title = title.to_owned();
self
}
pub fn get_title(&self) -> &str {
&self.config.title
}
pub fn set_author(mut self, author: &str) -> Self {
self.config.author = author.to_owned();
self
}
pub fn get_author(&self) -> &str {
&self.config.author
}
// Construct book
fn parse_summary(&mut self) -> Result<(), Box<Error>> {
// When append becomes stable, use self.content.append() ...
self.content = try!(parse::construct_bookitems(&self.config.get_src().join("SUMMARY.md")));
Ok(())
}
}

View File

@@ -1,7 +1,860 @@
pub mod mdbook;
pub mod bookitem;
pub mod bookconfig;
//! The internal representation of a book and infrastructure for loading it from
//! disk and building it.
//!
//! For examples on using `MDBook`, consult the [top-level documentation][1].
//!
//! [1]: ../index.html
pub use self::bookitem::{BookItem, BookItems};
pub use self::bookconfig::BookConfig;
pub use self::mdbook::MDBook;
#[allow(clippy::module_inception)]
mod book;
mod init;
mod summary;
pub use self::book::{load_book, Book, BookItem, BookItems, Chapter};
pub use self::init::BookBuilder;
pub use self::summary::{parse_summary, Link, SectionNumber, Summary, SummaryItem};
use log::{debug, error, info, log_enabled, trace, warn};
use std::io::Write;
use std::path::PathBuf;
use std::process::Command;
use std::string::ToString;
use tempfile::Builder as TempFileBuilder;
use toml::Value;
use topological_sort::TopologicalSort;
use crate::errors::*;
use crate::preprocess::{
CmdPreprocessor, IndexPreprocessor, LinkPreprocessor, Preprocessor, PreprocessorContext,
};
use crate::renderer::{CmdRenderer, HtmlHandlebars, MarkdownRenderer, RenderContext, Renderer};
use crate::utils;
use crate::config::{Config, RustEdition};
/// The object used to manage and build a book.
pub struct MDBook {
/// The book's root directory.
pub root: PathBuf,
/// The configuration used to tweak now a book is built.
pub config: Config,
/// A representation of the book's contents in memory.
pub book: Book,
renderers: Vec<Box<dyn Renderer>>,
/// List of pre-processors to be run on the book.
preprocessors: Vec<Box<dyn Preprocessor>>,
}
impl MDBook {
/// Load a book from its root directory on disk.
pub fn load<P: Into<PathBuf>>(book_root: P) -> Result<MDBook> {
let book_root = book_root.into();
let config_location = book_root.join("book.toml");
// the book.json file is no longer used, so we should emit a warning to
// let people know to migrate to book.toml
if book_root.join("book.json").exists() {
warn!("It appears you are still using book.json for configuration.");
warn!("This format is no longer used, so you should migrate to the");
warn!("book.toml format.");
warn!("Check the user guide for migration information:");
warn!("\thttps://rust-lang.github.io/mdBook/format/config.html");
}
let mut config = if config_location.exists() {
debug!("Loading config from {}", config_location.display());
Config::from_disk(&config_location)?
} else {
Config::default()
};
config.update_from_env();
if config
.html_config()
.map_or(false, |html| html.google_analytics.is_some())
{
warn!(
"The output.html.google-analytics field has been deprecated; \
it will be removed in a future release.\n\
Consider placing the appropriate site tag code into the \
theme/head.hbs file instead.\n\
The tracking code may be found in the Google Analytics Admin page.\n\
"
);
}
if log_enabled!(log::Level::Trace) {
for line in format!("Config: {:#?}", config).lines() {
trace!("{}", line);
}
}
MDBook::load_with_config(book_root, config)
}
/// Load a book from its root directory using a custom `Config`.
pub fn load_with_config<P: Into<PathBuf>>(book_root: P, config: Config) -> Result<MDBook> {
let root = book_root.into();
let src_dir = root.join(&config.book.src);
let book = book::load_book(&src_dir, &config.build)?;
let renderers = determine_renderers(&config);
let preprocessors = determine_preprocessors(&config)?;
Ok(MDBook {
root,
config,
book,
renderers,
preprocessors,
})
}
/// Load a book from its root directory using a custom `Config` and a custom summary.
pub fn load_with_config_and_summary<P: Into<PathBuf>>(
book_root: P,
config: Config,
summary: Summary,
) -> Result<MDBook> {
let root = book_root.into();
let src_dir = root.join(&config.book.src);
let book = book::load_book_from_disk(&summary, &src_dir)?;
let renderers = determine_renderers(&config);
let preprocessors = determine_preprocessors(&config)?;
Ok(MDBook {
root,
config,
book,
renderers,
preprocessors,
})
}
/// Returns a flat depth-first iterator over the elements of the book,
/// it returns a [`BookItem`] enum:
/// `(section: String, bookitem: &BookItem)`
///
/// ```no_run
/// # use mdbook::MDBook;
/// # use mdbook::book::BookItem;
/// # let book = MDBook::load("mybook").unwrap();
/// for item in book.iter() {
/// match *item {
/// BookItem::Chapter(ref chapter) => {},
/// BookItem::Separator => {},
/// BookItem::PartTitle(ref title) => {}
/// }
/// }
///
/// // would print something like this:
/// // 1. Chapter 1
/// // 1.1 Sub Chapter
/// // 1.2 Sub Chapter
/// // 2. Chapter 2
/// //
/// // etc.
/// ```
pub fn iter(&self) -> BookItems<'_> {
self.book.iter()
}
/// `init()` gives you a `BookBuilder` which you can use to setup a new book
/// and its accompanying directory structure.
///
/// The `BookBuilder` creates some boilerplate files and directories to get
/// you started with your book.
///
/// ```text
/// book-test/
/// ├── book
/// └── src
/// ├── chapter_1.md
/// └── SUMMARY.md
/// ```
///
/// It uses the path provided as the root directory for your book, then adds
/// in a `src/` directory containing a `SUMMARY.md` and `chapter_1.md` file
/// to get you started.
pub fn init<P: Into<PathBuf>>(book_root: P) -> BookBuilder {
BookBuilder::new(book_root)
}
/// Tells the renderer to build our book and put it in the build directory.
pub fn build(&self) -> Result<()> {
info!("Book building has started");
for renderer in &self.renderers {
self.execute_build_process(&**renderer)?;
}
Ok(())
}
/// Run the entire build process for a particular [`Renderer`].
pub fn execute_build_process(&self, renderer: &dyn Renderer) -> Result<()> {
let mut preprocessed_book = self.book.clone();
let preprocess_ctx = PreprocessorContext::new(
self.root.clone(),
self.config.clone(),
renderer.name().to_string(),
);
for preprocessor in &self.preprocessors {
if preprocessor_should_run(&**preprocessor, renderer, &self.config) {
debug!("Running the {} preprocessor.", preprocessor.name());
preprocessed_book = preprocessor.run(&preprocess_ctx, preprocessed_book)?;
}
}
let name = renderer.name();
let build_dir = self.build_dir_for(name);
let mut render_context = RenderContext::new(
self.root.clone(),
preprocessed_book,
self.config.clone(),
build_dir,
);
render_context
.chapter_titles
.extend(preprocess_ctx.chapter_titles.borrow_mut().drain());
info!("Running the {} backend", renderer.name());
renderer
.render(&render_context)
.with_context(|| "Rendering failed")
}
/// You can change the default renderer to another one by using this method.
/// The only requirement is that your renderer implement the [`Renderer`]
/// trait.
pub fn with_renderer<R: Renderer + 'static>(&mut self, renderer: R) -> &mut Self {
self.renderers.push(Box::new(renderer));
self
}
/// Register a [`Preprocessor`] to be used when rendering the book.
pub fn with_preprocessor<P: Preprocessor + 'static>(&mut self, preprocessor: P) -> &mut Self {
self.preprocessors.push(Box::new(preprocessor));
self
}
/// Run `rustdoc` tests on the book, linking against the provided libraries.
pub fn test(&mut self, library_paths: Vec<&str>) -> Result<()> {
// test_chapter with chapter:None will run all tests.
self.test_chapter(library_paths, None)
}
/// Run `rustdoc` tests on a specific chapter of the book, linking against the provided libraries.
/// If `chapter` is `None`, all tests will be run.
pub fn test_chapter(&mut self, library_paths: Vec<&str>, chapter: Option<&str>) -> Result<()> {
let library_args: Vec<&str> = (0..library_paths.len())
.map(|_| "-L")
.zip(library_paths.into_iter())
.flat_map(|x| vec![x.0, x.1])
.collect();
let temp_dir = TempFileBuilder::new().prefix("mdbook-").tempdir()?;
let mut chapter_found = false;
// FIXME: Is "test" the proper renderer name to use here?
let preprocess_context =
PreprocessorContext::new(self.root.clone(), self.config.clone(), "test".to_string());
let book = LinkPreprocessor::new().run(&preprocess_context, self.book.clone())?;
// Index Preprocessor is disabled so that chapter paths continue to point to the
// actual markdown files.
let mut failed = false;
for item in book.iter() {
if let BookItem::Chapter(ref ch) = *item {
let chapter_path = match ch.path {
Some(ref path) if !path.as_os_str().is_empty() => path,
_ => continue,
};
if let Some(chapter) = chapter {
if ch.name != chapter && chapter_path.to_str() != Some(chapter) {
if chapter == "?" {
info!("Skipping chapter '{}'...", ch.name);
}
continue;
}
}
chapter_found = true;
info!("Testing chapter '{}': {:?}", ch.name, chapter_path);
// write preprocessed file to tempdir
let path = temp_dir.path().join(&chapter_path);
let mut tmpf = utils::fs::create_file(&path)?;
tmpf.write_all(ch.content.as_bytes())?;
let mut cmd = Command::new("rustdoc");
cmd.arg(&path).arg("--test").args(&library_args);
if let Some(edition) = self.config.rust.edition {
match edition {
RustEdition::E2015 => {
cmd.args(&["--edition", "2015"]);
}
RustEdition::E2018 => {
cmd.args(&["--edition", "2018"]);
}
RustEdition::E2021 => {
cmd.args(&["--edition", "2021"]);
}
}
}
debug!("running {:?}", cmd);
let output = cmd.output()?;
if !output.status.success() {
failed = true;
error!(
"rustdoc returned an error:\n\
\n--- stdout\n{}\n--- stderr\n{}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);
}
}
}
if failed {
bail!("One or more tests failed");
}
if let Some(chapter) = chapter {
if !chapter_found {
bail!("Chapter not found: {}", chapter);
}
}
Ok(())
}
/// The logic for determining where a backend should put its build
/// artefacts.
///
/// If there is only 1 renderer, put it in the directory pointed to by the
/// `build.build_dir` key in [`Config`]. If there is more than one then the
/// renderer gets its own directory within the main build dir.
///
/// i.e. If there were only one renderer (in this case, the HTML renderer):
///
/// - build/
/// - index.html
/// - ...
///
/// Otherwise if there are multiple:
///
/// - build/
/// - epub/
/// - my_awesome_book.epub
/// - html/
/// - index.html
/// - ...
/// - latex/
/// - my_awesome_book.tex
///
pub fn build_dir_for(&self, backend_name: &str) -> PathBuf {
let build_dir = self.root.join(&self.config.build.build_dir);
if self.renderers.len() <= 1 {
build_dir
} else {
build_dir.join(backend_name)
}
}
/// Get the directory containing this book's source files.
pub fn source_dir(&self) -> PathBuf {
self.root.join(&self.config.book.src)
}
/// Get the directory containing the theme resources for the book.
pub fn theme_dir(&self) -> PathBuf {
self.config
.html_config()
.unwrap_or_default()
.theme_dir(&self.root)
}
}
/// Look at the `Config` and try to figure out what renderers to use.
fn determine_renderers(config: &Config) -> Vec<Box<dyn Renderer>> {
let mut renderers = Vec::new();
if let Some(output_table) = config.get("output").and_then(Value::as_table) {
renderers.extend(output_table.iter().map(|(key, table)| {
if key == "html" {
Box::new(HtmlHandlebars::new()) as Box<dyn Renderer>
} else if key == "markdown" {
Box::new(MarkdownRenderer::new()) as Box<dyn Renderer>
} else {
interpret_custom_renderer(key, table)
}
}));
}
// if we couldn't find anything, add the HTML renderer as a default
if renderers.is_empty() {
renderers.push(Box::new(HtmlHandlebars::new()));
}
renderers
}
const DEFAULT_PREPROCESSORS: &[&str] = &["links", "index"];
fn is_default_preprocessor(pre: &dyn Preprocessor) -> bool {
let name = pre.name();
name == LinkPreprocessor::NAME || name == IndexPreprocessor::NAME
}
/// Look at the `MDBook` and try to figure out what preprocessors to run.
fn determine_preprocessors(config: &Config) -> Result<Vec<Box<dyn Preprocessor>>> {
// Collect the names of all preprocessors intended to be run, and the order
// in which they should be run.
let mut preprocessor_names = TopologicalSort::<String>::new();
if config.build.use_default_preprocessors {
for name in DEFAULT_PREPROCESSORS {
preprocessor_names.insert(name.to_string());
}
}
if let Some(preprocessor_table) = config.get("preprocessor").and_then(Value::as_table) {
for (name, table) in preprocessor_table.iter() {
preprocessor_names.insert(name.to_string());
let exists = |name| {
(config.build.use_default_preprocessors && DEFAULT_PREPROCESSORS.contains(&name))
|| preprocessor_table.contains_key(name)
};
if let Some(before) = table.get("before") {
let before = before.as_array().ok_or_else(|| {
Error::msg(format!(
"Expected preprocessor.{}.before to be an array",
name
))
})?;
for after in before {
let after = after.as_str().ok_or_else(|| {
Error::msg(format!(
"Expected preprocessor.{}.before to contain strings",
name
))
})?;
if !exists(after) {
// Only warn so that preprocessors can be toggled on and off (e.g. for
// troubleshooting) without having to worry about order too much.
warn!(
"preprocessor.{}.after contains \"{}\", which was not found",
name, after
);
} else {
preprocessor_names.add_dependency(name, after);
}
}
}
if let Some(after) = table.get("after") {
let after = after.as_array().ok_or_else(|| {
Error::msg(format!(
"Expected preprocessor.{}.after to be an array",
name
))
})?;
for before in after {
let before = before.as_str().ok_or_else(|| {
Error::msg(format!(
"Expected preprocessor.{}.after to contain strings",
name
))
})?;
if !exists(before) {
// See equivalent warning above for rationale
warn!(
"preprocessor.{}.before contains \"{}\", which was not found",
name, before
);
} else {
preprocessor_names.add_dependency(before, name);
}
}
}
}
}
// Now that all links have been established, queue preprocessors in a suitable order
let mut preprocessors = Vec::with_capacity(preprocessor_names.len());
// `pop_all()` returns an empty vector when no more items are not being depended upon
for mut names in std::iter::repeat_with(|| preprocessor_names.pop_all())
.take_while(|names| !names.is_empty())
{
// The `topological_sort` crate does not guarantee a stable order for ties, even across
// runs of the same program. Thus, we break ties manually by sorting.
// Careful: `str`'s default sorting, which we are implicitly invoking here, uses code point
// values ([1]), which may not be an alphabetical sort.
// As mentioned in [1], doing so depends on locale, which is not desirable for deciding
// preprocessor execution order.
// [1]: https://doc.rust-lang.org/stable/std/cmp/trait.Ord.html#impl-Ord-14
names.sort();
for name in names {
let preprocessor: Box<dyn Preprocessor> = match name.as_str() {
"links" => Box::new(LinkPreprocessor::new()),
"index" => Box::new(IndexPreprocessor::new()),
_ => {
// The only way to request a custom preprocessor is through the `preprocessor`
// table, so it must exist, be a table, and contain the key.
let table = &config.get("preprocessor").unwrap().as_table().unwrap()[&name];
let command = get_custom_preprocessor_cmd(&name, table);
Box::new(CmdPreprocessor::new(name, command))
}
};
preprocessors.push(preprocessor);
}
}
// "If `pop_all` returns an empty vector and `len` is not 0, there are cyclic dependencies."
// Normally, `len() == 0` is equivalent to `is_empty()`, so we'll use that.
if preprocessor_names.is_empty() {
Ok(preprocessors)
} else {
Err(Error::msg("Cyclic dependency detected in preprocessors"))
}
}
fn get_custom_preprocessor_cmd(key: &str, table: &Value) -> String {
table
.get("command")
.and_then(Value::as_str)
.map(ToString::to_string)
.unwrap_or_else(|| format!("mdbook-{}", key))
}
fn interpret_custom_renderer(key: &str, table: &Value) -> Box<CmdRenderer> {
// look for the `command` field, falling back to using the key
// prepended by "mdbook-"
let table_dot_command = table
.get("command")
.and_then(Value::as_str)
.map(ToString::to_string);
let command = table_dot_command.unwrap_or_else(|| format!("mdbook-{}", key));
Box::new(CmdRenderer::new(key.to_string(), command))
}
/// Check whether we should run a particular `Preprocessor` in combination
/// with the renderer, falling back to `Preprocessor::supports_renderer()`
/// method if the user doesn't say anything.
///
/// The `build.use-default-preprocessors` config option can be used to ensure
/// default preprocessors always run if they support the renderer.
fn preprocessor_should_run(
preprocessor: &dyn Preprocessor,
renderer: &dyn Renderer,
cfg: &Config,
) -> bool {
// default preprocessors should be run by default (if supported)
if cfg.build.use_default_preprocessors && is_default_preprocessor(preprocessor) {
return preprocessor.supports_renderer(renderer.name());
}
let key = format!("preprocessor.{}.renderers", preprocessor.name());
let renderer_name = renderer.name();
if let Some(Value::Array(ref explicit_renderers)) = cfg.get(&key) {
return explicit_renderers
.iter()
.filter_map(Value::as_str)
.any(|name| name == renderer_name);
}
preprocessor.supports_renderer(renderer_name)
}
#[cfg(test)]
mod tests {
use super::*;
use std::str::FromStr;
use toml::value::{Table, Value};
#[test]
fn config_defaults_to_html_renderer_if_empty() {
let cfg = Config::default();
// make sure we haven't got anything in the `output` table
assert!(cfg.get("output").is_none());
let got = determine_renderers(&cfg);
assert_eq!(got.len(), 1);
assert_eq!(got[0].name(), "html");
}
#[test]
fn add_a_random_renderer_to_the_config() {
let mut cfg = Config::default();
cfg.set("output.random", Table::new()).unwrap();
let got = determine_renderers(&cfg);
assert_eq!(got.len(), 1);
assert_eq!(got[0].name(), "random");
}
#[test]
fn add_a_random_renderer_with_custom_command_to_the_config() {
let mut cfg = Config::default();
let mut table = Table::new();
table.insert("command".to_string(), Value::String("false".to_string()));
cfg.set("output.random", table).unwrap();
let got = determine_renderers(&cfg);
assert_eq!(got.len(), 1);
assert_eq!(got[0].name(), "random");
}
#[test]
fn config_defaults_to_link_and_index_preprocessor_if_not_set() {
let cfg = Config::default();
// make sure we haven't got anything in the `preprocessor` table
assert!(cfg.get("preprocessor").is_none());
let got = determine_preprocessors(&cfg);
assert!(got.is_ok());
assert_eq!(got.as_ref().unwrap().len(), 2);
assert_eq!(got.as_ref().unwrap()[0].name(), "index");
assert_eq!(got.as_ref().unwrap()[1].name(), "links");
}
#[test]
fn use_default_preprocessors_works() {
let mut cfg = Config::default();
cfg.build.use_default_preprocessors = false;
let got = determine_preprocessors(&cfg).unwrap();
assert_eq!(got.len(), 0);
}
#[test]
fn can_determine_third_party_preprocessors() {
let cfg_str = r#"
[book]
title = "Some Book"
[preprocessor.random]
[build]
build-dir = "outputs"
create-missing = false
"#;
let cfg = Config::from_str(cfg_str).unwrap();
// make sure the `preprocessor.random` table exists
assert!(cfg.get_preprocessor("random").is_some());
let got = determine_preprocessors(&cfg).unwrap();
assert!(got.into_iter().any(|p| p.name() == "random"));
}
#[test]
fn preprocessors_can_provide_their_own_commands() {
let cfg_str = r#"
[preprocessor.random]
command = "python random.py"
"#;
let cfg = Config::from_str(cfg_str).unwrap();
// make sure the `preprocessor.random` table exists
let random = cfg.get_preprocessor("random").unwrap();
let random = get_custom_preprocessor_cmd("random", &Value::Table(random.clone()));
assert_eq!(random, "python random.py");
}
#[test]
fn preprocessor_before_must_be_array() {
let cfg_str = r#"
[preprocessor.random]
before = 0
"#;
let cfg = Config::from_str(cfg_str).unwrap();
assert!(determine_preprocessors(&cfg).is_err());
}
#[test]
fn preprocessor_after_must_be_array() {
let cfg_str = r#"
[preprocessor.random]
after = 0
"#;
let cfg = Config::from_str(cfg_str).unwrap();
assert!(determine_preprocessors(&cfg).is_err());
}
#[test]
fn preprocessor_order_is_honored() {
let cfg_str = r#"
[preprocessor.random]
before = [ "last" ]
after = [ "index" ]
[preprocessor.last]
after = [ "links", "index" ]
"#;
let cfg = Config::from_str(cfg_str).unwrap();
let preprocessors = determine_preprocessors(&cfg).unwrap();
let index = |name| {
preprocessors
.iter()
.enumerate()
.find(|(_, preprocessor)| preprocessor.name() == name)
.unwrap()
.0
};
let assert_before = |before, after| {
if index(before) >= index(after) {
eprintln!("Preprocessor order:");
for preprocessor in &preprocessors {
eprintln!(" {}", preprocessor.name());
}
panic!("{} should come before {}", before, after);
}
};
assert_before("index", "random");
assert_before("index", "last");
assert_before("random", "last");
assert_before("links", "last");
}
#[test]
fn cyclic_dependencies_are_detected() {
let cfg_str = r#"
[preprocessor.links]
before = [ "index" ]
[preprocessor.index]
before = [ "links" ]
"#;
let cfg = Config::from_str(cfg_str).unwrap();
assert!(determine_preprocessors(&cfg).is_err());
}
#[test]
fn dependencies_dont_register_undefined_preprocessors() {
let cfg_str = r#"
[preprocessor.links]
before = [ "random" ]
"#;
let cfg = Config::from_str(cfg_str).unwrap();
let preprocessors = determine_preprocessors(&cfg).unwrap();
assert!(!preprocessors
.iter()
.any(|preprocessor| preprocessor.name() == "random"));
}
#[test]
fn dependencies_dont_register_builtin_preprocessors_if_disabled() {
let cfg_str = r#"
[preprocessor.random]
before = [ "links" ]
[build]
use-default-preprocessors = false
"#;
let cfg = Config::from_str(cfg_str).unwrap();
let preprocessors = determine_preprocessors(&cfg).unwrap();
assert!(!preprocessors
.iter()
.any(|preprocessor| preprocessor.name() == "links"));
}
#[test]
fn config_respects_preprocessor_selection() {
let cfg_str = r#"
[preprocessor.links]
renderers = ["html"]
"#;
let cfg = Config::from_str(cfg_str).unwrap();
// double-check that we can access preprocessor.links.renderers[0]
let html = cfg
.get_preprocessor("links")
.and_then(|links| links.get("renderers"))
.and_then(Value::as_array)
.and_then(|renderers| renderers.get(0))
.and_then(Value::as_str)
.unwrap();
assert_eq!(html, "html");
let html_renderer = HtmlHandlebars::default();
let pre = LinkPreprocessor::new();
let should_run = preprocessor_should_run(&pre, &html_renderer, &cfg);
assert!(should_run);
}
struct BoolPreprocessor(bool);
impl Preprocessor for BoolPreprocessor {
fn name(&self) -> &str {
"bool-preprocessor"
}
fn run(&self, _ctx: &PreprocessorContext, _book: Book) -> Result<Book> {
unimplemented!()
}
fn supports_renderer(&self, _renderer: &str) -> bool {
self.0
}
}
#[test]
fn preprocessor_should_run_falls_back_to_supports_renderer_method() {
let cfg = Config::default();
let html = HtmlHandlebars::new();
let should_be = true;
let got = preprocessor_should_run(&BoolPreprocessor(should_be), &html, &cfg);
assert_eq!(got, should_be);
let should_be = false;
let got = preprocessor_should_run(&BoolPreprocessor(should_be), &html, &cfg);
assert_eq!(got, should_be);
}
}

1098
src/book/summary.rs Normal file

File diff suppressed because it is too large Load Diff

38
src/cmd/build.rs Normal file
View File

@@ -0,0 +1,38 @@
use super::command_prelude::*;
use crate::{get_book_dir, open};
use mdbook::errors::Result;
use mdbook::MDBook;
use std::path::PathBuf;
// Create clap subcommand arguments
pub fn make_subcommand() -> Command {
Command::new("build")
.about("Builds a book from its markdown files")
.arg_dest_dir()
.arg_root_dir()
.arg_open()
}
// Build command implementation
pub fn execute(args: &ArgMatches) -> Result<()> {
let book_dir = get_book_dir(args);
let mut book = MDBook::load(&book_dir)?;
if let Some(dest_dir) = args.get_one::<PathBuf>("dest-dir") {
book.config.build.build_dir = dest_dir.into();
}
book.build()?;
if args.get_flag("open") {
// FIXME: What's the right behaviour if we don't use the HTML renderer?
let path = book.build_dir_for("html").join("index.html");
if !path.exists() {
error!("No chapter available to open");
std::process::exit(1)
}
open(path);
}
Ok(())
}

32
src/cmd/clean.rs Normal file
View File

@@ -0,0 +1,32 @@
use super::command_prelude::*;
use crate::get_book_dir;
use anyhow::Context;
use mdbook::MDBook;
use std::fs;
use std::path::PathBuf;
// Create clap subcommand arguments
pub fn make_subcommand() -> Command {
Command::new("clean")
.about("Deletes a built book")
.arg_dest_dir()
.arg_root_dir()
}
// Clean command implementation
pub fn execute(args: &ArgMatches) -> mdbook::errors::Result<()> {
let book_dir = get_book_dir(args);
let book = MDBook::load(&book_dir)?;
let dir_to_remove = match args.get_one::<PathBuf>("dest-dir") {
Some(dest_dir) => dest_dir.into(),
None => book.root.join(&book.config.build.build_dir),
};
if dir_to_remove.exists() {
fs::remove_dir_all(&dir_to_remove)
.with_context(|| "Unable to remove the build directory")?;
}
Ok(())
}

View File

@@ -0,0 +1,45 @@
//! Helpers for building the command-line arguments for commands.
pub use clap::{arg, Arg, ArgMatches, Command};
use std::path::PathBuf;
pub trait CommandExt: Sized {
fn _arg(self, arg: Arg) -> Self;
fn arg_dest_dir(self) -> Self {
self._arg(
Arg::new("dest-dir")
.short('d')
.long("dest-dir")
.value_name("dest-dir")
.value_parser(clap::value_parser!(PathBuf))
.help(
"Output directory for the book\n\
Relative paths are interpreted relative to the book's root directory.\n\
If omitted, mdBook uses build.build-dir from book.toml \
or defaults to `./book`.",
),
)
}
fn arg_root_dir(self) -> Self {
self._arg(
Arg::new("dir")
.help(
"Root directory for the book\n\
(Defaults to the current directory when omitted)",
)
.value_parser(clap::value_parser!(PathBuf)),
)
}
fn arg_open(self) -> Self {
self._arg(arg!(-o --open "Opens the compiled book in a web browser"))
}
}
impl CommandExt for Command {
fn _arg(self, arg: Arg) -> Self {
self.arg(arg)
}
}

118
src/cmd/init.rs Normal file
View File

@@ -0,0 +1,118 @@
use crate::get_book_dir;
use clap::{arg, ArgMatches, Command as ClapCommand};
use mdbook::config;
use mdbook::errors::Result;
use mdbook::MDBook;
use std::io;
use std::io::Write;
use std::process::Command;
// Create clap subcommand arguments
pub fn make_subcommand() -> ClapCommand {
ClapCommand::new("init")
.about("Creates the boilerplate structure and files for a new book")
.arg(
arg!([dir]
"Directory to create the book in\n\
(Defaults to the current directory when omitted)"
)
.value_parser(clap::value_parser!(std::path::PathBuf)),
)
.arg(arg!(--theme "Copies the default theme into your source folder"))
.arg(arg!(--force "Skips confirmation prompts"))
.arg(arg!(--title <title> "Sets the book title"))
.arg(
arg!(--ignore <ignore> "Creates a VCS ignore file (i.e. .gitignore)")
.value_parser(["none", "git"]),
)
}
// Init command implementation
pub fn execute(args: &ArgMatches) -> Result<()> {
let book_dir = get_book_dir(args);
let mut builder = MDBook::init(&book_dir);
let mut config = config::Config::default();
// If flag `--theme` is present, copy theme to src
if args.get_flag("theme") {
let theme_dir = book_dir.join("theme");
println!();
println!("Copying the default theme to {}", theme_dir.display());
// Skip this if `--force` is present
if !args.get_flag("force") && theme_dir.exists() {
println!("This could potentially overwrite files already present in that directory.");
print!("\nAre you sure you want to continue? (y/n) ");
// Read answer from user and exit if it's not 'yes'
if confirm() {
builder.copy_theme(true);
}
} else {
builder.copy_theme(true);
}
}
if let Some(ignore) = args.get_one::<String>("ignore").map(|s| s.as_str()) {
match ignore {
"git" => builder.create_gitignore(true),
_ => builder.create_gitignore(false),
};
} else {
println!("\nDo you want a .gitignore to be created? (y/n)");
if confirm() {
builder.create_gitignore(true);
}
}
config.book.title = if args.contains_id("title") {
args.get_one::<String>("title").map(String::from)
} else {
request_book_title()
};
if let Some(author) = get_author_name() {
debug!("Obtained user name from gitconfig: {:?}", author);
config.book.authors.push(author);
builder.with_config(config);
}
builder.build()?;
println!("\nAll done, no errors...");
Ok(())
}
/// Obtains author name from git config file by running the `git config` command.
fn get_author_name() -> Option<String> {
let output = Command::new("git")
.args(&["config", "--get", "user.name"])
.output()
.ok()?;
if output.status.success() {
Some(String::from_utf8_lossy(&output.stdout).trim().to_owned())
} else {
None
}
}
/// Request book title from user and return if provided.
fn request_book_title() -> Option<String> {
println!("What title would you like to give the book? ");
io::stdout().flush().unwrap();
let mut resp = String::new();
io::stdin().read_line(&mut resp).unwrap();
let resp = resp.trim();
if resp.is_empty() {
None
} else {
Some(resp.into())
}
}
// Simple function for user confirmation
fn confirm() -> bool {
io::stdout().flush().unwrap();
let mut s = String::new();
io::stdin().read_line(&mut s).ok();
matches!(&*s.trim(), "Y" | "y" | "yes" | "Yes")
}

11
src/cmd/mod.rs Normal file
View File

@@ -0,0 +1,11 @@
//! Subcommand modules for the `mdbook` binary.
pub mod build;
pub mod clean;
pub mod command_prelude;
pub mod init;
#[cfg(feature = "serve")]
pub mod serve;
pub mod test;
#[cfg(feature = "watch")]
pub mod watch;

164
src/cmd/serve.rs Normal file
View File

@@ -0,0 +1,164 @@
use super::command_prelude::*;
#[cfg(feature = "watch")]
use super::watch;
use crate::{get_book_dir, open};
use clap::builder::NonEmptyStringValueParser;
use futures_util::sink::SinkExt;
use futures_util::StreamExt;
use mdbook::errors::*;
use mdbook::utils;
use mdbook::utils::fs::get_404_output_file;
use mdbook::MDBook;
use std::net::{SocketAddr, ToSocketAddrs};
use std::path::PathBuf;
use tokio::sync::broadcast;
use warp::ws::Message;
use warp::Filter;
/// The HTTP endpoint for the websocket used to trigger reloads when a file changes.
const LIVE_RELOAD_ENDPOINT: &str = "__livereload";
// Create clap subcommand arguments
pub fn make_subcommand() -> Command {
Command::new("serve")
.about("Serves a book at http://localhost:3000, and rebuilds it on changes")
.arg_dest_dir()
.arg_root_dir()
.arg(
Arg::new("hostname")
.short('n')
.long("hostname")
.num_args(1)
.default_value("localhost")
.value_parser(NonEmptyStringValueParser::new())
.help("Hostname to listen on for HTTP connections"),
)
.arg(
Arg::new("port")
.short('p')
.long("port")
.num_args(1)
.default_value("3000")
.value_parser(NonEmptyStringValueParser::new())
.help("Port to use for HTTP connections"),
)
.arg_open()
}
// Serve command implementation
pub fn execute(args: &ArgMatches) -> Result<()> {
let book_dir = get_book_dir(args);
let mut book = MDBook::load(&book_dir)?;
let port = args.get_one::<String>("port").unwrap();
let hostname = args.get_one::<String>("hostname").unwrap();
let open_browser = args.get_flag("open");
let address = format!("{}:{}", hostname, port);
let update_config = |book: &mut MDBook| {
book.config
.set("output.html.live-reload-endpoint", LIVE_RELOAD_ENDPOINT)
.expect("live-reload-endpoint update failed");
if let Some(dest_dir) = args.get_one::<PathBuf>("dest-dir") {
book.config.build.build_dir = dest_dir.into();
}
// Override site-url for local serving of the 404 file
book.config.set("output.html.site-url", "/").unwrap();
};
update_config(&mut book);
book.build()?;
let sockaddr: SocketAddr = address
.to_socket_addrs()?
.next()
.ok_or_else(|| anyhow::anyhow!("no address found for {}", address))?;
let build_dir = book.build_dir_for("html");
let input_404 = book
.config
.get("output.html.input-404")
.and_then(toml::Value::as_str)
.map(ToString::to_string);
let file_404 = get_404_output_file(&input_404);
// A channel used to broadcast to any websockets to reload when a file changes.
let (tx, _rx) = tokio::sync::broadcast::channel::<Message>(100);
let reload_tx = tx.clone();
let thread_handle = std::thread::spawn(move || {
serve(build_dir, sockaddr, reload_tx, &file_404);
});
let serving_url = format!("http://{}", address);
info!("Serving on: {}", serving_url);
if open_browser {
open(serving_url);
}
#[cfg(feature = "watch")]
watch::trigger_on_change(&book, move |paths, book_dir| {
info!("Files changed: {:?}", paths);
info!("Building book...");
// FIXME: This area is really ugly because we need to re-set livereload :(
let result = MDBook::load(&book_dir).and_then(|mut b| {
update_config(&mut b);
b.build()
});
if let Err(e) = result {
error!("Unable to load the book");
utils::log_backtrace(&e);
} else {
let _ = tx.send(Message::text("reload"));
}
});
let _ = thread_handle.join();
Ok(())
}
#[tokio::main]
async fn serve(
build_dir: PathBuf,
address: SocketAddr,
reload_tx: broadcast::Sender<Message>,
file_404: &str,
) {
// A warp Filter which captures `reload_tx` and provides an `rx` copy to
// receive reload messages.
let sender = warp::any().map(move || reload_tx.subscribe());
// A warp Filter to handle the livereload endpoint. This upgrades to a
// websocket, and then waits for any filesystem change notifications, and
// relays them over the websocket.
let livereload = warp::path(LIVE_RELOAD_ENDPOINT)
.and(warp::ws())
.and(sender)
.map(|ws: warp::ws::Ws, mut rx: broadcast::Receiver<Message>| {
ws.on_upgrade(move |ws| async move {
let (mut user_ws_tx, _user_ws_rx) = ws.split();
trace!("websocket got connection");
if let Ok(m) = rx.recv().await {
trace!("notify of reload");
let _ = user_ws_tx.send(m).await;
}
})
});
// A warp Filter that serves from the filesystem.
let book_route = warp::fs::dir(build_dir.clone());
// The fallback route for 404 errors
let fallback_route = warp::fs::file(build_dir.join(file_404))
.map(|reply| warp::reply::with_status(reply, warp::http::StatusCode::NOT_FOUND));
let routes = livereload.or(book_route).or(fallback_route);
std::panic::set_hook(Box::new(move |panic_info| {
// exit if serve panics
error!("Unable to serve: {}", panic_info);
std::process::exit(1);
}));
warp::serve(routes).run(address).await;
}

58
src/cmd/test.rs Normal file
View File

@@ -0,0 +1,58 @@
use super::command_prelude::*;
use crate::get_book_dir;
use clap::builder::NonEmptyStringValueParser;
use clap::{Arg, ArgAction, ArgMatches, Command};
use mdbook::errors::Result;
use mdbook::MDBook;
use std::path::PathBuf;
// Create clap subcommand arguments
pub fn make_subcommand() -> Command {
Command::new("test")
.about("Tests that a book's Rust code samples compile")
// FIXME: --dest-dir is unused by the test command, it should be removed
.arg_dest_dir()
.arg_root_dir()
.arg(
Arg::new("chapter")
.short('c')
.long("chapter")
.value_name("chapter"),
)
.arg(
Arg::new("library-path")
.short('L')
.long("library-path")
.value_name("dir")
.value_delimiter(',')
.value_parser(NonEmptyStringValueParser::new())
.action(ArgAction::Append)
.help(
"A comma-separated list of directories to add to the crate \
search path when building tests",
),
)
}
// test command implementation
pub fn execute(args: &ArgMatches) -> Result<()> {
let library_paths: Vec<&str> = args
.get_many("library-path")
.map(|it| it.map(String::as_str).collect())
.unwrap_or_default();
let chapter: Option<&str> = args.get_one::<String>("chapter").map(|s| s.as_str());
let book_dir = get_book_dir(args);
let mut book = MDBook::load(&book_dir)?;
if let Some(dest_dir) = args.get_one::<PathBuf>("dest-dir") {
book.config.build.build_dir = dest_dir.to_path_buf();
}
match chapter {
Some(_) => book.test_chapter(library_paths, chapter),
None => book.test(library_paths),
}?;
Ok(())
}

180
src/cmd/watch.rs Normal file
View File

@@ -0,0 +1,180 @@
use super::command_prelude::*;
use crate::{get_book_dir, open};
use mdbook::errors::Result;
use mdbook::utils;
use mdbook::MDBook;
use std::path::{Path, PathBuf};
use std::sync::mpsc::channel;
use std::thread::sleep;
use std::time::Duration;
// Create clap subcommand arguments
pub fn make_subcommand() -> Command {
Command::new("watch")
.about("Watches a book's files and rebuilds it on changes")
.arg_dest_dir()
.arg_root_dir()
.arg_open()
}
// Watch command implementation
pub fn execute(args: &ArgMatches) -> Result<()> {
let book_dir = get_book_dir(args);
let mut book = MDBook::load(&book_dir)?;
let update_config = |book: &mut MDBook| {
if let Some(dest_dir) = args.get_one::<PathBuf>("dest-dir") {
book.config.build.build_dir = dest_dir.into();
}
};
update_config(&mut book);
if args.get_flag("open") {
book.build()?;
let path = book.build_dir_for("html").join("index.html");
if !path.exists() {
error!("No chapter available to open");
std::process::exit(1)
}
open(path);
}
trigger_on_change(&book, |paths, book_dir| {
info!("Files changed: {:?}\nBuilding book...\n", paths);
let result = MDBook::load(&book_dir).and_then(|mut b| {
update_config(&mut b);
b.build()
});
if let Err(e) = result {
error!("Unable to build the book");
utils::log_backtrace(&e);
}
});
Ok(())
}
fn remove_ignored_files(book_root: &Path, paths: &[PathBuf]) -> Vec<PathBuf> {
if paths.is_empty() {
return vec![];
}
match find_gitignore(book_root) {
Some(gitignore_path) => {
match gitignore::File::new(gitignore_path.as_path()) {
Ok(exclusion_checker) => filter_ignored_files(exclusion_checker, paths),
Err(_) => {
// We're unable to read the .gitignore file, so we'll silently allow everything.
// Please see discussion: https://github.com/rust-lang/mdBook/pull/1051
paths.iter().map(|path| path.to_path_buf()).collect()
}
}
}
None => {
// There is no .gitignore file.
paths.iter().map(|path| path.to_path_buf()).collect()
}
}
}
fn find_gitignore(book_root: &Path) -> Option<PathBuf> {
book_root
.ancestors()
.map(|p| p.join(".gitignore"))
.find(|p| p.exists())
}
fn filter_ignored_files(exclusion_checker: gitignore::File, paths: &[PathBuf]) -> Vec<PathBuf> {
paths
.iter()
.filter(|path| match exclusion_checker.is_excluded(path) {
Ok(exclude) => !exclude,
Err(error) => {
warn!(
"Unable to determine if {:?} is excluded: {:?}. Including it.",
&path, error
);
true
}
})
.map(|path| path.to_path_buf())
.collect()
}
/// Calls the closure when a book source file is changed, blocking indefinitely.
pub fn trigger_on_change<F>(book: &MDBook, closure: F)
where
F: Fn(Vec<PathBuf>, &Path),
{
use notify::RecursiveMode::*;
// Create a channel to receive the events.
let (tx, rx) = channel();
let mut debouncer = match notify_debouncer_mini::new_debouncer(Duration::from_secs(1), None, tx)
{
Ok(d) => d,
Err(e) => {
error!("Error while trying to watch the files:\n\n\t{:?}", e);
std::process::exit(1)
}
};
let watcher = debouncer.watcher();
// Add the source directory to the watcher
if let Err(e) = watcher.watch(&book.source_dir(), Recursive) {
error!("Error while watching {:?}:\n {:?}", book.source_dir(), e);
std::process::exit(1);
};
let _ = watcher.watch(&book.theme_dir(), Recursive);
// Add the book.toml file to the watcher if it exists
let _ = watcher.watch(&book.root.join("book.toml"), NonRecursive);
for dir in &book.config.build.extra_watch_dirs {
let path = dir.canonicalize().unwrap();
if let Err(e) = watcher.watch(&path, Recursive) {
error!(
"Error while watching extra directory {:?}:\n {:?}",
path, e
);
std::process::exit(1);
}
}
info!("Listening for changes...");
loop {
let first_event = rx.recv().unwrap();
sleep(Duration::from_millis(50));
let other_events = rx.try_iter();
let all_events = std::iter::once(first_event).chain(other_events);
let paths: Vec<_> = all_events
.filter_map(|event| match event {
Ok(events) => Some(events),
Err(errors) => {
for error in errors {
log::warn!("error while watching for changes: {error}");
}
None
}
})
.flatten()
.map(|event| event.path)
.collect();
// If we are watching files outside the current repository (via extra-watch-dirs), then they are definitionally
// ignored by gitignore. So we handle this case by including such files into the watched paths list.
let any_external_paths = paths.iter().filter(|p| !p.starts_with(&book.root)).cloned();
let mut paths = remove_ignored_files(&book.root, &paths[..]);
paths.extend(any_external_paths);
if !paths.is_empty() {
closure(paths, &book.root);
}
}
}

1196
src/config.rs Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,83 +1,108 @@
//! # mdBook
//!
//! **mdBook** is similar to Gitbook but implemented in Rust.
//! It offers a command line interface, but can also be used as a regular crate.
//! **mdBook** is a tool for rendering a collection of markdown documents into
//! a form more suitable for end users like HTML or EPUB. It offers a command
//! line interface, but this crate can be used if more control is required.
//!
//! This is the API doc, but you can find a [less "low-level" documentation here](../index.html) that
//! contains information about the command line tool, format, structure etc.
//! It is also rendered with mdBook to showcase the features and default theme.
//! This is the API doc, the [user guide] is also available if you want
//! information about the command line tool, format, structure etc. It is also
//! rendered with mdBook to showcase the features and default theme.
//!
//! Some reasons why you would want to use the crate (over the cli):
//!
//! - Integrate mdbook in a current project
//! - Extend the capabilities of mdBook
//! - Do some processing or test before building your book
//! - Write a new Renderer
//! - Accessing the public API to help create a new Renderer
//! - ...
//!
//! ## Example
//! > **Note:** While we try to ensure `mdbook`'s command-line interface and
//! > behaviour are backwards compatible, the tool's internals are still
//! > evolving and being iterated on. If you wish to prevent accidental
//! > breakages it is recommended to pin any tools building on top of the
//! > `mdbook` crate to a specific release.
//!
//! ```no_run
//! extern crate mdbook;
//! # Examples
//!
//! If creating a new book from scratch, you'll want to get a `BookBuilder` via
//! the `MDBook::init()` method.
//!
//! ```rust,no_run
//! use mdbook::MDBook;
//! use std::path::Path;
//! use mdbook::config::Config;
//!
//! fn main() {
//! let mut book = MDBook::new(Path::new("my-book")) // Path to root
//! .set_src(Path::new("src")) // Path from root to source directory
//! .set_dest(Path::new("book")) // Path from root to output directory
//! .read_config(); // Parse book.json file for configuration
//! let root_dir = "/path/to/book/root";
//!
//! book.build().unwrap(); // Render the book
//! }
//! // create a default config and change a couple things
//! let mut cfg = Config::default();
//! cfg.book.title = Some("My Book".to_string());
//! cfg.book.authors.push("Michael-F-Bryan".to_string());
//!
//! MDBook::init(root_dir)
//! .create_gitignore(true)
//! .with_config(cfg)
//! .build()
//! .expect("Book generation failed");
//! ```
//!
//! ## Implementing a new Renderer
//! You can also load an existing book and build it.
//!
//! If you want to create a new renderer for mdBook, the only thing you have to do is to implement
//! the [Renderer trait](renderer/renderer/trait.Renderer.html)
//! ```rust,no_run
//! use mdbook::MDBook;
//!
//! And then you can swap in your renderer like this:
//! let root_dir = "/path/to/book/root";
//!
//! ```no_run
//! # extern crate mdbook;
//! #
//! # use mdbook::MDBook;
//! # use mdbook::renderer::HtmlHandlebars;
//! # use std::path::Path;
//! #
//! # fn main() {
//! # let your_renderer = HtmlHandlebars::new();
//! #
//! let book = MDBook::new(Path::new("my-book")).set_renderer(Box::new(your_renderer));
//! # }
//! let mut md = MDBook::load(root_dir)
//! .expect("Unable to load the book");
//! md.build().expect("Building failed");
//! ```
//! If you make a renderer, you get the book constructed in form of `Vec<BookItems>` and you get
//! the book config in a `BookConfig` struct.
//!
//! It's your responsability to create the necessary files in the correct directories.
//! ## Implementing a new Backend
//!
//! ## utils
//! `mdbook` has a fairly flexible mechanism for creating additional backends
//! for your book. The general idea is you'll add an extra table in the book's
//! `book.toml` which specifies an executable to be invoked by `mdbook`. This
//! executable will then be called during a build, with an in-memory
//! representation ([`RenderContext`]) of the book being passed to the
//! subprocess via `stdin`.
//!
//! I have regrouped some useful functions in the [utils](utils/index.html) module, like the following function
//! The [`RenderContext`] gives the backend access to the contents of
//! `book.toml` and lets it know which directory all generated artefacts should
//! be placed in. For a much more in-depth explanation, consult the [relevant
//! chapter] in the *For Developers* section of the user guide.
//!
//! ```ignore
//! utils::create_path(path: &Path)
//! ```
//! This function creates all the directories in a given path if they do not exist
//! To make creating a backend easier, the `mdbook` crate can be imported
//! directly, making deserializing the `RenderContext` easy and giving you
//! access to the various methods for working with the [`Config`].
//!
//! Make sure to take a look at it.
//! [user guide]: https://rust-lang.github.io/mdBook/
//! [`RenderContext`]: renderer::RenderContext
//! [relevant chapter]: https://rust-lang.github.io/mdBook/for_developers/backends.html
//! [`Config`]: config::Config
#![deny(missing_docs)]
#![deny(rust_2018_idioms)]
#[macro_use]
pub mod macros;
pub mod book;
mod parse;
pub mod config;
pub mod preprocess;
pub mod renderer;
pub mod theme;
pub mod utils;
pub use book::MDBook;
pub use book::BookItem;
pub use book::BookConfig;
pub use renderer::Renderer;
/// The current version of `mdbook`.
///
/// This is provided as a way for custom preprocessors and renderers to do
/// compatibility checks.
pub const MDBOOK_VERSION: &str = env!("CARGO_PKG_VERSION");
pub use crate::book::BookItem;
pub use crate::book::MDBook;
pub use crate::config::Config;
pub use crate::renderer::Renderer;
/// The error types used through out this crate.
pub mod errors {
pub(crate) use anyhow::{bail, ensure, Context};
pub use anyhow::{Error, Result};
}

View File

@@ -1,23 +0,0 @@
#[cfg(feature = "debug")]
macro_rules! debug {
($fmt:expr) => (println!($fmt));
($fmt:expr, $($arg:tt)*) => (println!($fmt, $($arg)*));
}
#[cfg(not(feature = "debug"))]
macro_rules! debug {
($fmt:expr) => ();
($fmt:expr, $($arg:tt)*) => ();
}
#[cfg(feature = "output")]
macro_rules! output {
($fmt:expr) => (println!($fmt));
($fmt:expr, $($arg:tt)*) => (println!($fmt, $($arg)*));
}
#[cfg(not(feature = "output"))]
macro_rules! output {
($fmt:expr) => ();
($fmt:expr, $($arg:tt)*) => ();
}

146
src/main.rs Normal file
View File

@@ -0,0 +1,146 @@
#[macro_use]
extern crate clap;
#[macro_use]
extern crate log;
use anyhow::anyhow;
use chrono::Local;
use clap::{Arg, ArgMatches, Command};
use clap_complete::Shell;
use env_logger::Builder;
use log::LevelFilter;
use mdbook::utils;
use std::env;
use std::ffi::OsStr;
use std::io::Write;
use std::path::PathBuf;
mod cmd;
const VERSION: &str = concat!("v", crate_version!());
fn main() {
init_logger();
let command = create_clap_command();
// Check which subcommand the user ran...
let res = match command.get_matches().subcommand() {
Some(("init", sub_matches)) => cmd::init::execute(sub_matches),
Some(("build", sub_matches)) => cmd::build::execute(sub_matches),
Some(("clean", sub_matches)) => cmd::clean::execute(sub_matches),
#[cfg(feature = "watch")]
Some(("watch", sub_matches)) => cmd::watch::execute(sub_matches),
#[cfg(feature = "serve")]
Some(("serve", sub_matches)) => cmd::serve::execute(sub_matches),
Some(("test", sub_matches)) => cmd::test::execute(sub_matches),
Some(("completions", sub_matches)) => (|| {
let shell = sub_matches
.get_one::<Shell>("shell")
.ok_or_else(|| anyhow!("Shell name missing."))?;
let mut complete_app = create_clap_command();
clap_complete::generate(
*shell,
&mut complete_app,
"mdbook",
&mut std::io::stdout().lock(),
);
Ok(())
})(),
_ => unreachable!(),
};
if let Err(e) = res {
utils::log_backtrace(&e);
std::process::exit(101);
}
}
/// Create a list of valid arguments and sub-commands
fn create_clap_command() -> Command {
let app = Command::new(crate_name!())
.about(crate_description!())
.author("Mathieu David <mathieudavid@mathieudavid.org>")
.version(VERSION)
.propagate_version(true)
.arg_required_else_help(true)
.after_help(
"For more information about a specific command, try `mdbook <command> --help`\n\
The source code for mdBook is available at: https://github.com/rust-lang/mdBook",
)
.subcommand(cmd::init::make_subcommand())
.subcommand(cmd::build::make_subcommand())
.subcommand(cmd::test::make_subcommand())
.subcommand(cmd::clean::make_subcommand())
.subcommand(
Command::new("completions")
.about("Generate shell completions for your shell to stdout")
.arg(
Arg::new("shell")
.value_parser(clap::value_parser!(Shell))
.help("the shell to generate completions for")
.value_name("SHELL")
.required(true),
),
);
#[cfg(feature = "watch")]
let app = app.subcommand(cmd::watch::make_subcommand());
#[cfg(feature = "serve")]
let app = app.subcommand(cmd::serve::make_subcommand());
app
}
fn init_logger() {
let mut builder = Builder::new();
builder.format(|formatter, record| {
writeln!(
formatter,
"{} [{}] ({}): {}",
Local::now().format("%Y-%m-%d %H:%M:%S"),
record.level(),
record.target(),
record.args()
)
});
if let Ok(var) = env::var("RUST_LOG") {
builder.parse_filters(&var);
} else {
// if no RUST_LOG provided, default to logging at the Info level
builder.filter(None, LevelFilter::Info);
// Filter extraneous html5ever not-implemented messages
builder.filter(Some("html5ever"), LevelFilter::Error);
}
builder.init();
}
fn get_book_dir(args: &ArgMatches) -> PathBuf {
if let Some(p) = args.get_one::<PathBuf>("dir") {
// Check if path is relative from current dir, or absolute...
if p.is_relative() {
env::current_dir().unwrap().join(p)
} else {
p.to_path_buf()
}
} else {
env::current_dir().expect("Unable to determine the current directory")
}
}
fn open<P: AsRef<OsStr>>(path: P) {
info!("Opening web browser");
if let Err(e) = opener::open(path) {
error!("Error opening web browser: {}", e);
}
}
#[test]
fn verify_app() {
create_clap_command().debug_assert();
}

View File

@@ -1,3 +0,0 @@
pub use self::summary::construct_bookitems;
pub mod summary;

View File

@@ -1,216 +0,0 @@
use std::path::PathBuf;
use std::fs::File;
use std::io::{Read, Result, Error, ErrorKind};
use book::bookitem::{BookItem, Chapter};
pub fn construct_bookitems(path: &PathBuf) -> Result<Vec<BookItem>> {
debug!("[fn]: construct_bookitems");
let mut summary = String::new();
try!(try!(File::open(path)).read_to_string(&mut summary));
debug!("[*]: Parse SUMMARY.md");
let top_items = try!(parse_level(&mut summary.split('\n').collect(), 0, vec![0]));
debug!("[*]: Done parsing SUMMARY.md");
Ok(top_items)
}
fn parse_level(summary: &mut Vec<&str>, current_level: i32, mut section: Vec<i32>) -> Result<Vec<BookItem>> {
debug!("[fn]: parse_level");
let mut items: Vec<BookItem> = vec![];
// Construct the book recursively
while !summary.is_empty() {
let item: BookItem;
// Indentation level of the line to parse
let level = try!(level(summary[0], 4));
// if level < current_level we remove the last digit of section, exit the current function,
// and return the parsed level to the calling function.
if level < current_level { break }
// if level > current_level we call ourselves to go one level deeper
if level > current_level {
// Level can not be root level !!
// Add a sub-number to section
section.push(0);
let last = items.pop().expect("There should be at least one item since this can't be the root level");
item = if let BookItem::Chapter(ref s, ref ch) = last {
let mut ch = ch.clone();
ch.sub_items = try!(parse_level(summary, level, section.clone()));
items.push(BookItem::Chapter(s.clone(), ch));
// Remove the last number from the section, because we got back to our level..
section.pop();
continue
} else {
return Err(Error::new( ErrorKind::Other, format!(
"Your summary.md is messed up\n\n
Prefix, Suffix and Spacer elements can only exist on the root level.\n
Prefix elements can only exist before any chapter and there can be no chapters after suffix elements."
)))
};
} else {
// level and current_level are the same, parse the line
item = if let Some(parsed_item) = parse_line(summary[0]) {
// Eliminate possible errors and set section to -1 after suffix
match parsed_item {
// error if level != 0 and BookItem is != Chapter
BookItem::Affix(_) | BookItem::Spacer if level > 0 => {
return Err(Error::new( ErrorKind::Other, format!(
"Your summary.md is messed up\n\n
Prefix, Suffix and Spacer elements can only exist on the root level.\n
Prefix elements can only exist before any chapter and there can be no chapters after suffix elements."
)))
},
// error if BookItem == Chapter and section == -1
BookItem::Chapter(_, _) if section[0] == -1 => {
return Err(Error::new( ErrorKind::Other, format!(
"Your summary.md is messed up\n\n
Prefix, Suffix and Spacer elements can only exist on the root level.\n
Prefix elements can only exist before any chapter and there can be no chapters after suffix elements."
)))
},
// Set section = -1 after suffix
BookItem::Affix(_) if section[0] > 0 => {
section[0] = -1;
}
_ => {},
}
match parsed_item {
BookItem::Chapter(_, ch) => {
// Increment section
let len = section.len() -1;
section[len] += 1;
let s = section.iter().fold("".to_owned(), |s, i| s + &i.to_string() + ".");
BookItem::Chapter(s, ch)
}
_ => parsed_item
}
} else {
// If parse_line does not return Some(_) continue...
summary.remove(0);
continue;
};
}
summary.remove(0);
items.push(item)
}
debug!("[*]: Level: {:?}", items);
Ok(items)
}
fn level(line: &str, spaces_in_tab: i32) -> Result<i32> {
debug!("[fn]: level");
let mut spaces = 0;
let mut level = 0;
for ch in line.chars() {
match ch {
' ' => spaces += 1,
'\t' => level += 1,
_ => break,
}
if spaces >= spaces_in_tab {
level += 1;
spaces = 0;
}
}
// If there are spaces left, there is an indentation error
if spaces > 0 {
debug!("[SUMMARY.md]:");
debug!("\t[line]: {}", line);
debug!("[*]: There is an indentation error on this line. Indentation should be {} spaces", spaces_in_tab);
return Err(Error::new(
ErrorKind::Other,
format!("Indentation error on line:\n\n{}", line)
)
)
}
Ok(level)
}
fn parse_line(l: &str) -> Option<BookItem> {
debug!("[fn]: parse_line");
// Remove leading and trailing spaces or tabs
let line = l.trim_matches(|c: char| { c == ' ' || c == '\t' });
// Spacers are "------"
if line.starts_with("--") {
debug!("[*]: Line is spacer");
return Some(BookItem::Spacer)
}
if let Some(c) = line.chars().nth(0) {
match c {
// List item
'-' | '*' => {
debug!("[*]: Line is list element");
if let Some((name, path)) = read_link(line) {
return Some(BookItem::Chapter("0".to_owned(), Chapter::new(name, path)))
} else { return None }
},
// Non-list element
'[' => {
debug!("[*]: Line is a link element");
if let Some((name, path)) = read_link(line) {
return Some(BookItem::Affix(Chapter::new(name, path)))
} else { return None }
}
_ => {}
}
}
None
}
fn read_link(line: &str) -> Option<(String, PathBuf)> {
let mut start_delimitor;
let mut end_delimitor;
// In the future, support for list item that is not a link
// Not sure if I should error on line I can't parse or just ignore them...
if let Some(i) = line.find('[') { start_delimitor = i; }
else {
debug!("[*]: '[' not found, this line is not a link. Ignoring...");
return None
}
if let Some(i) = line[start_delimitor..].find("](") {
end_delimitor = start_delimitor +i;
}
else {
debug!("[*]: '](' not found, this line is not a link. Ignoring...");
return None
}
let name = line[start_delimitor + 1 .. end_delimitor].to_owned();
start_delimitor = end_delimitor + 1;
if let Some(i) = line[start_delimitor..].find(')') {
end_delimitor = start_delimitor + i;
}
else {
debug!("[*]: ')' not found, this line is not a link. Ignoring...");
return None
}
let path = PathBuf::from(line[start_delimitor + 1 .. end_delimitor].to_owned());
Some((name, path))
}

208
src/preprocess/cmd.rs Normal file
View File

@@ -0,0 +1,208 @@
use super::{Preprocessor, PreprocessorContext};
use crate::book::Book;
use crate::errors::*;
use log::{debug, trace, warn};
use shlex::Shlex;
use std::io::{self, Read, Write};
use std::process::{Child, Command, Stdio};
/// A custom preprocessor which will shell out to a 3rd-party program.
///
/// # Preprocessing Protocol
///
/// When the `supports_renderer()` method is executed, `CmdPreprocessor` will
/// execute the shell command `$cmd supports $renderer`. If the renderer is
/// supported, custom preprocessors should exit with a exit code of `0`,
/// any other exit code be considered as unsupported.
///
/// The `run()` method is implemented by passing a `(PreprocessorContext, Book)`
/// tuple to the spawned command (`$cmd`) as JSON via `stdin`. Preprocessors
/// should then "return" a processed book by printing it to `stdout` as JSON.
/// For convenience, the `CmdPreprocessor::parse_input()` function can be used
/// to parse the input provided by `mdbook`.
///
/// Exiting with a non-zero exit code while preprocessing is considered an
/// error. `stderr` is passed directly through to the user, so it can be used
/// for logging or emitting warnings if desired.
///
/// # Examples
///
/// An example preprocessor is available in this project's `examples/`
/// directory.
#[derive(Debug, Clone, PartialEq)]
pub struct CmdPreprocessor {
name: String,
cmd: String,
}
impl CmdPreprocessor {
/// Create a new `CmdPreprocessor`.
pub fn new(name: String, cmd: String) -> CmdPreprocessor {
CmdPreprocessor { name, cmd }
}
/// A convenience function custom preprocessors can use to parse the input
/// written to `stdin` by a `CmdRenderer`.
pub fn parse_input<R: Read>(reader: R) -> Result<(PreprocessorContext, Book)> {
serde_json::from_reader(reader).with_context(|| "Unable to parse the input")
}
fn write_input_to_child(&self, child: &mut Child, book: &Book, ctx: &PreprocessorContext) {
let stdin = child.stdin.take().expect("Child has stdin");
if let Err(e) = self.write_input(stdin, book, ctx) {
// Looks like the backend hung up before we could finish
// sending it the render context. Log the error and keep going
warn!("Error writing the RenderContext to the backend, {}", e);
}
}
fn write_input<W: Write>(
&self,
writer: W,
book: &Book,
ctx: &PreprocessorContext,
) -> Result<()> {
serde_json::to_writer(writer, &(ctx, book)).map_err(Into::into)
}
/// The command this `Preprocessor` will invoke.
pub fn cmd(&self) -> &str {
&self.cmd
}
fn command(&self) -> Result<Command> {
let mut words = Shlex::new(&self.cmd);
let executable = match words.next() {
Some(e) => e,
None => bail!("Command string was empty"),
};
let mut cmd = Command::new(executable);
for arg in words {
cmd.arg(arg);
}
Ok(cmd)
}
}
impl Preprocessor for CmdPreprocessor {
fn name(&self) -> &str {
&self.name
}
fn run(&self, ctx: &PreprocessorContext, book: Book) -> Result<Book> {
let mut cmd = self.command()?;
let mut child = cmd
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::inherit())
.spawn()
.with_context(|| {
format!(
"Unable to start the \"{}\" preprocessor. Is it installed?",
self.name()
)
})?;
self.write_input_to_child(&mut child, &book, ctx);
let output = child.wait_with_output().with_context(|| {
format!(
"Error waiting for the \"{}\" preprocessor to complete",
self.name
)
})?;
trace!("{} exited with output: {:?}", self.cmd, output);
ensure!(
output.status.success(),
format!(
"The \"{}\" preprocessor exited unsuccessfully with {} status",
self.name, output.status
)
);
serde_json::from_slice(&output.stdout).with_context(|| {
format!(
"Unable to parse the preprocessed book from \"{}\" processor",
self.name
)
})
}
fn supports_renderer(&self, renderer: &str) -> bool {
debug!(
"Checking if the \"{}\" preprocessor supports \"{}\"",
self.name(),
renderer
);
let mut cmd = match self.command() {
Ok(c) => c,
Err(e) => {
warn!(
"Unable to create the command for the \"{}\" preprocessor, {}",
self.name(),
e
);
return false;
}
};
let outcome = cmd
.arg("supports")
.arg(renderer)
.stdin(Stdio::null())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.status()
.map(|status| status.code() == Some(0));
if let Err(ref e) = outcome {
if e.kind() == io::ErrorKind::NotFound {
warn!(
"The command wasn't found, is the \"{}\" preprocessor installed?",
self.name
);
warn!("\tCommand: {}", self.cmd);
}
}
outcome.unwrap_or(false)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::MDBook;
use std::path::Path;
fn guide() -> MDBook {
let example = Path::new(env!("CARGO_MANIFEST_DIR")).join("guide");
MDBook::load(example).unwrap()
}
#[test]
fn round_trip_write_and_parse_input() {
let cmd = CmdPreprocessor::new("test".to_string(), "test".to_string());
let md = guide();
let ctx = PreprocessorContext::new(
md.root.clone(),
md.config.clone(),
"some-renderer".to_string(),
);
let mut buffer = Vec::new();
cmd.write_input(&mut buffer, &md.book, &ctx).unwrap();
let (got_ctx, got_book) = CmdPreprocessor::parse_input(buffer.as_slice()).unwrap();
assert_eq!(got_book, md.book);
assert_eq!(got_ctx, ctx);
}
}

105
src/preprocess/index.rs Normal file
View File

@@ -0,0 +1,105 @@
use regex::Regex;
use std::path::Path;
use super::{Preprocessor, PreprocessorContext};
use crate::book::{Book, BookItem};
use crate::errors::*;
use log::warn;
use once_cell::sync::Lazy;
/// A preprocessor for converting file name `README.md` to `index.md` since
/// `README.md` is the de facto index file in markdown-based documentation.
#[derive(Default)]
pub struct IndexPreprocessor;
impl IndexPreprocessor {
pub(crate) const NAME: &'static str = "index";
/// Create a new `IndexPreprocessor`.
pub fn new() -> Self {
IndexPreprocessor
}
}
impl Preprocessor for IndexPreprocessor {
fn name(&self) -> &str {
Self::NAME
}
fn run(&self, ctx: &PreprocessorContext, mut book: Book) -> Result<Book> {
let source_dir = ctx.root.join(&ctx.config.book.src);
book.for_each_mut(|section: &mut BookItem| {
if let BookItem::Chapter(ref mut ch) = *section {
if let Some(ref mut path) = ch.path {
if is_readme_file(&path) {
let mut index_md = source_dir.join(path.with_file_name("index.md"));
if index_md.exists() {
warn_readme_name_conflict(&path, &&mut index_md);
}
path.set_file_name("index.md");
}
}
}
});
Ok(book)
}
}
fn warn_readme_name_conflict<P: AsRef<Path>>(readme_path: P, index_path: P) {
let file_name = readme_path.as_ref().file_name().unwrap_or_default();
let parent_dir = index_path
.as_ref()
.parent()
.unwrap_or_else(|| index_path.as_ref());
warn!(
"It seems that there are both {:?} and index.md under \"{}\".",
file_name,
parent_dir.display()
);
warn!(
"mdbook converts {:?} into index.html by default. It may cause",
file_name
);
warn!("unexpected behavior if putting both files under the same directory.");
warn!("To solve the warning, try to rearrange the book structure or disable");
warn!("\"index\" preprocessor to stop the conversion.");
}
fn is_readme_file<P: AsRef<Path>>(path: P) -> bool {
static RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)^readme$").unwrap());
RE.is_match(
path.as_ref()
.file_stem()
.and_then(std::ffi::OsStr::to_str)
.unwrap_or_default(),
)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn file_stem_exactly_matches_readme_case_insensitively() {
let path = "path/to/Readme.md";
assert!(is_readme_file(path));
let path = "path/to/README.md";
assert!(is_readme_file(path));
let path = "path/to/rEaDmE.md";
assert!(is_readme_file(path));
let path = "path/to/README.markdown";
assert!(is_readme_file(path));
let path = "path/to/README";
assert!(is_readme_file(path));
let path = "path/to/README-README.md";
assert!(!is_readme_file(path));
}
}

Some files were not shown because too many files have changed in this diff Show More