Compare commits

..

105 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
74 changed files with 3208 additions and 1500 deletions

8
.gitattributes vendored
View File

@@ -2,7 +2,7 @@
* text=auto eol=lf
*.rs rust
*.woff -text
*.ttf -text
*.otf -text
*.png -text
*.woff binary
*.ttf binary
*.otf binary
*.png binary

View File

@@ -1,42 +1,76 @@
language: rust
rust:
- stable
- beta
- nightly
os:
- linux
- osx
cache:
timeout: 360
cargo: true
cache:
directories:
- "$HOME/.cargo"
- "$HOME/.cache/sccache"
before_cache:
- chmod -R a+r $HOME/.cargo
- rm -rf "$HOME/.cargo/registry"
env:
global:
- CRATE_NAME=mdbook
matrix:
include:
- rust: stable
env: TARGET=x86_64-unknown-linux-gnu
- rust: beta
env: TARGET=x86_64-unknown-linux-gnu
- rust: nightly
env: TARGET=x86_64-unknown-linux-gnu
- rust: stable
os: osx
env: TARGET=x86_64-apple-darwin
before_install:
- export SCCACHE_VER=0.2.8 RUSTC_WRAPPER=sccache
- case "$TRAVIS_OS_NAME" in
linux )
cd /tmp
&& travis_retry curl -sSL "https://github.com/mozilla/sccache/releases/download/${SCCACHE_VER}/sccache-${SCCACHE_VER}-x86_64-unknown-linux-musl.tar.gz" | tar xzf -
&& sudo mv "sccache-${SCCACHE_VER}-x86_64-unknown-linux-musl/sccache" /usr/local/bin/sccache;
;;
osx )
cd "${TMPDIR}"
&& travis_retry curl -sSL "https://github.com/mozilla/sccache/releases/download/${SCCACHE_VER}/sccache-${SCCACHE_VER}-x86_64-apple-darwin.tar.gz" | tar xzf -
&& sudo mv "sccache-${SCCACHE_VER}-x86_64-apple-darwin/sccache" /usr/local/bin/sccache;
;;
* ) unset RUSTC_WRAPPER;;
esac
- cd "$TRAVIS_BUILD_DIR"
script:
- cargo test --all
- cargo test --all --no-default-features
- if [ "$TARGET" = x86_64-unknown-linux-gnu ] && [ "$TRAVIS_RUST_VERSION" = stable ]; then
rustup component add rustfmt;
rustfmt -vV;
cargo fmt --all -- --check;
fi
before_deploy:
- cargo run -- build book-example
- sh ci/before_deploy.sh
deploy:
provider: releases
api_key:
- secure: cURRWBr034iqBz/ifD7uOunBfNR30YxIXfgLX0osWz+iafkVbhDGYYz9sBmRraqO2P7L2koEXMADVb/md1kI2+ykiq/ml+l9zuEAZPVmvSGUN7ZD+7s+lu3l5OBPG5z175T+b2q2q2m8XVR7TW20ra4QbE0bq06KAoOyjSgQVBTSCYsL9uTsGwiVRMEqqJT/BmKhKJNkpGsTKyBSKkOXvfeAAbE260vXUDEN9TYdJ3fvteRrpwLX56ee64gIZUq0RjDc4SKIEqilM6iUtNMvurqaewYNGkiXKRruV6BPCHxEHo6NNT46kOJLBJTf7gZw//dWhSoWpg9P0gdAnPWm407kSa3F7aJ1eRShAFQ4BLyfz9efTqm+jP3fOp7Mm7igSh9w6caSRuOnSsUf5+raRQ8E5Y9HsWGzzpZQk24Fx9EGZ04EeDSdpZAFz+jcbMpHf8t2p4CEx0CCNwYvKx6EydMKbMF5QteQ8SQkXNLhv7Rz2OgtXWYZPRVCMfQfOplsi2InsLCrQxTgwh+6u654SqVSgaHG+IncEAxBrdWy4rHcg7qereUcKfcY3k96vaDxdn/T2c00Ig0aNFR91YnixGMd6J6tQgDcRK9jh6fUm1CCBE9hT+pNUmtgYKuWBoLZexUZFFnfuBed0WciBot1bGDDamndqKq0jJiAzg+GMHk=
- provider: releases
api_key: "$GITHUB_TOKEN"
file_glob: true
file: "$CRATE_NAME-$TRAVIS_TAG-$TARGET.*"
on:
condition: "$TRAVIS_RUST_VERSION = stable"
tags: true
skip_cleanup: true
- provider: pages
local_dir: book-example/book
skip_cleanup: true
github_token: "$GITHUB_TOKEN"
keep_history: true
on:
condition: $TRAVIS_OS_NAME = "linux" && $TRAVIS_RUST_VERSION = "stable"
tags: true
branches:
only:

190
CHANGELOG.md Normal file
View File

@@ -0,0 +1,190 @@
# Changelog
## mdBook 0.3.0
[6cbc41d...84d4063](https://github.com/rust-lang-nursery/mdBook/compare/6cbc41d...84d4063)
### Added
- Added ability to resize the sidebar.
[#849](https://github.com/rust-lang-nursery/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-nursery/mdBook/pull/883)
- Set `noindex` on `print.html` page to prevent robots from indexing it.
[#844](https://github.com/rust-lang-nursery/mdBook/pull/844)
- Added support for ~~strikethrough~~ and GitHub-style tasklists.
[#952](https://github.com/rust-lang-nursery/mdBook/pull/952)
### Changed
- Command-line help output is now colored.
[#861](https://github.com/rust-lang-nursery/mdBook/pull/861)
- The build directory is now deleted before rendering starts, instead of after
if finishes.
[#878](https://github.com/rust-lang-nursery/mdBook/pull/878)
- Removed dependency on `same-file` crate.
[#903](https://github.com/rust-lang-nursery/mdBook/pull/903)
- 💥 Renamed `with_preprecessor` to `with_preprocessor`.
[#906](https://github.com/rust-lang-nursery/mdBook/pull/906)
- Updated ACE editor to 1.4.4, should remove a JavaScript console warning.
[#935](https://github.com/rust-lang-nursery/mdBook/pull/935)
- Dependencies have been updated.
[#934](https://github.com/rust-lang-nursery/mdBook/pull/934)
[#945](https://github.com/rust-lang-nursery/mdBook/pull/945)
- Highlight.js has been updated. This fixes some TOML highlighting, and adds
Julia support.
[#942](https://github.com/rust-lang-nursery/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-nursery/mdBook/pull/898)
- The `diff` language should now highlight correctly.
[#943](https://github.com/rust-lang-nursery/mdBook/pull/943)
- Make the blank region of a header not clickable.
[#948](https://github.com/rust-lang-nursery/mdBook/pull/948)
- Rustdoc tests now use the preprocessed content instead of the raw,
unpreprocessed content.
[#891](https://github.com/rust-lang-nursery/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-nursery/mdBook/pull/870)
- Fixed on-hover color highlighting for links in sidebar.
[#834](https://github.com/rust-lang-nursery/mdBook/pull/834)
- Fixed loss of focus when clicking the "Copy" button in code blocks.
[#867](https://github.com/rust-lang-nursery/mdBook/pull/867)
- Fixed incorrectly stripping the path for `additional-js` files.
[#796](https://github.com/rust-lang-nursery/mdBook/pull/796)
- Fixed color of `code spans` that are links.
[#905](https://github.com/rust-lang-nursery/mdBook/pull/905)
- Fixed "next" navigation on index.html.
[#916](https://github.com/rust-lang-nursery/mdBook/pull/916)
- Fixed keyboard chapter navigation for `file` urls.
[#915](https://github.com/rust-lang-nursery/mdBook/pull/915)
- Fixed bad wrapping for inline code on some browsers.
[#818](https://github.com/rust-lang-nursery/mdBook/pull/818)
- Properly load an existing `SUMMARY.md` in `mdbook init`.
[#841](https://github.com/rust-lang-nursery/mdBook/pull/841)
- Fixed some broken links in `print.html`.
[#871](https://github.com/rust-lang-nursery/mdBook/pull/871)
- The Rust Playground link now supports the 2018 edition.
[#946](https://github.com/rust-lang-nursery/mdBook/pull/946)
## mdBook 0.2.3 (2018-01-18)
[2c20c99...6cbc41d](https://github.com/rust-lang-nursery/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-nursery/mdBook/pull/802)
- Added a `default-theme` option to the `[output.html]` section.
[#804](https://github.com/rust-lang-nursery/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-nursery/mdBook/pull/788)
### Fixed
- Fix websocket hostname usage
[#865](https://github.com/rust-lang-nursery/mdBook/pull/865)
- Fixing links in print.html
[#866](https://github.com/rust-lang-nursery/mdBook/pull/866)
## mdBook 0.2.2 (2018-10-19)
[7e2e095...2c20c99](https://github.com/rust-lang-nursery/mdBook/compare/7e2e095...2c20c99)
### Added
- 🎉 Process-based custom preprocessors. See [the
docs](https://rust-lang-nursery.github.io/mdBook/for_developers/preprocessors.html)
for more.
[#792](https://github.com/rust-lang-nursery/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-nursery/mdBook/pull/658)
[#787](https://github.com/rust-lang-nursery/mdBook/pull/787)
### Fixed
- Fix paths to additional CSS and JavaScript files
[#777](https://github.com/rust-lang-nursery/mdBook/pull/777)
- Ensure section numbers are correctly incremented after a horizontal
separator
[#790](https://github.com/rust-lang-nursery/mdBook/pull/790)
## mdBook 0.2.1 (2018-08-22)
[91ffca1...7e2e095](https://github.com/rust-lang-nursery/mdBook/compare/91ffca1...7e2e095)
### Changed
- Update to handlebars-rs 1.0
[#761](https://github.com/rust-lang-nursery/mdBook/pull/761)
### Fixed
- Fix table colors, broken by Stylus -> CSS transition
[#765](https://github.com/rust-lang-nursery/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-nursery/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-nursery/mdBook/pull/754)
### Fixed
- Escaped includes (`\{{#include file.rs}}`) will now render correctly.
[f30ce01](https://github.com/rust-lang-nursery/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-nursery/mdBook/pull/756)

1318
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,39 +1,40 @@
[package]
name = "mdbook"
version = "0.2.3"
version = "0.3.0"
authors = [
"Mathieu David <mathieudavid@mathieudavid.org>",
"Mathieu David <mathieudavid@mathieudavid.org>",
"Michael-F-Bryan <michaelfbryan@gmail.com>",
"Matt Ickstadt <mattico8@gmail.com>"
]
description = "Create books from markdown files"
documentation = "http://rust-lang-nursery.github.io/mdBook/index.html"
repository = "https://github.com/rust-lang-nursery/mdBook"
edition = "2018"
exclude = ["/book-example/*"]
keywords = ["book", "gitbook", "rustbook", "markdown"]
license = "MPL-2.0"
readme = "README.md"
exclude = ["book-example/*"]
repository = "https://github.com/rust-lang-nursery/mdBook"
description = "Creates a book from markdown files"
[dependencies]
clap = "2.24"
chrono = "0.4"
handlebars = "1.0"
serde = "1.0"
serde_derive = "1.0"
clap = "2.24"
env_logger = "0.6"
error-chain = "0.12"
serde_json = "1.0"
pulldown-cmark = "0.1.2"
handlebars = { version = "1.0", default-features = false, features = ["no_dir_source"] }
itertools = "0.8"
lazy_static = "1.0"
log = "0.4"
env_logger = "0.5"
toml = "0.4.8"
memchr = "2.0"
open = "1.1"
pulldown-cmark = "0.5"
regex = "1.0.0"
tempfile = "3.0"
itertools = "0.7"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
shlex = "0.1"
toml-query = "0.7"
tempfile = "3.0"
toml = "0.5.1"
toml-query = "0.9"
# Watch feature
notify = { version = "4.0", optional = true }
@@ -41,17 +42,16 @@ notify = { version = "4.0", optional = true }
# Serve feature
iron = { version = "0.6", optional = true }
staticfile = { version = "0.5", optional = true }
ws = { version = "0.7", optional = true}
ws = { version = "0.8", optional = true}
# Search feature
elasticlunr-rs = { version = "2.3", optional = true, default-features = false }
ammonia = { version = "1.1", optional = true }
ammonia = { version = "2.1", optional = true }
[dev-dependencies]
select = "0.4"
pretty_assertions = "0.5"
pretty_assertions = "0.6"
walkdir = "2.0"
pulldown-cmark-to-cmark = "1.1.0"
[features]
default = ["output", "watch", "serve", "search"]

View File

@@ -4,7 +4,7 @@
<tr>
<td><strong>Linux / OS X</strong></td>
<td>
<a href="https://travis-ci.org/rust-lang-nursery/mdBook"><img src="https://travis-ci.org/rust-lang-nursery/mdBook.svg?branch=master"></a>
<a href="https://travis-ci.com/rust-lang-nursery/mdBook"><img src="https://travis-ci.com/rust-lang-nursery/mdBook.svg?branch=master"></a>
</td>
</tr>
<tr>
@@ -57,7 +57,7 @@ There are multiple ways to install mdBook.
another CI server, we recommend that you specify a semver version range for
mdBook when you install it through your script!
This will constrain the server to install the latests **non-breaking**
This will constrain the server to install the latest **non-breaking**
version of mdBook and will prevent your books from failing to build because
we released a new version. For example:
@@ -65,7 +65,7 @@ There are multiple ways to install mdBook.
cargo install mdbook --vers "^0.1.0"
```
3. **From Git**
3. **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
@@ -77,7 +77,7 @@ There are multiple ways to install mdBook.
Again, make sure to add the Cargo bin directory to your `PATH`.
4. **For Contributions**
4. **For Contributions**
If you want to contribute to mdBook you will have to clone the repository on
your local machine:
@@ -152,9 +152,9 @@ party plugins. These plugins are just programs which will be invoked during the
build process and are split into roughly two categories, *preprocessors* and
*renderers*.
Preprocessors are used to transform a book before it is sent to a renderer.
One example would be to replace all occurrences of
`{{#include some_file.ext}}` with the contents of that file. Some existing
Preprocessors are used to transform a book before it is sent to a renderer.
One example would be to replace all occurrences of
`{{#include some_file.ext}}` with the contents of that file. Some existing
preprocessors are:
- `index` - a built-in preprocessor (enabled by default) which will transform

View File

@@ -7,14 +7,7 @@ environment:
RUST_CHANNEL: stable
- TARGET: x86_64-pc-windows-msvc
RUST_CHANNEL: stable
# Beta channel
- TARGET: i686-pc-windows-msvc
RUST_CHANNEL: beta
- TARGET: x86_64-pc-windows-msvc
RUST_CHANNEL: beta
# Nightly channel
- TARGET: i686-pc-windows-msvc
RUST_CHANNEL: nightly
- TARGET: x86_64-pc-windows-msvc
RUST_CHANNEL: nightly
@@ -51,8 +44,7 @@ before_deploy:
deploy:
description: 'Windows release'
artifact: /.*\.zip/
auth_token:
secure: QQhjKVyz7mpjlyGhlXytbFQQfKFQWTahHkD+B0NzIUoEVqO7ZLWjnoWasvLqW4nE
auth_token: $(GITHUB_TOKEN)
provider: GitHub
on:
RUST_CHANNEL: stable

View File

@@ -20,7 +20,7 @@
- [Continuous Integration](continuous-integration.md)
- [For Developers](for_developers/README.md)
- [Preprocessors](for_developers/preprocessors.md)
- [Alternate Backends](for_developers/backends.md)
- [Alternative Backends](for_developers/backends.md)
-----------

View File

@@ -37,7 +37,7 @@ configured.
#### --open
When you use the `--open` (`-o`) flag, mdbook will open the book in your your
When you use the `--open` (`-o`) flag, mdbook will open the book in your
default web browser after starting the server.
#### --dest-dir

View File

@@ -22,7 +22,7 @@ rust:
before_script:
- (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update)
- (test -x $HOME/.cargo/bin/mdbook || cargo install --vers "^0.1" mdbook)
- (test -x $HOME/.cargo/bin/mdbook || cargo install --vers "^0.3" mdbook)
- cargo install-update -a
script:
@@ -54,3 +54,36 @@ deploy:
```
That's it!
### Deploying to GitHub Pages manually
If your CI doesn't support GitHub pages, or you're deploying somewhere else
with integrations such as Github Pages:
*note: you may want to use different tmp dirs*:
```console
$> git worktree add /tmp/book gh-pages
$> mdbook build
$> rm -rf /tmp/book/* # this won't delete the .git directory
$> cp -rp book/* /tmp/book/
$> cd /tmp/book
$> git add -A
$> git commit 'new book message'
$> git push origin gh-pages
$> cd -
```
Or put this into a Makefile rule:
```makefile
.PHONY: deploy
deploy: book
@echo "====> deploying to github"
git worktree add /tmp/book gh-pages
rm -rf /tmp/book/*
cp -rp book/* /tmp/book/
cd /tmp/book && \
git add -A && \
git commit -m "deployed on $(shell date) by ${USER}" && \
git push origin gh-pages
```

View File

@@ -12,7 +12,7 @@ The *For Developers* chapters are here to show you the more advanced usage of
The two main ways a developer can hook into the book's build process is via,
- [Preprocessors](preprocessors.md)
- [Alternate Backends](backends.md)
- [Alternative Backends](backends.md)
## The Build Process

View File

@@ -1,11 +1,11 @@
# Alternate Backends
# 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.
There are already several alternate backends on GitHub which can be used as a
There are already several alternative backends on GitHub which can be used as a
rough example of how this is accomplished in practice.
- [mdbook-linkcheck] - a simple program for verifying the book doesn't contain
@@ -14,7 +14,7 @@ rough example of how this is accomplished in practice.
- [mdbook-test] - a program to run the book's contents through [rust-skeptic] to
verify everything compiles and runs correctly (similar to `rustdoc --test`)
This page will step you through creating your own alternate backend in the form
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.
@@ -24,9 +24,9 @@ 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
$ cd mdbook-wordcount
$ cargo add mdbook
```
@@ -52,8 +52,8 @@ fn main() {
> **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`.
`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.
@@ -92,12 +92,12 @@ fn count_words(ch: &Chapter) -> usize {
Now we've got the basics running, we want to actually use it. First, install the
program.
```
```shell
$ cargo install
```
Then `cd` to the particular book you'd like to count the words of and update its
`book.toml` file.
`book.toml` file.
```diff
[book]
@@ -112,7 +112,7 @@ Then `cd` to the particular book you'd like to count the words of and update its
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.
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.
@@ -120,7 +120,7 @@ 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
@@ -140,7 +140,7 @@ Syntax highlighting: 314
MathJax Support: 153
Rust code specific features: 148
For Developers: 788
Alternate Backends: 710
Alternative Backends: 710
Contributors: 85
```
@@ -169,7 +169,7 @@ arguments or be an interpreted script), you can use the `command` field.
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.
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
@@ -211,13 +211,13 @@ and then add a check to make sure we skip ignored chapters.
+ 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);
}
@@ -239,17 +239,17 @@ in [`RenderContext`].
- 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();
@@ -276,11 +276,11 @@ like this:
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();
@@ -303,7 +303,7 @@ like this:
Now, if we reinstall the backend and build a book,
```
```shell
$ cargo install --force
$ mdbook build /path/to/book
...
@@ -329,7 +329,7 @@ the usual `RUST_LOG` to control logging verbosity.
## Wrapping Up
Although contrived, hopefully this example was enough to show how you'd create
an alternate backend for `mdbook`. If you feel it's missing something, don't
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.

View File

@@ -109,7 +109,7 @@ For everything else, have a look [at the complete example][example].
[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-nursery/mdBook/blob/master/examples/de-emphasize.rs
[example]: https://github.com/rust-lang-nursery/mdBook/blob/master/examples/nop-preprocessor.rs
[an example no-op preprocessor]: https://github.com/rust-lang-nursery/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

View File

@@ -14,9 +14,9 @@ description = "The example book covers examples."
build-dir = "my-example-book"
create-missing = false
[preprocess.index]
[preprocessor.index]
[preprocess.links]
[preprocessor.links]
[output.html]
additional-css = ["custom.css"]
@@ -68,11 +68,11 @@ This controls the build process of your book.
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
- 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
- Adding `[preprocessor.links]`, for example, will ensure, regardless of
`use-default-preprocessors` that `links` it will run.
## Configuring Preprocessors
@@ -92,9 +92,9 @@ The following preprocessors are available and included by default:
build-dir = "build"
create-missing = false
[preprocess.links]
[preprocessor.links]
[preprocess.index]
[preprocessor.index]
```
### Custom Preprocessor Configuration
@@ -105,8 +105,8 @@ configuration to the preprocessor by adding key-value pairs to the table.
For example
```
[preprocess.links]
```toml
[preprocessor.links]
# set the renderers this preprocessor will run for
renderers = ["html"]
some_extra_feature = true
@@ -117,7 +117,7 @@ some_extra_feature = true
You can explicitly specify that a preprocessor should run for a renderer by
binding the two together.
```
```toml
[preprocessor.mathjax]
renderers = ["html"] # mathjax only makes sense with the HTML renderer
```
@@ -125,7 +125,7 @@ renderers = ["html"] # mathjax only makes sense 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` executa`ble. If you want to use a
`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.
@@ -146,10 +146,12 @@ 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
- **default-theme:** The theme color scheme to select by default in the
'Change Theme' dropdown. Defaults to `light`.
- **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`.
- **google-analytics:** If you use Google Analytics, this option lets you enable
it by simply specifying your ID in the configuration file.
- **additional-css:** If you need to slightly change the appearance of your book
@@ -165,9 +167,9 @@ The following configuration options are available:
- **playpen:** A subtable for configuring various playpen settings.
- **search:** A subtable for configuring the in-browser search functionality.
mdBook must be compiled with the `search` feature enabled (on by default).
- **git_repository_url:** A url to the git repository for the book. If provided
- **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
- **git-repository-icon:** The FontAwesome icon class to use for the git
repository link. Defaults to `fa-github`.
Available configuration options for the `[output.html.playpen]` table:
@@ -209,25 +211,24 @@ title = "Example book"
authors = ["John Doe", "Jane Doe"]
description = "The example book covers examples."
[build]
build-dir = "book"
create-missing = true
preprocess = ["links", "index"]
[output.html]
theme = "my-theme"
default-theme = "light"
curly-quotes = true
mathjax-support = false
google-analytics = "123456"
additional-css = ["custom.css", "custom2.css"]
additional-js = ["custom.js"]
no-section-label = false
git-repository-url = "https://github.com/rust-lang-nursery/mdBook"
git-repository-icon = "fa-github"
[output.html.playpen]
editor = "./path/to/editor"
editable = false
copy-js = true
[output.html.search]
enable = true
searcher = "./path/to/searcher"
limit-results = 30
teaser-word-count = 30
use-boolean-and = true
@@ -241,13 +242,13 @@ copy-js = true
### Custom Renderers
A custom renderer can be enabled by adding a `[output.foo]` table to your
`book.toml`. Similar to [preprocessors](#configuring-preprocessors) this will
instruct `mdbook` to pass a representation of the book to `mdbook-foo` for
A custom renderer can be enabled by adding a `[output.foo]` table to your
`book.toml`. Similar to [preprocessors](#configuring-preprocessors) this will
instruct `mdbook` to pass a representation of the book to `mdbook-foo` for
rendering.
Custom renderers will have access to all configuration within their table
(i.e. anything under `[output.foo]`), and the command to be invoked can be
(i.e. anything under `[output.foo]`), and the command to be invoked can be
manually specified with the `command` field.
## Environment Variables
@@ -280,11 +281,11 @@ book's title without needing to touch your `book.toml`.
> This means, if you so desired, you could override all book metadata when
> building the book with something like
>
> ```text
> ```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.
building.

View File

@@ -35,10 +35,20 @@ With the following syntax, you can include files into your book:
The path to the file has to be relative from the current source file.
Usually, this command is used for including code snippets and examples. In this
case, oftens one would include a specific part of the file e.g. which only
contains the relevant lines for the example. We support four different modes of
partial includes:
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
interpretting 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}}

View File

@@ -45,51 +45,55 @@ at your disposal.
### 1. toc
The toc helper is used like this
The toc helper is used like this
```handlebars
{{#toc}}{{/toc}}
```
```handlebars
{{#toc}}{{/toc}}
```
and outputs something that looks like this, depending on the structure of your book
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>
```
```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.
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>
```
```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.
The previous and next helpers expose a `link` and `name` property to the
previous and next chapters.
They are used like this
They are used like this
```handlebars
{{#previous}}
<a href="{{link}}" class="nav-chapters previous">
<i class="fa fa-angle-left"></i>
</a>
{{/previous}}
```
```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.
The inner html will only be rendered if the previous / next chapter exists.
Of course the inner html can be changed to your liking.
------

View File

@@ -1,80 +0,0 @@
//! An example preprocessor for removing all forms of emphasis from a markdown
//! book.
extern crate mdbook;
extern crate pulldown_cmark;
extern crate pulldown_cmark_to_cmark;
use mdbook::book::{Book, BookItem, Chapter};
use mdbook::errors::{Error, Result};
use mdbook::preprocess::{Preprocessor, PreprocessorContext};
use pulldown_cmark::{Event, Parser, Tag};
use pulldown_cmark_to_cmark::fmt::cmark;
const NAME: &str = "md-links-to-html-links";
fn main() {
panic!("This example is intended to be part of a library");
}
#[allow(dead_code)]
struct Deemphasize;
impl Preprocessor for Deemphasize {
fn name(&self) -> &str {
NAME
}
fn run(&self, _ctx: &PreprocessorContext, mut book: Book) -> Result<Book> {
eprintln!("Running '{}' preprocessor", self.name());
let mut num_removed_items = 0;
process(&mut book.sections, &mut num_removed_items)?;
eprintln!(
"{}: removed {} events from markdown stream.",
self.name(),
num_removed_items
);
Ok(book)
}
}
fn process<'a, I>(items: I, num_removed_items: &mut usize) -> Result<()>
where
I: IntoIterator<Item = &'a mut BookItem> + 'a,
{
for item in items {
if let BookItem::Chapter(ref mut chapter) = *item {
eprintln!("{}: processing chapter '{}'", NAME, chapter.name);
let md = remove_emphasis(num_removed_items, chapter)?;
chapter.content = md;
}
}
Ok(())
}
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)))
}

View File

@@ -1,12 +1,8 @@
extern crate clap;
extern crate mdbook;
extern crate serde_json;
use crate::nop_lib::Nop;
use clap::{App, Arg, ArgMatches, SubCommand};
use mdbook::book::Book;
use mdbook::errors::Error;
use mdbook::preprocess::{CmdPreprocessor, Preprocessor, PreprocessorContext};
use nop_lib::Nop;
use std::io;
use std::process;
@@ -28,11 +24,9 @@ fn main() {
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);
}
} else if let Err(e) = handle_preprocessing(&preprocessor) {
eprintln!("{}", e);
process::exit(1);
}
}

View File

@@ -5,8 +5,8 @@ use std::io::{Read, Write};
use std::path::{Path, PathBuf};
use super::summary::{parse_summary, Link, SectionNumber, Summary, SummaryItem};
use config::BuildConfig;
use errors::*;
use crate::config::BuildConfig;
use crate::errors::*;
/// Load a book into memory from its `src/` directory.
pub fn load_book<P: AsRef<Path>>(src_dir: P, cfg: &BuildConfig) -> Result<Book> {
@@ -82,7 +82,7 @@ impl Book {
}
/// Get a depth-first iterator over the items in the book.
pub fn iter(&self) -> BookItems {
pub fn iter(&self) -> BookItems<'_> {
BookItems {
items: self.sections.iter().collect(),
}
@@ -116,7 +116,7 @@ where
I: IntoIterator<Item = &'a mut BookItem>,
{
for item in items {
if let &mut BookItem::Chapter(ref mut ch) = item {
if let BookItem::Chapter(ch) = item {
for_each_mut(func, &mut ch.sub_items);
}
@@ -179,7 +179,7 @@ impl Chapter {
///
/// You need to pass in the book's source directory because all the links in
/// `SUMMARY.md` give the chapter locations relative to it.
fn load_book_from_disk<P: AsRef<Path>>(summary: &Summary, src_dir: P) -> Result<Book> {
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();
@@ -286,7 +286,7 @@ impl<'a> Iterator for BookItems<'a> {
}
impl Display for Chapter {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
if let Some(ref section_number) = self.number {
write!(f, "{} ", section_number)?;
}
@@ -301,7 +301,7 @@ mod tests {
use std::io::Write;
use tempfile::{Builder as TempFileBuilder, TempDir};
const DUMMY_SRC: &'static str = "
const DUMMY_SRC: &str = "
# Dummy Chapter
this is some dummy text.
@@ -317,7 +317,7 @@ And here is some \
let chapter_path = temp.path().join("chapter_1.md");
File::create(&chapter_path)
.unwrap()
.write(DUMMY_SRC.as_bytes())
.write_all(DUMMY_SRC.as_bytes())
.unwrap();
let link = Link::new("Chapter 1", chapter_path);
@@ -333,7 +333,7 @@ And here is some \
File::create(&second_path)
.unwrap()
.write_all("Hello World!".as_bytes())
.write_all(b"Hello World!")
.unwrap();
let mut second = Link::new("Nested Chapter 1", &second_path);
@@ -481,7 +481,8 @@ And here is some \
.filter_map(|i| match *i {
BookItem::Chapter(ref ch) => Some(ch.name.clone()),
_ => None,
}).collect();
})
.collect();
let should_be: Vec<_> = vec![
String::from("Chapter 1"),
String::from("Hello World"),

View File

@@ -1,12 +1,11 @@
use std::fs::{self, File};
use std::io::Write;
use std::path::PathBuf;
use toml;
use super::MDBook;
use config::Config;
use errors::*;
use theme;
use crate::config::Config;
use crate::errors::*;
use crate::theme;
/// A helper for setting up a new book and its directory structure.
#[derive(Debug, Clone, PartialEq)]
@@ -173,15 +172,19 @@ impl BookBuilder {
let src_dir = self.root.join(&self.config.book.src);
let summary = src_dir.join("SUMMARY.md");
let mut f = File::create(&summary).chain_err(|| "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).chain_err(|| "Unable to create chapter_1.md")?;
writeln!(f, "# Chapter 1")?;
if !summary.exists() {
trace!("No summary found creating stub summary and chapter_1.md.");
let mut f = File::create(&summary).chain_err(|| "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).chain_err(|| "Unable to create chapter_1.md")?;
writeln!(f, "# Chapter 1")?;
} else {
trace!("Existing summary found, no need to create stub files.");
}
Ok(())
}

View File

@@ -16,17 +16,18 @@ pub use self::summary::{parse_summary, Link, SectionNumber, Summary, SummaryItem
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 errors::*;
use preprocess::{
use crate::errors::*;
use crate::preprocess::{
CmdPreprocessor, IndexPreprocessor, LinkPreprocessor, Preprocessor, PreprocessorContext,
};
use renderer::{CmdRenderer, HtmlHandlebars, RenderContext, Renderer};
use utils;
use crate::renderer::{CmdRenderer, HtmlHandlebars, RenderContext, Renderer};
use crate::utils;
use config::Config;
use crate::config::Config;
/// The object used to manage and build a book.
pub struct MDBook {
@@ -36,10 +37,10 @@ pub struct MDBook {
pub config: Config,
/// A representation of the book's contents in memory.
pub book: Book,
renderers: Vec<Box<Renderer>>,
renderers: Vec<Box<dyn Renderer>>,
/// List of pre-processors to be run on the book
preprocessors: Vec<Box<Preprocessor>>,
preprocessors: Vec<Box<dyn Preprocessor>>,
}
impl MDBook {
@@ -67,7 +68,7 @@ impl MDBook {
config.update_from_env();
if log_enabled!(::log::Level::Trace) {
if log_enabled!(log::Level::Trace) {
for line in format!("Config: {:#?}", config).lines() {
trace!("{}", line);
}
@@ -95,12 +96,34 @@ impl MDBook {
})
}
/// 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 an [BookItem enum](bookitem.html):
/// `(section: String, bookitem: &BookItem)`
///
/// ```no_run
/// # extern crate mdbook;
/// # use mdbook::MDBook;
/// # use mdbook::book::BookItem;
/// # #[allow(unused_variables)]
@@ -122,7 +145,7 @@ impl MDBook {
/// // etc.
/// # }
/// ```
pub fn iter(&self) -> BookItems {
pub fn iter(&self) -> BookItems<'_> {
self.book.iter()
}
@@ -159,7 +182,7 @@ impl MDBook {
}
/// Run the entire build process for a particular `Renderer`.
fn execute_build_process(&self, renderer: &Renderer) -> Result<()> {
fn execute_build_process(&self, renderer: &dyn Renderer) -> Result<()> {
let mut preprocessed_book = self.book.clone();
let preprocess_ctx = PreprocessorContext::new(
self.root.clone(),
@@ -167,6 +190,19 @@ impl MDBook {
renderer.name().to_string(),
);
let name = renderer.name();
let build_dir = self.build_dir_for(name);
if build_dir.exists() {
debug!(
"Cleaning build dir for the \"{}\" renderer ({})",
name,
build_dir.display()
);
utils::fs::remove_dir_content(&build_dir)
.chain_err(|| "Unable to clear output directory")?;
}
for preprocessor in &self.preprocessors {
if preprocessor_should_run(&**preprocessor, renderer, &self.config) {
debug!("Running the {} preprocessor.", preprocessor.name());
@@ -180,19 +216,9 @@ impl MDBook {
Ok(())
}
fn render(&self, preprocessed_book: &Book, renderer: &Renderer) -> Result<()> {
fn render(&self, preprocessed_book: &Book, renderer: &dyn Renderer) -> Result<()> {
let name = renderer.name();
let build_dir = self.build_dir_for(name);
if build_dir.exists() {
debug!(
"Cleaning build dir for the \"{}\" renderer ({})",
name,
build_dir.display()
);
utils::fs::remove_dir_content(&build_dir)
.chain_err(|| "Unable to clear output directory")?;
}
let render_context = RenderContext::new(
self.root.clone(),
@@ -215,7 +241,7 @@ impl MDBook {
}
/// Register a [`Preprocessor`](../preprocess/trait.Preprocessor.html) to be used when rendering the book.
pub fn with_preprecessor<P: Preprocessor + 'static>(&mut self, preprocessor: P) -> &mut Self {
pub fn with_preprocessor<P: Preprocessor + 'static>(&mut self, preprocessor: P) -> &mut Self {
self.preprocessors.push(Box::new(preprocessor));
self
}
@@ -242,13 +268,12 @@ impl MDBook {
if let BookItem::Chapter(ref ch) = *item {
if !ch.path.as_os_str().is_empty() {
let path = self.source_dir().join(&ch.path);
let content = utils::fs::file_to_string(&path)?;
info!("Testing file: {:?}", path);
// write preprocessed file to tempdir
let path = temp_dir.path().join(&ch.path);
let mut tmpf = utils::fs::create_file(&path)?;
tmpf.write_all(content.as_bytes())?;
tmpf.write_all(ch.content.as_bytes())?;
let output = Command::new("rustdoc")
.arg(&path)
@@ -317,10 +342,10 @@ impl MDBook {
}
/// Look at the `Config` and try to figure out what renderers to use.
fn determine_renderers(config: &Config) -> Vec<Box<Renderer>> {
let mut renderers: Vec<Box<Renderer>> = Vec::new();
fn determine_renderers(config: &Config) -> Vec<Box<dyn Renderer>> {
let mut renderers: Vec<Box<dyn Renderer>> = Vec::new();
if let Some(output_table) = config.get("output").and_then(|o| o.as_table()) {
if let Some(output_table) = config.get("output").and_then(Value::as_table) {
for (key, table) in output_table.iter() {
// the "html" backend has its own Renderer
if key == "html" {
@@ -340,27 +365,27 @@ fn determine_renderers(config: &Config) -> Vec<Box<Renderer>> {
renderers
}
fn default_preprocessors() -> Vec<Box<Preprocessor>> {
fn default_preprocessors() -> Vec<Box<dyn Preprocessor>> {
vec![
Box::new(LinkPreprocessor::new()),
Box::new(IndexPreprocessor::new()),
]
}
fn is_default_preprocessor(pre: &Preprocessor) -> bool {
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<Preprocessor>>> {
fn determine_preprocessors(config: &Config) -> Result<Vec<Box<dyn Preprocessor>>> {
let mut preprocessors = Vec::new();
if config.build.use_default_preprocessors {
preprocessors.extend(default_preprocessors());
}
if let Some(preprocessor_table) = config.get("preprocessor").and_then(|v| v.as_table()) {
if let Some(preprocessor_table) = config.get("preprocessor").and_then(Value::as_table) {
for key in preprocessor_table.keys() {
match key.as_ref() {
"links" => preprocessors.push(Box::new(LinkPreprocessor::new())),
@@ -379,8 +404,8 @@ fn determine_preprocessors(config: &Config) -> Result<Vec<Box<Preprocessor>>> {
fn interpret_custom_preprocessor(key: &str, table: &Value) -> Box<CmdPreprocessor> {
let command = table
.get("command")
.and_then(|c| c.as_str())
.map(|s| s.to_string())
.and_then(Value::as_str)
.map(ToString::to_string)
.unwrap_or_else(|| format!("mdbook-{}", key));
Box::new(CmdPreprocessor::new(key.to_string(), command.to_string()))
@@ -391,8 +416,8 @@ fn interpret_custom_renderer(key: &str, table: &Value) -> Box<CmdRenderer> {
// prepended by "mdbook-"
let table_dot_command = table
.get("command")
.and_then(|c| c.as_str())
.map(|s| s.to_string());
.and_then(Value::as_str)
.map(ToString::to_string);
let command = table_dot_command.unwrap_or_else(|| format!("mdbook-{}", key));
@@ -405,7 +430,11 @@ fn interpret_custom_renderer(key: &str, table: &Value) -> Box<CmdRenderer> {
///
/// 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: &Preprocessor, renderer: &Renderer, cfg: &Config) -> bool {
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());
@@ -417,7 +446,7 @@ fn preprocessor_should_run(preprocessor: &Preprocessor, renderer: &Renderer, cfg
if let Some(Value::Array(ref explicit_renderers)) = cfg.get(&key) {
return explicit_renderers
.iter()
.filter_map(|val| val.as_str())
.filter_map(Value::as_str)
.any(|name| name == renderer_name);
}
@@ -427,6 +456,7 @@ fn preprocessor_should_run(preprocessor: &Preprocessor, renderer: &Renderer, cfg
#[cfg(test)]
mod tests {
use super::*;
use std::str::FromStr;
use toml::value::{Table, Value};
#[test]
@@ -494,7 +524,7 @@ mod tests {
#[test]
fn can_determine_third_party_preprocessors() {
let cfg_str: &'static str = r#"
let cfg_str = r#"
[book]
title = "Some Book"
@@ -533,7 +563,7 @@ mod tests {
#[test]
fn config_respects_preprocessor_selection() {
let cfg_str: &'static str = r#"
let cfg_str = r#"
[preprocessor.links]
renderers = ["html"]
"#;
@@ -544,9 +574,9 @@ mod tests {
let html = cfg
.get_preprocessor("links")
.and_then(|links| links.get("renderers"))
.and_then(|renderers| renderers.as_array())
.and_then(Value::as_array)
.and_then(|renderers| renderers.get(0))
.and_then(|renderer| renderer.as_str())
.and_then(Value::as_str)
.unwrap();
assert_eq!(html, "html");
let html_renderer = HtmlHandlebars::default();

View File

@@ -1,4 +1,4 @@
use errors::*;
use crate::errors::*;
use memchr::{self, Memchr};
use pulldown_cmark::{self, Event, Tag};
use std::fmt::{self, Display, Formatter};
@@ -195,7 +195,7 @@ macro_rules! collect_events {
}
impl<'a> SummaryParser<'a> {
fn new(text: &str) -> SummaryParser {
fn new(text: &str) -> SummaryParser<'_> {
let pulldown_parser = pulldown_cmark::Parser::new(text);
SummaryParser {
@@ -259,7 +259,7 @@ impl<'a> SummaryParser<'a> {
bail!(self.parse_error("Suffix chapters cannot be followed by a list"));
}
}
Some(Event::Start(Tag::Link(href, _))) => {
Some(Event::Start(Tag::Link(_type, href, _title))) => {
let link = self.parse_link(href.to_string())?;
items.push(SummaryItem::Link(link));
}
@@ -397,7 +397,7 @@ impl<'a> SummaryParser<'a> {
loop {
match self.next_event() {
Some(Event::Start(Tag::Paragraph)) => continue,
Some(Event::Start(Tag::Link(href, _))) => {
Some(Event::Start(Tag::Link(_type, href, _title))) => {
let mut link = self.parse_link(href.to_string())?;
let mut number = parent.clone();
@@ -471,13 +471,14 @@ fn get_last_link(links: &mut [SummaryItem]) -> Result<(usize, &mut Link)> {
/// Removes the styling from a list of Markdown events and returns just the
/// plain text.
fn stringify_events(events: Vec<Event>) -> String {
fn stringify_events(events: Vec<Event<'_>>) -> String {
events
.into_iter()
.filter_map(|t| match t {
Event::Text(text) => Some(text.into_owned()),
Event::Text(text) | Event::Code(text) => Some(text.into_string()),
_ => None,
}).collect()
})
.collect()
}
/// A section number like "1.2.3", basically just a newtype'd `Vec<u32>` with
@@ -486,7 +487,7 @@ fn stringify_events(events: Vec<Event>) -> String {
pub struct SectionNumber(pub Vec<u32>);
impl Display for SectionNumber {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
if self.0.is_empty() {
write!(f, "0")
} else {
@@ -628,7 +629,7 @@ mod tests {
let _ = parser.stream.next(); // skip past start of paragraph
let href = match parser.stream.next() {
Some(Event::Start(Tag::Link(href, _))) => href.to_string(),
Some(Event::Start(Tag::Link(_type, href, _title))) => href.to_string(),
other => panic!("Unreachable, {:?}", other),
};

View File

@@ -1,7 +1,7 @@
use crate::{get_book_dir, open};
use clap::{App, ArgMatches, SubCommand};
use mdbook::errors::Result;
use mdbook::MDBook;
use {get_book_dir, open};
// Create clap subcommand arguments
pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
@@ -11,10 +11,12 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
"-d, --dest-dir=[dest-dir] '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`.'",
).arg_from_usage(
)
.arg_from_usage(
"[dir] 'Root directory for the book{n}\
(Defaults to the Current Directory when omitted)'",
).arg_from_usage("-o, --open 'Opens the compiled book in a web browser'")
)
.arg_from_usage("-o, --open 'Opens the compiled book in a web browser'")
}
// Build command implementation

View File

@@ -1,5 +1,5 @@
use crate::get_book_dir;
use clap::{App, ArgMatches, SubCommand};
use get_book_dir;
use mdbook::errors::*;
use mdbook::MDBook;
use std::fs;
@@ -13,14 +13,15 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
Relative paths are interpreted relative to the book's root directory.{n}\
Running this command deletes this directory.{n}\
If omitted, mdBook uses build.build-dir from book.toml or defaults to `./book`.'",
).arg_from_usage(
)
.arg_from_usage(
"[dir] 'Root directory for the book{n}\
(Defaults to the Current Directory when omitted)'",
)
}
// Clean command implementation
pub fn execute(args: &ArgMatches) -> ::mdbook::errors::Result<()> {
pub fn execute(args: &ArgMatches) -> mdbook::errors::Result<()> {
let book_dir = get_book_dir(args);
let book = MDBook::load(&book_dir)?;

View File

@@ -1,5 +1,5 @@
use crate::get_book_dir;
use clap::{App, ArgMatches, SubCommand};
use get_book_dir;
use mdbook::config;
use mdbook::errors::Result;
use mdbook::MDBook;
@@ -15,7 +15,8 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
.arg_from_usage(
"[dir] 'Directory to create the book in{n}\
(Defaults to the Current Directory when omitted)'",
).arg_from_usage("--theme 'Copies the default theme into your source folder'")
)
.arg_from_usage("--theme 'Copies the default theme into your source folder'")
.arg_from_usage("--force 'Skips confirmation prompts'")
}

View File

@@ -1,18 +1,11 @@
extern crate iron;
extern crate staticfile;
extern crate ws;
use self::iron::{
status, AfterMiddleware, Chain, Iron, IronError, IronResult, Request, Response, Set,
};
#[cfg(feature = "watch")]
use super::watch;
use crate::{get_book_dir, open};
use clap::{App, Arg, ArgMatches, SubCommand};
use iron::{status, AfterMiddleware, Chain, Iron, IronError, IronResult, Request, Response, Set};
use mdbook::errors::*;
use mdbook::utils;
use mdbook::MDBook;
use std;
use {get_book_dir, open};
struct ErrorRecover;
@@ -115,8 +108,8 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
}
#[cfg(feature = "watch")]
watch::trigger_on_change(&book, move |path, book_dir| {
info!("File changed: {:?}", path);
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 :(
@@ -126,7 +119,8 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
b.config
.set("output.html.livereload-url", &livereload_url)?;
Ok(b)
}).and_then(|b| b.build());
})
.and_then(|b| b.build());
if let Err(e) = result {
error!("Unable to load the book");

View File

@@ -1,5 +1,5 @@
use crate::get_book_dir;
use clap::{App, Arg, ArgMatches, SubCommand};
use get_book_dir;
use mdbook::errors::Result;
use mdbook::MDBook;
@@ -31,7 +31,7 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
pub fn execute(args: &ArgMatches) -> Result<()> {
let library_paths: Vec<&str> = args
.values_of("library-path")
.map(|v| v.collect())
.map(std::iter::Iterator::collect)
.unwrap_or_default();
let book_dir = get_book_dir(args);
let mut book = MDBook::load(&book_dir)?;

View File

@@ -1,14 +1,13 @@
extern crate notify;
use self::notify::Watcher;
use crate::{get_book_dir, open};
use clap::{App, ArgMatches, SubCommand};
use mdbook::errors::Result;
use mdbook::utils;
use mdbook::MDBook;
use std::path::Path;
use notify::Watcher;
use std::path::{Path, PathBuf};
use std::sync::mpsc::channel;
use std::thread::sleep;
use std::time::Duration;
use {get_book_dir, open};
// Create clap subcommand arguments
pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
@@ -18,10 +17,12 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
"-d, --dest-dir=[dest-dir] '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`.'",
).arg_from_usage(
)
.arg_from_usage(
"[dir] 'Root directory for the book{n}\
(Defaults to the Current Directory when omitted)'",
).arg_from_usage("-o, --open 'Open the compiled book in a web browser'")
)
.arg_from_usage("-o, --open 'Open the compiled book in a web browser'")
}
// Watch command implementation
@@ -34,8 +35,8 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
open(book.build_dir_for("html").join("index.html"));
}
trigger_on_change(&book, |path, book_dir| {
info!("File changed: {:?}\nBuilding book...\n", path);
trigger_on_change(&book, |paths, book_dir| {
info!("Files changed: {:?}\nBuilding book...\n", paths);
let result = MDBook::load(&book_dir).and_then(|b| b.build());
if let Err(e) = result {
@@ -50,10 +51,10 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
/// 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(&Path, &Path),
F: Fn(Vec<PathBuf>, &Path),
{
use self::notify::DebouncedEvent::*;
use self::notify::RecursiveMode::*;
use notify::DebouncedEvent::*;
use notify::RecursiveMode::*;
// Create a channel to receive the events.
let (tx, rx) = channel();
@@ -62,14 +63,14 @@ where
Ok(w) => w,
Err(e) => {
error!("Error while trying to watch the files:\n\n\t{:?}", e);
::std::process::exit(1)
std::process::exit(1)
}
};
// 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);
std::process::exit(1);
};
let _ = watcher.watch(book.theme_dir(), Recursive);
@@ -79,13 +80,24 @@ where
info!("Listening for changes...");
for event in rx.iter() {
debug!("Received filesystem event: {:?}", event);
match event {
Create(path) | Write(path) | Remove(path) | Rename(_, path) => {
closure(&path, &book.root);
}
_ => {}
}
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 = all_events
.filter_map(|event| {
debug!("Received filesystem event: {:?}", event);
match event {
Create(path) | Write(path) | Remove(path) | Rename(_, path) => Some(path),
_ => None,
}
})
.collect();
closure(paths, &book.root);
}
}

View File

@@ -3,16 +3,15 @@
//! The main entrypoint of the `config` module is the `Config` struct. This acts
//! essentially as a bag of configuration information, with a couple
//! pre-determined tables (`BookConfig` and `BuildConfig`) as well as support
//! for arbitrary data which is exposed to plugins and alternate backends.
//! for arbitrary data which is exposed to plugins and alternative backends.
//!
//!
//! # Examples
//!
//! ```rust
//! # extern crate mdbook;
//! # use mdbook::errors::*;
//! # extern crate toml;
//! use std::path::PathBuf;
//! use std::str::FromStr;
//! use mdbook::Config;
//! use toml::Value;
//!
@@ -51,18 +50,18 @@
#![deny(missing_docs)]
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_json;
use std::env;
use std::fs::File;
use std::io::Read;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use toml::value::Table;
use toml::{self, Value};
use toml_query::delete::TomlValueDeleteExt;
use toml_query::insert::TomlValueInsertExt;
use toml_query::read::TomlValueReadExt;
use errors::*;
use crate::errors::*;
/// The overall configuration object for MDBook, essentially an in-memory
/// representation of `book.toml`.
@@ -75,12 +74,16 @@ pub struct Config {
rest: Value,
}
impl Config {
impl FromStr for Config {
type Err = Error;
/// Load a `Config` from some string.
pub fn from_str(src: &str) -> Result<Config> {
fn from_str(src: &str) -> Result<Self> {
toml::from_str(src).chain_err(|| Error::from("Invalid configuration file"))
}
}
impl Config {
/// Load the configuration file from disk.
pub fn from_disk<P: AsRef<Path>>(config_file: P) -> Result<Config> {
let mut buffer = String::new();
@@ -203,7 +206,9 @@ impl Config {
} else if index.starts_with("build.") {
self.build.update_value(&index[6..], value);
} else {
self.rest.insert(index, value)?;
self.rest
.insert(index, value)
.map_err(|e| ErrorKind::TomlQueryError(e))?;
}
Ok(())
@@ -212,13 +217,13 @@ impl Config {
/// Get the table associated with a particular renderer.
pub fn get_renderer<I: AsRef<str>>(&self, index: I) -> Option<&Table> {
let key = format!("output.{}", index.as_ref());
self.get(&key).and_then(|v| v.as_table())
self.get(&key).and_then(Value::as_table)
}
/// Get the table associated with a particular preprocessor.
pub fn get_preprocessor<I: AsRef<str>>(&self, index: I) -> Option<&Table> {
let key = format!("preprocessor.{}", index.as_ref());
self.get(&key).and_then(|v| v.as_table())
self.get(&key).and_then(Value::as_table)
}
fn from_legacy(mut table: Value) -> Config {
@@ -265,7 +270,7 @@ impl Default for Config {
}
}
impl<'de> Deserialize<'de> for Config {
fn deserialize<D: Deserializer<'de>>(de: D) -> ::std::result::Result<Self, D::Error> {
fn deserialize<D: Deserializer<'de>>(de: D) -> std::result::Result<Self, D::Error> {
let raw = Value::deserialize(de)?;
if is_legacy_format(&raw) {
@@ -309,7 +314,7 @@ impl<'de> Deserialize<'de> for Config {
}
impl Serialize for Config {
fn serialize<S: Serializer>(&self, s: S) -> ::std::result::Result<S::Ok, S::Error> {
fn serialize<S: Serializer>(&self, s: S) -> std::result::Result<S::Ok, S::Error> {
use serde::ser::Error;
let mut table = self.rest.clone();
@@ -560,7 +565,7 @@ impl<'de, T> Updateable<'de> for T where T: Serialize + Deserialize<'de> {}
mod tests {
use super::*;
const COMPLEX_CONFIG: &'static str = r#"
const COMPLEX_CONFIG: &str = r#"
[book]
title = "Some Book"
authors = ["Michael-F-Bryan <michaelfbryan@gmail.com>"]
@@ -586,9 +591,9 @@ mod tests {
editable = true
editor = "ace"
[preprocess.first]
[preprocessor.first]
[preprocess.second]
[preprocessor.second]
"#;
#[test]
@@ -601,7 +606,6 @@ mod tests {
description: Some(String::from("A completely useless book")),
multilingual: true,
src: PathBuf::from("source"),
..Default::default()
};
let build_should_be = BuildConfig {
build_dir: PathBuf::from("outputs"),
@@ -658,10 +662,10 @@ mod tests {
assert_eq!(got, should_be);
let baz: Vec<bool> = cfg.get_deserialized("output.random.baz").unwrap();
let got_baz: Vec<bool> = cfg.get_deserialized("output.random.baz").unwrap();
let baz_should_be = vec![true, true, false];
assert_eq!(baz, baz_should_be);
assert_eq!(got_baz, baz_should_be);
}
#[test]
@@ -753,7 +757,7 @@ mod tests {
for (src, should_be) in inputs {
let got = parse_env(src);
let should_be = should_be.map(|s| s.to_string());
let should_be = should_be.map(ToString::to_string);
assert_eq!(got, should_be);
}
@@ -783,6 +787,7 @@ mod tests {
}
#[test]
#[allow(clippy::approx_constant)]
fn update_config_using_env_var_and_complex_value() {
let mut cfg = Config::default();
let key = "foo-bar.baz";

View File

@@ -81,27 +81,18 @@
//! [`Config`]: config/struct.Config.html
#![deny(missing_docs)]
#![deny(rust_2018_idioms)]
#[macro_use]
extern crate error_chain;
extern crate handlebars;
extern crate itertools;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate log;
extern crate memchr;
extern crate pulldown_cmark;
extern crate regex;
extern crate serde;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate serde_json;
extern crate shlex;
extern crate tempfile;
extern crate toml;
extern crate toml_query;
#[cfg(test)]
#[macro_use]
@@ -120,31 +111,27 @@ pub mod utils;
/// compatibility checks.
pub const MDBOOK_VERSION: &str = env!("CARGO_PKG_VERSION");
pub use book::BookItem;
pub use book::MDBook;
pub use config::Config;
pub use renderer::Renderer;
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 {
use std::path::PathBuf;
error_chain!{
error_chain! {
foreign_links {
Io(::std::io::Error) #[doc = "A wrapper around `std::io::Error`"];
HandlebarsRender(::handlebars::RenderError) #[doc = "Handlebars rendering failed"];
HandlebarsTemplate(Box<::handlebars::TemplateError>) #[doc = "Unable to parse the template"];
Utf8(::std::string::FromUtf8Error) #[doc = "Invalid UTF-8"];
SerdeJson(::serde_json::Error) #[doc = "JSON conversion failed"];
}
links {
TomlQuery(::toml_query::error::Error, ::toml_query::error::ErrorKind) #[doc = "A TomlQuery error"];
Io(std::io::Error) #[doc = "A wrapper around `std::io::Error`"];
HandlebarsRender(handlebars::RenderError) #[doc = "Handlebars rendering failed"];
HandlebarsTemplate(Box<handlebars::TemplateError>) #[doc = "Unable to parse the template"];
Utf8(std::string::FromUtf8Error) #[doc = "Invalid UTF-8"];
SerdeJson(serde_json::Error) #[doc = "JSON conversion failed"];
}
errors {
/// A subprocess exited with an unsuccessful return code.
Subprocess(message: String, output: ::std::process::Output) {
Subprocess(message: String, output: std::process::Output) {
description("A subprocess failed")
display("{}: {}", message, String::from_utf8_lossy(&output.stdout))
}
@@ -160,12 +147,18 @@ pub mod errors {
description("Reserved Filename")
display("{} is reserved for internal use", filename.display())
}
/// Error with a TOML file.
TomlQueryError(inner: toml_query::error::Error) {
description("toml_query error")
display("{}", inner)
}
}
}
// Box to halve the size of Error
impl From<::handlebars::TemplateError> for Error {
fn from(e: ::handlebars::TemplateError) -> Error {
impl From<handlebars::TemplateError> for Error {
fn from(e: handlebars::TemplateError) -> Error {
From::from(Box::new(e))
}
}

View File

@@ -1,12 +1,7 @@
extern crate chrono;
#[macro_use]
extern crate clap;
extern crate env_logger;
extern crate error_chain;
#[macro_use]
extern crate log;
extern crate mdbook;
extern crate open;
use chrono::Local;
use clap::{App, AppSettings, ArgMatches};
@@ -20,19 +15,19 @@ use std::path::{Path, PathBuf};
mod cmd;
const NAME: &str = "mdBook";
const VERSION: &str = concat!("v", crate_version!());
fn main() {
init_logger();
// Create a list of valid arguments and sub-commands
let app = App::new(NAME)
.about("Creates a book from markdown files")
let app = App::new(crate_name!())
.about(crate_description!())
.author("Mathieu David <mathieudavid@mathieudavid.org>")
.version(VERSION)
.setting(AppSettings::GlobalVersion)
.setting(AppSettings::ArgRequiredElseHelp)
.setting(AppSettings::ColoredHelp)
.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-nursery/mdBook",
@@ -63,7 +58,7 @@ fn main() {
if let Err(e) = res {
utils::log_backtrace(&e);
::std::process::exit(101);
std::process::exit(101);
}
}
@@ -82,7 +77,7 @@ fn init_logger() {
});
if let Ok(var) = env::var("RUST_LOG") {
builder.parse(&var);
builder.parse_filters(&var);
} else {
// if no RUST_LOG provided, default to logging at the Info level
builder.filter(None, LevelFilter::Info);

View File

@@ -1,7 +1,6 @@
use super::{Preprocessor, PreprocessorContext};
use book::Book;
use errors::*;
use serde_json;
use crate::book::Book;
use crate::errors::*;
use shlex::Shlex;
use std::io::{self, Read, Write};
use std::process::{Child, Command, Stdio};
@@ -168,8 +167,8 @@ impl Preprocessor for CmdPreprocessor {
#[cfg(test)]
mod tests {
use super::*;
use crate::MDBook;
use std::path::Path;
use MDBook;
fn book_example() -> MDBook {
let example = Path::new(env!("CARGO_MANIFEST_DIR")).join("book-example");

View File

@@ -1,13 +1,14 @@
use regex::Regex;
use std::path::Path;
use errors::*;
use crate::errors::*;
use super::{Preprocessor, PreprocessorContext};
use book::{Book, BookItem};
use crate::book::{Book, BookItem};
/// 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 {
@@ -45,7 +46,10 @@ impl Preprocessor for IndexPreprocessor {
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(index_path.as_ref());
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,
@@ -67,7 +71,7 @@ fn is_readme_file<P: AsRef<Path>>(path: P) -> bool {
RE.is_match(
path.as_ref()
.file_stem()
.and_then(|s| s.to_str())
.and_then(std::ffi::OsStr::to_str)
.unwrap_or_default(),
)
}

View File

@@ -1,18 +1,19 @@
use errors::*;
use crate::errors::*;
use crate::utils::fs::file_to_string;
use crate::utils::take_lines;
use regex::{CaptureMatches, Captures, Regex};
use std::ops::{Range, RangeFrom, RangeFull, RangeTo};
use std::path::{Path, PathBuf};
use utils::fs::file_to_string;
use utils::take_lines;
use super::{Preprocessor, PreprocessorContext};
use book::{Book, BookItem};
use crate::book::{Book, BookItem};
const ESCAPE_CHAR: char = '\\';
const MAX_LINK_NESTED_DEPTH: usize = 10;
/// A preprocessor for expanding the `{{# playpen}}` and `{{# include}}`
/// helpers in a chapter.
#[derive(Default)]
pub struct LinkPreprocessor;
impl LinkPreprocessor {
@@ -143,17 +144,19 @@ fn parse_include_path(path: &str) -> LinkType<'static> {
match start {
Some(start) => match end {
Some(end) => LinkType::IncludeRange(path, Range { start, end }),
None => if has_end {
LinkType::IncludeRangeFrom(path, RangeFrom { start })
} else {
LinkType::IncludeRange(
path,
Range {
start,
end: start + 1,
},
)
},
None => {
if has_end {
LinkType::IncludeRangeFrom(path, RangeFrom { start })
} else {
LinkType::IncludeRange(
path,
Range {
start,
end: start + 1,
},
)
}
}
},
None => match end {
Some(end) => LinkType::IncludeRangeTo(path, RangeTo { end }),
@@ -291,7 +294,7 @@ impl<'a> Iterator for LinkIter<'a> {
}
}
fn find_links(contents: &str) -> LinkIter {
fn find_links(contents: &str) -> LinkIter<'_> {
// lazily compute following regex
// r"\\\{\{#.*\}\}|\{\{#([a-zA-Z0-9]+)\s*([a-zA-Z0-9_.\-:/\\\s]+)\}\}")?;
lazy_static! {
@@ -304,7 +307,8 @@ fn find_links(contents: &str) -> LinkIter {
\s+ # separating whitespace
([a-zA-Z0-9\s_.\-:/\\]+) # link target path and space separated properties
\s*\}\} # whitespace and link closing parens"
).unwrap();
)
.unwrap();
}
LinkIter(RE.captures_iter(contents))
}

View File

@@ -8,9 +8,9 @@ mod cmd;
mod index;
mod links;
use book::Book;
use config::Config;
use errors::*;
use crate::book::Book;
use crate::config::Config;
use crate::errors::*;
use std::path::PathBuf;
@@ -37,7 +37,7 @@ impl PreprocessorContext {
root,
config,
renderer,
mdbook_version: ::MDBOOK_VERSION.to_string(),
mdbook_version: crate::MDBOOK_VERSION.to_string(),
__non_exhaustive: (),
}
}

View File

@@ -1,10 +1,10 @@
use book::{Book, BookItem};
use config::{Config, HtmlConfig, Playpen};
use errors::*;
use renderer::html_handlebars::helpers;
use renderer::{RenderContext, Renderer};
use theme::{self, playpen_editor, Theme};
use utils;
use crate::book::{Book, BookItem};
use crate::config::{Config, HtmlConfig, Playpen};
use crate::errors::*;
use crate::renderer::html_handlebars::helpers;
use crate::renderer::{RenderContext, Renderer};
use crate::theme::{self, playpen_editor, Theme};
use crate::utils;
use std::collections::BTreeMap;
use std::collections::HashMap;
@@ -13,7 +13,6 @@ use std::path::{Path, PathBuf};
use handlebars::Handlebars;
use regex::{Captures, Regex};
use serde_json;
#[derive(Default)]
pub struct HtmlHandlebars;
@@ -26,7 +25,7 @@ impl HtmlHandlebars {
fn render_item(
&self,
item: &BookItem,
mut ctx: RenderItemContext,
mut ctx: RenderItemContext<'_>,
print_content: &mut String,
) -> Result<()> {
// FIXME: This should be made DRY-er and rely less on mutable state
@@ -36,7 +35,11 @@ impl HtmlHandlebars {
let string_path = ch.path.parent().unwrap().display().to_string();
let fixed_content = utils::render_markdown_with_base(&ch.content, ctx.html_config.curly_quotes, &string_path);
let fixed_content = utils::render_markdown_with_base(
&ch.content,
ctx.html_config.curly_quotes,
&string_path,
);
print_content.push_str(&fixed_content);
// Update the context with data for this file
@@ -82,7 +85,7 @@ impl HtmlHandlebars {
utils::fs::write_file(&ctx.destination, &filepath, rendered.as_bytes())?;
if ctx.is_index {
ctx.data.insert("path".to_owned(), json!("index.html"));
ctx.data.insert("path".to_owned(), json!("index.md"));
ctx.data.insert("path_to_root".to_owned(), json!(""));
let rendered_index = ctx.handlebars.render("index", &ctx.data)?;
let rendered_index = self.post_process(rendered_index, &ctx.html_config.playpen);
@@ -109,7 +112,7 @@ impl HtmlHandlebars {
theme: &Theme,
html_config: &HtmlConfig,
) -> Result<()> {
use utils::fs::write_file;
use crate::utils::fs::write_file;
write_file(
destination,
@@ -425,13 +428,7 @@ fn make_data(
for script in &html.additional_js {
match script.strip_prefix(root) {
Ok(p) => js.push(p.to_str().expect("Could not convert to str")),
Err(_) => js.push(
script
.file_name()
.expect("File has a file name")
.to_str()
.expect("Could not convert to str"),
),
Err(_) => js.push(script.to_str().expect("Could not convert to str")),
}
}
data.insert("additional_js".to_owned(), json!(js));
@@ -499,25 +496,26 @@ fn make_data(
Ok(data)
}
/// Goes through the rendered HTML, making sure all header tags are wrapped in
/// an anchor so people can link to sections directly.
/// Goes through the rendered HTML, making sure all header tags have
/// an anchor respectively so people can link to sections directly.
fn build_header_links(html: &str) -> String {
let regex = Regex::new(r"<h(\d)>(.*?)</h\d>").unwrap();
let mut id_counter = HashMap::new();
regex
.replace_all(html, |caps: &Captures| {
.replace_all(html, |caps: &Captures<'_>| {
let level = caps[1]
.parse()
.expect("Regex should ensure we only ever get numbers here");
wrap_header_with_link(level, &caps[2], &mut id_counter)
}).into_owned()
insert_link_into_header(level, &caps[2], &mut id_counter)
})
.into_owned()
}
/// Wraps a single header tag with a link, making sure each tag gets its own
/// Insert a sinle link into a header, making sure each link gets its own
/// unique ID by appending an auto-incremented number (if necessary).
fn wrap_header_with_link(
fn insert_link_into_header(
level: usize,
content: &str,
id_counter: &mut HashMap<String, usize>,
@@ -534,7 +532,7 @@ fn wrap_header_with_link(
*id_count += 1;
format!(
r##"<a class="header" href="#{id}" id="{id}"><h{level}>{text}</h{level}></a>"##,
r##"<h{level}><a class="header" href="#{id}" id="{id}">{text}</a></h{level}>"##,
level = level,
id = id,
text = content
@@ -552,7 +550,7 @@ fn wrap_header_with_link(
fn fix_code_blocks(html: &str) -> String {
let regex = Regex::new(r##"<code([^>]+)class="([^"]+)"([^>]*)>"##).unwrap();
regex
.replace_all(html, |caps: &Captures| {
.replace_all(html, |caps: &Captures<'_>| {
let before = &caps[1];
let classes = &caps[2].replace(",", " ");
let after = &caps[3];
@@ -563,13 +561,14 @@ fn fix_code_blocks(html: &str) -> String {
classes = classes,
after = after
)
}).into_owned()
})
.into_owned()
}
fn add_playpen_pre(html: &str, playpen_config: &Playpen) -> String {
let regex = Regex::new(r##"((?s)<code[^>]?class="([^"]+)".*?>(.*?)</code>)"##).unwrap();
regex
.replace_all(html, |caps: &Captures| {
.replace_all(html, |caps: &Captures<'_>| {
let text = &caps[1];
let classes = &caps[2];
let code = &caps[3];
@@ -599,7 +598,8 @@ fn add_playpen_pre(html: &str, playpen_config: &Playpen) -> String {
// not language-rust, so no-op
text.to_owned()
}
}).into_owned()
})
.into_owned()
}
fn partition_source(s: &str) -> (String, String) {
@@ -609,7 +609,7 @@ fn partition_source(s: &str) -> (String, String) {
for line in s.lines() {
let trimline = line.trim();
let header = trimline.chars().all(|c| c.is_whitespace()) || trimline.starts_with("#![");
let header = trimline.chars().all(char::is_whitespace) || trimline.starts_with("#![");
if !header || after_header {
after_header = true;
after.push_str(line);
@@ -640,27 +640,27 @@ mod tests {
let inputs = vec![
(
"blah blah <h1>Foo</h1>",
r##"blah blah <a class="header" href="#foo" id="foo"><h1>Foo</h1></a>"##,
r##"blah blah <h1><a class="header" href="#foo" id="foo">Foo</a></h1>"##,
),
(
"<h1>Foo</h1>",
r##"<a class="header" href="#foo" id="foo"><h1>Foo</h1></a>"##,
r##"<h1><a class="header" href="#foo" id="foo">Foo</a></h1>"##,
),
(
"<h3>Foo^bar</h3>",
r##"<a class="header" href="#foobar" id="foobar"><h3>Foo^bar</h3></a>"##,
r##"<h3><a class="header" href="#foobar" id="foobar">Foo^bar</a></h3>"##,
),
(
"<h4></h4>",
r##"<a class="header" href="#" id=""><h4></h4></a>"##,
r##"<h4><a class="header" href="#" id=""></a></h4>"##,
),
(
"<h4><em>Hï</em></h4>",
r##"<a class="header" href="#hï" id="hï"><h4><em>Hï</em></h4></a>"##,
r##"<h4><a class="header" href="#hï" id="hï"><em>Hï</em></a></h4>"##,
),
(
"<h1>Foo</h1><h3>Foo</h3>",
r##"<a class="header" href="#foo" id="foo"><h1>Foo</h1></a><a class="header" href="#foo-1" id="foo-1"><h3>Foo</h3></a>"##,
r##"<h1><a class="header" href="#foo" id="foo">Foo</a></h1><h3><a class="header" href="#foo-1" id="foo-1">Foo</a></h3>"##,
),
];

View File

@@ -2,9 +2,8 @@ use std::collections::BTreeMap;
use std::path::Path;
use handlebars::{Context, Handlebars, Helper, Output, RenderContext, RenderError, Renderable};
use serde_json;
use utils;
use crate::utils;
type StringMap = BTreeMap<String, String>;
@@ -47,7 +46,7 @@ impl Target {
fn find_chapter(
ctx: &Context,
rc: &mut RenderContext,
rc: &mut RenderContext<'_>,
target: Target,
) -> Result<Option<StringMap>, RenderError> {
debug!("Get data from context");
@@ -86,11 +85,11 @@ fn find_chapter(
}
fn render(
_h: &Helper,
_h: &Helper<'_, '_>,
r: &Handlebars,
ctx: &Context,
rc: &mut RenderContext,
out: &mut Output,
rc: &mut RenderContext<'_>,
out: &mut dyn Output,
chapter: &StringMap,
) -> Result<(), RenderError> {
trace!("Creating BTreeMap to inject in context");
@@ -137,11 +136,11 @@ fn render(
}
pub fn previous(
_h: &Helper,
_h: &Helper<'_, '_>,
r: &Handlebars,
ctx: &Context,
rc: &mut RenderContext,
out: &mut Output,
rc: &mut RenderContext<'_>,
out: &mut dyn Output,
) -> Result<(), RenderError> {
trace!("previous (handlebars helper)");
@@ -153,11 +152,11 @@ pub fn previous(
}
pub fn next(
_h: &Helper,
_h: &Helper<'_, '_>,
r: &Handlebars,
ctx: &Context,
rc: &mut RenderContext,
out: &mut Output,
rc: &mut RenderContext<'_>,
out: &mut dyn Output,
) -> Result<(), RenderError> {
trace!("next (handlebars helper)");
@@ -172,29 +171,29 @@ pub fn next(
mod tests {
use super::*;
static TEMPLATE: &'static str =
static TEMPLATE: &str =
"{{#previous}}{{title}}: {{link}}{{/previous}}|{{#next}}{{title}}: {{link}}{{/next}}";
#[test]
fn test_next_previous() {
let data = json!({
"name": "two",
"path": "two.path",
"chapters": [
{
"name": "one",
"path": "one.path"
},
{
"name": "two",
"path": "two.path",
},
{
"name": "three",
"path": "three.path"
}
]
});
"name": "two",
"path": "two.path",
"chapters": [
{
"name": "one",
"path": "one.path"
},
{
"name": "two",
"path": "two.path",
},
{
"name": "three",
"path": "three.path"
}
]
});
let mut h = Handlebars::new();
h.register_helper("previous", Box::new(previous));
@@ -209,23 +208,23 @@ mod tests {
#[test]
fn test_first() {
let data = json!({
"name": "one",
"path": "one.path",
"chapters": [
{
"name": "one",
"path": "one.path"
},
{
"name": "two",
"path": "two.path",
},
{
"name": "three",
"path": "three.path"
}
]
});
"name": "one",
"path": "one.path",
"chapters": [
{
"name": "one",
"path": "one.path"
},
{
"name": "two",
"path": "two.path",
},
{
"name": "three",
"path": "three.path"
}
]
});
let mut h = Handlebars::new();
h.register_helper("previous", Box::new(previous));
@@ -239,23 +238,23 @@ mod tests {
#[test]
fn test_last() {
let data = json!({
"name": "three",
"path": "three.path",
"chapters": [
{
"name": "one",
"path": "one.path"
},
{
"name": "two",
"path": "two.path",
},
{
"name": "three",
"path": "three.path"
}
]
});
"name": "three",
"path": "three.path",
"chapters": [
{
"name": "one",
"path": "one.path"
},
{
"name": "two",
"path": "two.path",
},
{
"name": "three",
"path": "three.path"
}
]
});
let mut h = Handlebars::new();
h.register_helper("previous", Box::new(previous));

View File

@@ -1,20 +1,17 @@
use handlebars::{Context, Handlebars, Helper, Output, RenderContext, RenderError};
pub fn theme_option(
h: &Helper,
h: &Helper<'_, '_>,
_r: &Handlebars,
ctx: &Context,
rc: &mut RenderContext,
out: &mut Output,
rc: &mut RenderContext<'_>,
out: &mut dyn Output,
) -> Result<(), RenderError> {
trace!("theme_option (handlebars helper)");
let param = h
.param(0)
.and_then(|v| v.value().as_str())
.ok_or(RenderError::new(
"Param 0 with String type is required for theme_option helper.",
))?;
let param = h.param(0).and_then(|v| v.value().as_str()).ok_or_else(|| {
RenderError::new("Param 0 with String type is required for theme_option helper.")
})?;
let theme_name = rc
.evaluate_absolute(ctx, "default_theme", true)?

View File

@@ -1,11 +1,10 @@
use std::collections::BTreeMap;
use std::path::Path;
use utils;
use crate::utils;
use handlebars::{Context, Handlebars, Helper, HelperDef, Output, RenderContext, RenderError};
use pulldown_cmark::{html, Event, Parser, Tag};
use serde_json;
use pulldown_cmark::{html, Event, Parser};
// Handlebars helper to construct TOC
#[derive(Clone, Copy)]
@@ -16,11 +15,11 @@ pub struct RenderToc {
impl HelperDef for RenderToc {
fn call<'reg: 'rc, 'rc>(
&self,
_h: &Helper,
_: &Handlebars,
ctx: &Context,
rc: &mut RenderContext,
out: &mut Output,
_h: &Helper<'reg, 'rc>,
_r: &'reg Handlebars,
ctx: &'rc Context,
rc: &mut RenderContext<'reg>,
out: &mut dyn Output,
) -> Result<(), RenderError> {
// get value from context data
// rc.get_path() is current json parent path, you should always use it like this
@@ -118,10 +117,7 @@ impl HelperDef for RenderToc {
// filter all events that are not inline code blocks
let parser = Parser::new(name).filter(|event| match *event {
Event::Start(Tag::Code)
| Event::End(Tag::Code)
| Event::InlineHtml(_)
| Event::Text(_) => true,
Event::Code(_) | Event::InlineHtml(_) | Event::Text(_) => true,
_ => false,
});

View File

@@ -1,19 +1,15 @@
extern crate ammonia;
extern crate elasticlunr;
use std::borrow::Cow;
use std::collections::{HashMap, HashSet};
use std::path::Path;
use self::elasticlunr::Index;
use elasticlunr::Index;
use pulldown_cmark::*;
use serde_json;
use book::{Book, BookItem};
use config::Search;
use errors::*;
use theme::searcher;
use utils;
use crate::book::{Book, BookItem};
use crate::config::Search;
use crate::errors::*;
use crate::theme::searcher;
use crate::utils;
/// Creates all files required for search.
pub fn create_files(search_config: &Search, destination: &Path, book: &Book) -> Result<()> {
@@ -35,7 +31,7 @@ pub fn create_files(search_config: &Search, destination: &Path, book: &Book) ->
utils::fs::write_file(
destination,
"searchindex.js",
format!("window.search = {};", index).as_bytes(),
format!("Object.assign(window.search, {});", index).as_bytes(),
)?;
utils::fs::write_file(destination, "searcher.js", searcher::JS)?;
utils::fs::write_file(destination, "mark.min.js", searcher::MARK_JS)?;
@@ -85,16 +81,14 @@ fn render_item(
.chain_err(|| "Could not convert HTML path to str")?;
let anchor_base = utils::fs::normalize_path(filepath);
let mut opts = Options::empty();
opts.insert(OPTION_ENABLE_TABLES);
opts.insert(OPTION_ENABLE_FOOTNOTES);
let p = Parser::new_ext(&chapter.content, opts);
let p = utils::new_cmark_parser(&chapter.content);
let mut in_header = false;
let max_section_depth = search_config.heading_split_level as i32;
let max_section_depth = i32::from(search_config.heading_split_level);
let mut section_id = None;
let mut heading = String::new();
let mut body = String::new();
let mut html_block = String::new();
let mut breadcrumbs = chapter.parent_names.clone();
let mut footnote_numbers = HashMap::new();
@@ -128,6 +122,13 @@ fn render_item(
let number = footnote_numbers.len() + 1;
footnote_numbers.entry(name).or_insert(number);
}
Event::Html(html) => {
html_block.push_str(&html);
}
Event::End(Tag::HtmlBlock) => {
body.push_str(&clean_html(&html_block));
html_block.clear();
}
Event::Start(_) | Event::End(_) | Event::SoftBreak | Event::HardBreak => {
// Insert spaces where HTML output would usually seperate text
// to ensure words don't get merged together
@@ -137,14 +138,14 @@ fn render_item(
body.push(' ');
}
}
Event::Text(text) => {
Event::Text(text) | Event::Code(text) => {
if in_header {
heading.push_str(&text);
} else {
body.push_str(&text);
}
}
Event::Html(html) | Event::InlineHtml(html) => {
Event::InlineHtml(html) => {
body.push_str(&clean_html(&html));
}
Event::FootnoteReference(name) => {
@@ -152,6 +153,7 @@ fn render_item(
let number = footnote_numbers.entry(name).or_insert(len);
body.push_str(&format!(" [{}] ", number));
}
Event::TaskListMarker(_checked) => {}
}
}
@@ -170,7 +172,7 @@ fn render_item(
}
fn write_to_json(index: Index, search_config: &Search, doc_urls: Vec<String>) -> Result<String> {
use self::elasticlunr::config::{SearchBool, SearchOptions, SearchOptionsField};
use elasticlunr::config::{SearchBool, SearchOptions, SearchOptionsField};
use std::collections::BTreeMap;
#[derive(Serialize)]

View File

@@ -15,16 +15,15 @@ pub use self::html_handlebars::HtmlHandlebars;
mod html_handlebars;
use serde_json;
use shlex::Shlex;
use std::fs;
use std::io::{self, Read};
use std::path::PathBuf;
use std::process::{Command, Stdio};
use book::Book;
use config::Config;
use errors::*;
use crate::book::Book;
use crate::config::Config;
use crate::errors::*;
/// An arbitrary `mdbook` backend.
///
@@ -78,7 +77,7 @@ impl RenderContext {
RenderContext {
book,
config,
version: ::MDBOOK_VERSION.to_string(),
version: crate::MDBOOK_VERSION.to_string(),
root: root.into(),
destination: destination.into(),
__non_exhaustive: (),

View File

@@ -69,3 +69,11 @@ Original by Dempfi (https://github.com/dempfi/ayu)
.hljs-strong {
font-weight: bold;
}
.hljs-addition {
color: #91b362;
}
.hljs-deletion {
color: #d96c75;
}

View File

@@ -101,11 +101,15 @@ function playpen_text(playpen) {
}
let text = playpen_text(code_block);
let classes = code_block.querySelector('code').classList;
let has_2018 = classes.contains("edition2018");
let edition = has_2018 ? "2018" : "2015";
var params = {
version: "stable",
optimize: "0",
code: text
code: text,
edition: edition
};
if (text.indexOf("#![feature") !== -1) {
@@ -330,13 +334,11 @@ function playpen_text(playpen) {
stylesheets.ayuHighlight.disabled = false;
stylesheets.tomorrowNight.disabled = true;
stylesheets.highlight.disabled = true;
ace_theme = "ace/theme/tomorrow_night";
} else {
stylesheets.ayuHighlight.disabled = true;
stylesheets.tomorrowNight.disabled = true;
stylesheets.highlight.disabled = false;
ace_theme = "ace/theme/dawn";
}
@@ -435,6 +437,7 @@ function playpen_text(playpen) {
var sidebar = document.getElementById("sidebar");
var sidebarLinks = document.querySelectorAll('#sidebar a');
var sidebarToggleButton = document.getElementById("sidebar-toggle");
var sidebarResizeHandle = document.getElementById("sidebar-resize-handle");
var firstContact = null;
function showSidebar() {
@@ -474,6 +477,23 @@ function playpen_text(playpen) {
}
});
sidebarResizeHandle.addEventListener('mousedown', initResize, false);
function initResize(e) {
window.addEventListener('mousemove', resize, false);
window.addEventListener('mouseup', stopResize, false);
html.classList.add('sidebar-resizing');
}
function resize(e) {
document.documentElement.style.setProperty('--sidebar-width', (e.clientX - sidebar.offsetLeft) + 'px');
}
//on mouseup remove windows functions mousemove & mouseup
function stopResize(e) {
html.classList.remove('sidebar-resizing');
window.removeEventListener('mousemove', resize, false);
window.removeEventListener('mouseup', stopResize, false);
}
document.addEventListener('touchstart', function (e) {
firstContact = {
x: e.touches[0].clientX,
@@ -543,7 +563,7 @@ function playpen_text(playpen) {
elem.className = 'fa fa-copy tooltipped';
}
var clipboardSnippets = new Clipboard('.clip-button', {
var clipboardSnippets = new ClipboardJS('.clip-button', {
text: function (trigger) {
hideTooltip(trigger);
let playpen = trigger.closest("pre");

File diff suppressed because one or more lines are too long

View File

@@ -78,7 +78,7 @@ html:not(.sidebar-visible) #menu-bar:not(:hover).folded > #menu-bar-sticky-conta
display: flex;
margin: 0 5px;
}
.no-js .left-buttons {
.no-js .left-buttons {
display: none;
}
@@ -145,7 +145,7 @@ html:not(.sidebar-visible) #menu-bar:not(:hover).folded > #menu-bar-sticky-conta
display: none;
}
.mobile-nav-chapters {
.mobile-nav-chapters {
font-size: 2.5em;
text-align: center;
text-decoration: none;
@@ -180,7 +180,11 @@ html:not(.sidebar-visible) #menu-bar:not(:hover).folded > #menu-bar-sticky-conta
vertical-align: middle;
padding: 0.1em 0.3em;
border-radius: 3px;
}
:not(pre):not(a) > .hljs {
color: var(--inline-code-color);
overflow-x: initial;
}
a:hover > .hljs {
@@ -301,8 +305,6 @@ ul#searchresults span.teaser em {
top: 0;
bottom: 0;
width: var(--sidebar-width);
overflow-y: auto;
padding: 10px 10px;
font-size: 0.875em;
box-sizing: border-box;
-webkit-overflow-scrolling: touch;
@@ -310,12 +312,39 @@ ul#searchresults span.teaser em {
background-color: var(--sidebar-bg);
color: var(--sidebar-fg);
}
.js .sidebar {
.sidebar-resizing {
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
}
.js:not(.sidebar-resizing) .sidebar {
transition: transform 0.3s; /* Animation: slide away */
}
.sidebar code {
line-height: 2em;
}
.sidebar .sidebar-scrollbox {
overflow-y: auto;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
padding: 10px 10px;
}
.sidebar .sidebar-resize-handle {
position: absolute;
cursor: col-resize;
width: 0;
right: 0;
top: 0;
bottom: 0;
}
.js .sidebar .sidebar-resize-handle {
cursor: col-resize;
width: 5px;
}
.sidebar-hidden .sidebar {
transform: translateX(calc(0px - var(--sidebar-width)));
}
@@ -345,15 +374,17 @@ ul#searchresults span.teaser em {
color: var(--sidebar-non-existant);
}
.chapter li a {
color: var(--sidebar-fg);
display: block;
padding: 0;
text-decoration: none;
color: var(--sidebar-fg);
}
.chapter li a:hover { text-decoration: none }
.chapter li .active,
a:hover {
/* Animate color change */
.chapter li a:hover {
color: var(--sidebar-active);
}
.chapter li .active {
color: var(--sidebar-active);
}
@@ -366,7 +397,7 @@ a:hover {
background-color: var(--sidebar-spacer);
}
@media (-moz-touch-enabled: 1), (pointer: coarse) {
@media (-moz-touch-enabled: 1), (pointer: coarse) {
.chapter li a { padding: 5px 0; }
.spacer { margin: 10px 0; }
}

View File

@@ -30,14 +30,14 @@ h4, h5 { margin-top: 2em; }
.header + .header h3,
.header + .header h4,
.header + .header h5 {
.header + .header h5 {
margin-top: 1em;
}
a.header:target h1:before,
a.header:target h2:before,
a.header:target h3:before,
a.header:target h4:before {
h1 a.header:target::before,
h2 a.header:target::before,
h3 a.header:target::before,
h4 a.header:target::before {
display: inline-block;
content: "»";
margin-left: -30px;
@@ -51,7 +51,7 @@ a.header:target h4:before {
.page-wrapper {
box-sizing: border-box;
}
.js .page-wrapper {
.js:not(.sidebar-resizing) .page-wrapper {
transition: margin-left 0.3s ease, transform 0.3s ease; /* Animation: slide away */
}
@@ -141,4 +141,3 @@ blockquote {
.tooltipped .tooltiptext {
visibility: visible;
}

View File

@@ -67,3 +67,13 @@
.hljs-strong {
font-weight: bold;
}
.hljs-addition {
color: #22863a;
background-color: #f0fff4;
}
.hljs-deletion {
color: #b31d28;
background-color: #ffeef0;
}

File diff suppressed because one or more lines are too long

View File

@@ -4,6 +4,10 @@
<!-- Book generated using mdBook -->
<meta charset="UTF-8">
<title>{{ title }}</title>
{{#if is_print }}
<meta name="robots" content="noindex" />
{{/if}}
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta name="description" content="{{ description }}">
<meta name="viewport" content="width=device-width, initial-scale=1">
@@ -61,7 +65,7 @@
<!-- Set the theme before any content is loaded, prevents flash -->
<script type="text/javascript">
var theme;
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
if (theme === null || theme === undefined) { theme = default_theme; }
document.body.className = theme;
document.querySelector('html').className = theme + ' js';
@@ -80,7 +84,10 @@
</script>
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
{{#toc}}{{/toc}}
<div class="sidebar-scrollbox">
{{#toc}}{{/toc}}
</div>
<div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
</nav>
<div id="page-wrapper" class="page-wrapper">
@@ -110,7 +117,7 @@
{{/if}}
</div>
<h1 class="menu-title">{{ book_title }}</h1>
<h1 class="menu-title">{{ book_title }}</h1>
<div class="right-buttons">
<a href="{{ path_to_root }}print.html" title="Print this book" aria-label="Print this book">

View File

@@ -9,33 +9,29 @@ use std::fs::File;
use std::io::Read;
use std::path::Path;
use errors::*;
use crate::errors::*;
pub static INDEX: &'static [u8] = include_bytes!("index.hbs");
pub static HEADER: &'static [u8] = include_bytes!("header.hbs");
pub static CHROME_CSS: &'static [u8] = include_bytes!("css/chrome.css");
pub static GENERAL_CSS: &'static [u8] = include_bytes!("css/general.css");
pub static PRINT_CSS: &'static [u8] = include_bytes!("css/print.css");
pub static VARIABLES_CSS: &'static [u8] = include_bytes!("css/variables.css");
pub static FAVICON: &'static [u8] = include_bytes!("favicon.png");
pub static JS: &'static [u8] = include_bytes!("book.js");
pub static HIGHLIGHT_JS: &'static [u8] = include_bytes!("highlight.js");
pub static TOMORROW_NIGHT_CSS: &'static [u8] = include_bytes!("tomorrow-night.css");
pub static HIGHLIGHT_CSS: &'static [u8] = include_bytes!("highlight.css");
pub static AYU_HIGHLIGHT_CSS: &'static [u8] = include_bytes!("ayu-highlight.css");
pub static CLIPBOARD_JS: &'static [u8] = include_bytes!("clipboard.min.js");
pub static FONT_AWESOME: &'static [u8] = include_bytes!("FontAwesome/css/font-awesome.min.css");
pub static FONT_AWESOME_EOT: &'static [u8] =
include_bytes!("FontAwesome/fonts/fontawesome-webfont.eot");
pub static FONT_AWESOME_SVG: &'static [u8] =
include_bytes!("FontAwesome/fonts/fontawesome-webfont.svg");
pub static FONT_AWESOME_TTF: &'static [u8] =
include_bytes!("FontAwesome/fonts/fontawesome-webfont.ttf");
pub static FONT_AWESOME_WOFF: &'static [u8] =
include_bytes!("FontAwesome/fonts/fontawesome-webfont.woff");
pub static FONT_AWESOME_WOFF2: &'static [u8] =
pub static INDEX: &[u8] = include_bytes!("index.hbs");
pub static HEADER: &[u8] = include_bytes!("header.hbs");
pub static CHROME_CSS: &[u8] = include_bytes!("css/chrome.css");
pub static GENERAL_CSS: &[u8] = include_bytes!("css/general.css");
pub static PRINT_CSS: &[u8] = include_bytes!("css/print.css");
pub static VARIABLES_CSS: &[u8] = include_bytes!("css/variables.css");
pub static FAVICON: &[u8] = include_bytes!("favicon.png");
pub static JS: &[u8] = include_bytes!("book.js");
pub static HIGHLIGHT_JS: &[u8] = include_bytes!("highlight.js");
pub static TOMORROW_NIGHT_CSS: &[u8] = include_bytes!("tomorrow-night.css");
pub static HIGHLIGHT_CSS: &[u8] = include_bytes!("highlight.css");
pub static AYU_HIGHLIGHT_CSS: &[u8] = include_bytes!("ayu-highlight.css");
pub static CLIPBOARD_JS: &[u8] = include_bytes!("clipboard.min.js");
pub static FONT_AWESOME: &[u8] = include_bytes!("FontAwesome/css/font-awesome.min.css");
pub static FONT_AWESOME_EOT: &[u8] = include_bytes!("FontAwesome/fonts/fontawesome-webfont.eot");
pub static FONT_AWESOME_SVG: &[u8] = include_bytes!("FontAwesome/fonts/fontawesome-webfont.svg");
pub static FONT_AWESOME_TTF: &[u8] = include_bytes!("FontAwesome/fonts/fontawesome-webfont.ttf");
pub static FONT_AWESOME_WOFF: &[u8] = include_bytes!("FontAwesome/fonts/fontawesome-webfont.woff");
pub static FONT_AWESOME_WOFF2: &[u8] =
include_bytes!("FontAwesome/fonts/fontawesome-webfont.woff2");
pub static FONT_AWESOME_OTF: &'static [u8] = include_bytes!("FontAwesome/fonts/FontAwesome.otf");
pub static FONT_AWESOME_OTF: &[u8] = include_bytes!("FontAwesome/fonts/FontAwesome.otf");
/// The `Theme` struct should be used instead of the static variables because
/// the `new()` method will look if the user has a theme directory in their

File diff suppressed because one or more lines are too long

View File

@@ -13,7 +13,7 @@ window.editors = [];
showLineNumbers: false,
showGutter: false,
maxLines: Infinity,
fontSize: "0.875em" // please adjust the font size of the code in general.styl
fontSize: "0.875em" // please adjust the font size of the code in general.css
});
editor.$blockScrolling = Infinity;

View File

@@ -1,7 +1,7 @@
//! Theme dependencies for the playpen editor.
pub static JS: &'static [u8] = include_bytes!("editor.js");
pub static ACE_JS: &'static [u8] = include_bytes!("ace.js");
pub static MODE_RUST_JS: &'static [u8] = include_bytes!("mode-rust.js");
pub static THEME_DAWN_JS: &'static [u8] = include_bytes!("theme-dawn.js");
pub static THEME_TOMORROW_NIGHT_JS: &'static [u8] = include_bytes!("theme-tomorrow_night.js");
pub static JS: &[u8] = include_bytes!("editor.js");
pub static ACE_JS: &[u8] = include_bytes!("ace.js");
pub static MODE_RUST_JS: &[u8] = include_bytes!("mode-rust.js");
pub static THEME_DAWN_JS: &[u8] = include_bytes!("theme-dawn.js");
pub static THEME_TOMORROW_NIGHT_JS: &[u8] = include_bytes!("theme-tomorrow_night.js");

File diff suppressed because one or more lines are too long

View File

@@ -1 +1,7 @@
ace.define("ace/theme/dawn",["require","exports","module","ace/lib/dom"],function(e,t,n){t.isDark=!1,t.cssClass="ace-dawn",t.cssText=".ace-dawn .ace_gutter {background: #ebebeb;color: #333}.ace-dawn .ace_print-margin {width: 1px;background: #e8e8e8}.ace-dawn {background-color: #F9F9F9;color: #080808}.ace-dawn .ace_cursor {color: #000000}.ace-dawn .ace_marker-layer .ace_selection {background: rgba(39, 95, 255, 0.30)}.ace-dawn.ace_multiselect .ace_selection.ace_start {box-shadow: 0 0 3px 0px #F9F9F9;}.ace-dawn .ace_marker-layer .ace_step {background: rgb(255, 255, 0)}.ace-dawn .ace_marker-layer .ace_bracket {margin: -1px 0 0 -1px;border: 1px solid rgba(75, 75, 126, 0.50)}.ace-dawn .ace_marker-layer .ace_active-line {background: rgba(36, 99, 180, 0.12)}.ace-dawn .ace_gutter-active-line {background-color : #dcdcdc}.ace-dawn .ace_marker-layer .ace_selected-word {border: 1px solid rgba(39, 95, 255, 0.30)}.ace-dawn .ace_invisible {color: rgba(75, 75, 126, 0.50)}.ace-dawn .ace_keyword,.ace-dawn .ace_meta {color: #794938}.ace-dawn .ace_constant,.ace-dawn .ace_constant.ace_character,.ace-dawn .ace_constant.ace_character.ace_escape,.ace-dawn .ace_constant.ace_other {color: #811F24}.ace-dawn .ace_invalid.ace_illegal {text-decoration: underline;font-style: italic;color: #F8F8F8;background-color: #B52A1D}.ace-dawn .ace_invalid.ace_deprecated {text-decoration: underline;font-style: italic;color: #B52A1D}.ace-dawn .ace_support {color: #691C97}.ace-dawn .ace_support.ace_constant {color: #B4371F}.ace-dawn .ace_fold {background-color: #794938;border-color: #080808}.ace-dawn .ace_list,.ace-dawn .ace_markup.ace_list,.ace-dawn .ace_support.ace_function {color: #693A17}.ace-dawn .ace_storage {font-style: italic;color: #A71D5D}.ace-dawn .ace_string {color: #0B6125}.ace-dawn .ace_string.ace_regexp {color: #CF5628}.ace-dawn .ace_comment {font-style: italic;color: #5A525F}.ace-dawn .ace_heading,.ace-dawn .ace_markup.ace_heading {color: #19356D}.ace-dawn .ace_variable {color: #234A97}.ace-dawn .ace_indent-guide {background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAEklEQVQImWNgYGBgYLh/5+x/AAizA4hxNNsZAAAAAElFTkSuQmCC) right repeat-y}";var r=e("../lib/dom");r.importCssString(t.cssText,t.cssClass)})
ace.define("ace/theme/dawn",["require","exports","module","ace/lib/dom"],function(e,t,n){t.isDark=!1,t.cssClass="ace-dawn",t.cssText=".ace-dawn .ace_gutter {background: #ebebeb;color: #333}.ace-dawn .ace_print-margin {width: 1px;background: #e8e8e8}.ace-dawn {background-color: #F9F9F9;color: #080808}.ace-dawn .ace_cursor {color: #000000}.ace-dawn .ace_marker-layer .ace_selection {background: rgba(39, 95, 255, 0.30)}.ace-dawn.ace_multiselect .ace_selection.ace_start {box-shadow: 0 0 3px 0px #F9F9F9;}.ace-dawn .ace_marker-layer .ace_step {background: rgb(255, 255, 0)}.ace-dawn .ace_marker-layer .ace_bracket {margin: -1px 0 0 -1px;border: 1px solid rgba(75, 75, 126, 0.50)}.ace-dawn .ace_marker-layer .ace_active-line {background: rgba(36, 99, 180, 0.12)}.ace-dawn .ace_gutter-active-line {background-color : #dcdcdc}.ace-dawn .ace_marker-layer .ace_selected-word {border: 1px solid rgba(39, 95, 255, 0.30)}.ace-dawn .ace_invisible {color: rgba(75, 75, 126, 0.50)}.ace-dawn .ace_keyword,.ace-dawn .ace_meta {color: #794938}.ace-dawn .ace_constant,.ace-dawn .ace_constant.ace_character,.ace-dawn .ace_constant.ace_character.ace_escape,.ace-dawn .ace_constant.ace_other {color: #811F24}.ace-dawn .ace_invalid.ace_illegal {text-decoration: underline;font-style: italic;color: #F8F8F8;background-color: #B52A1D}.ace-dawn .ace_invalid.ace_deprecated {text-decoration: underline;font-style: italic;color: #B52A1D}.ace-dawn .ace_support {color: #691C97}.ace-dawn .ace_support.ace_constant {color: #B4371F}.ace-dawn .ace_fold {background-color: #794938;border-color: #080808}.ace-dawn .ace_list,.ace-dawn .ace_markup.ace_list,.ace-dawn .ace_support.ace_function {color: #693A17}.ace-dawn .ace_storage {font-style: italic;color: #A71D5D}.ace-dawn .ace_string {color: #0B6125}.ace-dawn .ace_string.ace_regexp {color: #CF5628}.ace-dawn .ace_comment {font-style: italic;color: #5A525F}.ace-dawn .ace_heading,.ace-dawn .ace_markup.ace_heading {color: #19356D}.ace-dawn .ace_variable {color: #234A97}.ace-dawn .ace_indent-guide {background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAEklEQVQImWNgYGBgYLh/5+x/AAizA4hxNNsZAAAAAElFTkSuQmCC) right repeat-y}";var r=e("../lib/dom");r.importCssString(t.cssText,t.cssClass)}); (function() {
ace.require(["ace/theme/dawn"], function(m) {
if (typeof module == "object" && typeof exports == "object" && module) {
module.exports = m;
}
});
})();

View File

@@ -1 +1,7 @@
ace.define("ace/theme/tomorrow_night",["require","exports","module","ace/lib/dom"],function(e,t,n){t.isDark=!0,t.cssClass="ace-tomorrow-night",t.cssText=".ace-tomorrow-night .ace_gutter {background: #25282c;color: #C5C8C6}.ace-tomorrow-night .ace_print-margin {width: 1px;background: #25282c}.ace-tomorrow-night {background-color: #1D1F21;color: #C5C8C6}.ace-tomorrow-night .ace_cursor {color: #AEAFAD}.ace-tomorrow-night .ace_marker-layer .ace_selection {background: #373B41}.ace-tomorrow-night.ace_multiselect .ace_selection.ace_start {box-shadow: 0 0 3px 0px #1D1F21;}.ace-tomorrow-night .ace_marker-layer .ace_step {background: rgb(102, 82, 0)}.ace-tomorrow-night .ace_marker-layer .ace_bracket {margin: -1px 0 0 -1px;border: 1px solid #4B4E55}.ace-tomorrow-night .ace_marker-layer .ace_active-line {background: #282A2E}.ace-tomorrow-night .ace_gutter-active-line {background-color: #282A2E}.ace-tomorrow-night .ace_marker-layer .ace_selected-word {border: 1px solid #373B41}.ace-tomorrow-night .ace_invisible {color: #4B4E55}.ace-tomorrow-night .ace_keyword,.ace-tomorrow-night .ace_meta,.ace-tomorrow-night .ace_storage,.ace-tomorrow-night .ace_storage.ace_type,.ace-tomorrow-night .ace_support.ace_type {color: #B294BB}.ace-tomorrow-night .ace_keyword.ace_operator {color: #8ABEB7}.ace-tomorrow-night .ace_constant.ace_character,.ace-tomorrow-night .ace_constant.ace_language,.ace-tomorrow-night .ace_constant.ace_numeric,.ace-tomorrow-night .ace_keyword.ace_other.ace_unit,.ace-tomorrow-night .ace_support.ace_constant,.ace-tomorrow-night .ace_variable.ace_parameter {color: #DE935F}.ace-tomorrow-night .ace_constant.ace_other {color: #CED1CF}.ace-tomorrow-night .ace_invalid {color: #CED2CF;background-color: #DF5F5F}.ace-tomorrow-night .ace_invalid.ace_deprecated {color: #CED2CF;background-color: #B798BF}.ace-tomorrow-night .ace_fold {background-color: #81A2BE;border-color: #C5C8C6}.ace-tomorrow-night .ace_entity.ace_name.ace_function,.ace-tomorrow-night .ace_support.ace_function,.ace-tomorrow-night .ace_variable {color: #81A2BE}.ace-tomorrow-night .ace_support.ace_class,.ace-tomorrow-night .ace_support.ace_type {color: #F0C674}.ace-tomorrow-night .ace_heading,.ace-tomorrow-night .ace_markup.ace_heading,.ace-tomorrow-night .ace_string {color: #B5BD68}.ace-tomorrow-night .ace_entity.ace_name.ace_tag,.ace-tomorrow-night .ace_entity.ace_other.ace_attribute-name,.ace-tomorrow-night .ace_meta.ace_tag,.ace-tomorrow-night .ace_string.ace_regexp,.ace-tomorrow-night .ace_variable {color: #CC6666}.ace-tomorrow-night .ace_comment {color: #969896}.ace-tomorrow-night .ace_indent-guide {background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAEklEQVQImWNgYGBgYHB3d/8PAAOIAdULw8qMAAAAAElFTkSuQmCC) right repeat-y}";var r=e("../lib/dom");r.importCssString(t.cssText,t.cssClass)})
ace.define("ace/theme/tomorrow_night",["require","exports","module","ace/lib/dom"],function(e,t,n){t.isDark=!0,t.cssClass="ace-tomorrow-night",t.cssText=".ace-tomorrow-night .ace_gutter {background: #25282c;color: #C5C8C6}.ace-tomorrow-night .ace_print-margin {width: 1px;background: #25282c}.ace-tomorrow-night {background-color: #1D1F21;color: #C5C8C6}.ace-tomorrow-night .ace_cursor {color: #AEAFAD}.ace-tomorrow-night .ace_marker-layer .ace_selection {background: #373B41}.ace-tomorrow-night.ace_multiselect .ace_selection.ace_start {box-shadow: 0 0 3px 0px #1D1F21;}.ace-tomorrow-night .ace_marker-layer .ace_step {background: rgb(102, 82, 0)}.ace-tomorrow-night .ace_marker-layer .ace_bracket {margin: -1px 0 0 -1px;border: 1px solid #4B4E55}.ace-tomorrow-night .ace_marker-layer .ace_active-line {background: #282A2E}.ace-tomorrow-night .ace_gutter-active-line {background-color: #282A2E}.ace-tomorrow-night .ace_marker-layer .ace_selected-word {border: 1px solid #373B41}.ace-tomorrow-night .ace_invisible {color: #4B4E55}.ace-tomorrow-night .ace_keyword,.ace-tomorrow-night .ace_meta,.ace-tomorrow-night .ace_storage,.ace-tomorrow-night .ace_storage.ace_type,.ace-tomorrow-night .ace_support.ace_type {color: #B294BB}.ace-tomorrow-night .ace_keyword.ace_operator {color: #8ABEB7}.ace-tomorrow-night .ace_constant.ace_character,.ace-tomorrow-night .ace_constant.ace_language,.ace-tomorrow-night .ace_constant.ace_numeric,.ace-tomorrow-night .ace_keyword.ace_other.ace_unit,.ace-tomorrow-night .ace_support.ace_constant,.ace-tomorrow-night .ace_variable.ace_parameter {color: #DE935F}.ace-tomorrow-night .ace_constant.ace_other {color: #CED1CF}.ace-tomorrow-night .ace_invalid {color: #CED2CF;background-color: #DF5F5F}.ace-tomorrow-night .ace_invalid.ace_deprecated {color: #CED2CF;background-color: #B798BF}.ace-tomorrow-night .ace_fold {background-color: #81A2BE;border-color: #C5C8C6}.ace-tomorrow-night .ace_entity.ace_name.ace_function,.ace-tomorrow-night .ace_support.ace_function,.ace-tomorrow-night .ace_variable {color: #81A2BE}.ace-tomorrow-night .ace_support.ace_class,.ace-tomorrow-night .ace_support.ace_type {color: #F0C674}.ace-tomorrow-night .ace_heading,.ace-tomorrow-night .ace_markup.ace_heading,.ace-tomorrow-night .ace_string {color: #B5BD68}.ace-tomorrow-night .ace_entity.ace_name.ace_tag,.ace-tomorrow-night .ace_entity.ace_other.ace_attribute-name,.ace-tomorrow-night .ace_meta.ace_tag,.ace-tomorrow-night .ace_string.ace_regexp,.ace-tomorrow-night .ace_variable {color: #CC6666}.ace-tomorrow-night .ace_comment {color: #969896}.ace-tomorrow-night .ace_indent-guide {background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAEklEQVQImWNgYGBgYHB3d/8PAAOIAdULw8qMAAAAAElFTkSuQmCC) right repeat-y}";var r=e("../lib/dom");r.importCssString(t.cssText,t.cssClass)}); (function() {
ace.require(["ace/theme/tomorrow_night"], function(m) {
if (typeof module == "object" && typeof exports == "object" && module) {
module.exports = m;
}
});
})();

View File

@@ -1,6 +1,6 @@
//! Theme dependencies for in-browser search. Not included in mdbook when
//! the "search" cargo feature is disabled.
pub static JS: &'static [u8] = include_bytes!("searcher.js");
pub static MARK_JS: &'static [u8] = include_bytes!("mark.min.js");
pub static ELASTICLUNR_JS: &'static [u8] = include_bytes!("elasticlunr.min.js");
pub static JS: &[u8] = include_bytes!("searcher.js");
pub static MARK_JS: &[u8] = include_bytes!("mark.min.js");
pub static ELASTICLUNR_JS: &[u8] = include_bytes!("elasticlunr.min.js");

View File

@@ -94,3 +94,11 @@
.xml .hljs-cdata {
opacity: 0.5;
}
.hljs-addition {
color: #718c00;
}
.hljs-deletion {
color: #c82829;
}

View File

@@ -1,4 +1,5 @@
use errors::*;
use crate::errors::*;
use std::convert::Into;
use std::fs::{self, File};
use std::io::{Read, Write};
use std::path::{Component, Path, PathBuf};
@@ -28,7 +29,7 @@ pub fn normalize_path(path: &str) -> String {
pub fn write_file<P: AsRef<Path>>(build_dir: &Path, filename: P, content: &[u8]) -> Result<()> {
let path = build_dir.join(filename);
create_file(&path)?.write_all(content).map_err(|e| e.into())
create_file(&path)?.write_all(content).map_err(Into::into)
}
/// Takes a path and returns a path containing just enough `../` to point to
@@ -38,8 +39,6 @@ pub fn write_file<P: AsRef<Path>>(build_dir: &Path, filename: P, content: &[u8])
/// directory from where the path starts.
///
/// ```rust
/// # extern crate mdbook;
/// #
/// # use std::path::Path;
/// # use mdbook::utils::fs::path_to_root;
/// #
@@ -85,7 +84,7 @@ pub fn create_file(path: &Path) -> Result<File> {
fs::create_dir_all(p)?;
}
File::create(path).map_err(|e| e.into())
File::create(path).map_err(Into::into)
}
/// Removes all the content of a directory but not the directory itself
@@ -187,8 +186,6 @@ pub fn copy_files_except_ext(
#[cfg(test)]
mod tests {
extern crate tempfile;
use super::copy_files_except_ext;
use std::fs;
@@ -196,43 +193,44 @@ mod tests {
fn copy_files_except_ext_test() {
let tmp = match tempfile::TempDir::new() {
Ok(t) => t,
Err(_) => panic!("Could not create a temp dir"),
Err(e) => panic!("Could not create a temp dir: {}", e),
};
// Create a couple of files
if let Err(_) = fs::File::create(&tmp.path().join("file.txt")) {
panic!("Could not create file.txt")
if let Err(err) = fs::File::create(&tmp.path().join("file.txt")) {
panic!("Could not create file.txt: {}", err);
}
if let Err(_) = fs::File::create(&tmp.path().join("file.md")) {
panic!("Could not create file.md")
if let Err(err) = fs::File::create(&tmp.path().join("file.md")) {
panic!("Could not create file.md: {}", err);
}
if let Err(_) = fs::File::create(&tmp.path().join("file.png")) {
panic!("Could not create file.png")
if let Err(err) = fs::File::create(&tmp.path().join("file.png")) {
panic!("Could not create file.png: {}", err);
}
if let Err(_) = fs::create_dir(&tmp.path().join("sub_dir")) {
panic!("Could not create sub_dir")
if let Err(err) = fs::create_dir(&tmp.path().join("sub_dir")) {
panic!("Could not create sub_dir: {}", err);
}
if let Err(_) = fs::File::create(&tmp.path().join("sub_dir/file.png")) {
panic!("Could not create sub_dir/file.png")
if let Err(err) = fs::File::create(&tmp.path().join("sub_dir/file.png")) {
panic!("Could not create sub_dir/file.png: {}", err);
}
if let Err(_) = fs::create_dir(&tmp.path().join("sub_dir_exists")) {
panic!("Could not create sub_dir_exists")
if let Err(err) = fs::create_dir(&tmp.path().join("sub_dir_exists")) {
panic!("Could not create sub_dir_exists: {}", err);
}
if let Err(_) = fs::File::create(&tmp.path().join("sub_dir_exists/file.txt")) {
panic!("Could not create sub_dir_exists/file.txt")
if let Err(err) = fs::File::create(&tmp.path().join("sub_dir_exists/file.txt")) {
panic!("Could not create sub_dir_exists/file.txt: {}", err);
}
// Create output dir
if let Err(_) = fs::create_dir(&tmp.path().join("output")) {
panic!("Could not create output")
if let Err(err) = fs::create_dir(&tmp.path().join("output")) {
panic!("Could not create output: {}", err);
}
if let Err(_) = fs::create_dir(&tmp.path().join("output/sub_dir_exists")) {
panic!("Could not create output/sub_dir_exists")
if let Err(err) = fs::create_dir(&tmp.path().join("output/sub_dir_exists")) {
panic!("Could not create output/sub_dir_exists: {}", err);
}
match copy_files_except_ext(&tmp.path(), &tmp.path().join("output"), true, &["md"]) {
Err(e) => panic!("Error while executing the function:\n{:?}", e),
Ok(_) => {}
if let Err(e) =
copy_files_except_ext(&tmp.path(), &tmp.path().join("output"), true, &["md"])
{
panic!("Error while executing the function:\n{:?}", e);
}
// Check if the correct files where created

View File

@@ -2,19 +2,17 @@
pub mod fs;
mod string;
use errors::Error;
use crate::errors::Error;
use regex::Regex;
use pulldown_cmark::{
html, Event, Options, Parser, Tag, OPTION_ENABLE_FOOTNOTES, OPTION_ENABLE_TABLES,
};
use pulldown_cmark::{html, CowStr, Event, Options, Parser, Tag};
use std::borrow::Cow;
pub use self::string::{take_lines, RangeArgument};
/// Replaces multiple consecutive whitespace characters with a single space character.
pub fn collapse_whitespace<'a>(text: &'a str) -> Cow<'a, str> {
pub fn collapse_whitespace(text: &str) -> Cow<'_, str> {
lazy_static! {
static ref RE: Regex = Regex::new(r"\s\s+").unwrap();
}
@@ -34,7 +32,8 @@ pub fn normalize_id(content: &str) -> String {
} else {
None
}
}).collect::<String>()
})
.collect::<String>()
}
/// Generate an ID for use with anchors which is derived from a "normalised"
@@ -61,38 +60,47 @@ pub fn id_from_content(content: &str) -> String {
}
// Remove spaces and hashes indicating a header
let trimmed = content.trim().trim_left_matches('#').trim();
let trimmed = content.trim().trim_start_matches('#').trim();
normalize_id(trimmed)
}
fn adjust_links<'a>(event: Event<'a>, with_base: &str) -> Event<'a> {
lazy_static! {
static ref HTTP_LINK: Regex = Regex::new("^https?://").unwrap();
static ref SCHEME_LINK: Regex = Regex::new(r"^[a-z][a-z0-9+.-]*:").unwrap();
static ref MD_LINK: Regex = Regex::new(r"(?P<link>.*)\.md(?P<anchor>#.*)?").unwrap();
}
match event {
Event::Start(Tag::Link(dest, title)) => {
if !HTTP_LINK.is_match(&dest) {
let dest = if !with_base.is_empty() {
format!("{}/{}", with_base, dest)
} else {
dest.clone().into_owned()
};
if let Some(caps) = MD_LINK.captures(&dest) {
let mut html_link = [&caps["link"], ".html"].concat();
if let Some(anchor) = caps.name("anchor") {
html_link.push_str(anchor.as_str());
}
return Event::Start(Tag::Link(Cow::from(html_link), title));
}
fn fix<'a>(dest: CowStr<'a>, base: &str) -> CowStr<'a> {
// Don't modify links with schemes like `https`.
if !SCHEME_LINK.is_match(&dest) {
// This is a relative link, adjust it as necessary.
let mut fixed_link = String::new();
if !base.is_empty() {
fixed_link.push_str(base);
fixed_link.push_str("/");
}
Event::Start(Tag::Link(dest, title))
if let Some(caps) = MD_LINK.captures(&dest) {
fixed_link.push_str(&caps["link"]);
fixed_link.push_str(".html");
if let Some(anchor) = caps.name("anchor") {
fixed_link.push_str(anchor.as_str());
}
} else {
fixed_link.push_str(&dest);
};
return CowStr::from(fixed_link);
}
dest
}
match event {
Event::Start(Tag::Link(link_type, dest, title)) => {
Event::Start(Tag::Link(link_type, fix(dest, with_base), title))
}
Event::Start(Tag::Image(link_type, dest, title)) => {
Event::Start(Tag::Image(link_type, fix(dest, with_base), title))
}
_ => event,
}
@@ -103,14 +111,18 @@ pub fn render_markdown(text: &str, curly_quotes: bool) -> String {
render_markdown_with_base(text, curly_quotes, "")
}
pub fn new_cmark_parser(text: &str) -> Parser<'_> {
let mut opts = Options::empty();
opts.insert(Options::ENABLE_TABLES);
opts.insert(Options::ENABLE_FOOTNOTES);
opts.insert(Options::ENABLE_STRIKETHROUGH);
opts.insert(Options::ENABLE_TASKLISTS);
Parser::new_ext(text, opts)
}
pub fn render_markdown_with_base(text: &str, curly_quotes: bool, base: &str) -> String {
let mut s = String::with_capacity(text.len() * 3 / 2);
let mut opts = Options::empty();
opts.insert(OPTION_ENABLE_TABLES);
opts.insert(OPTION_ENABLE_FOOTNOTES);
let p = Parser::new_ext(text, opts);
let p = new_cmark_parser(text);
let mut converter = EventQuoteConverter::new(curly_quotes);
let events = p
.map(clean_codeblock_headers)
@@ -140,28 +152,28 @@ impl EventQuoteConverter {
}
match event {
Event::Start(Tag::CodeBlock(_)) | Event::Start(Tag::Code) => {
Event::Start(Tag::CodeBlock(_)) => {
self.convert_text = false;
event
}
Event::End(Tag::CodeBlock(_)) | Event::End(Tag::Code) => {
Event::End(Tag::CodeBlock(_)) => {
self.convert_text = true;
event
}
Event::Text(ref text) if self.convert_text => {
Event::Text(Cow::from(convert_quotes_to_curly(text)))
Event::Text(CowStr::from(convert_quotes_to_curly(text)))
}
_ => event,
}
}
}
fn clean_codeblock_headers(event: Event) -> Event {
fn clean_codeblock_headers(event: Event<'_>) -> Event<'_> {
match event {
Event::Start(Tag::CodeBlock(ref info)) => {
let info: String = info.chars().filter(|ch| !ch.is_whitespace()).collect();
Event::Start(Tag::CodeBlock(Cow::from(info)))
Event::Start(Tag::CodeBlock(CowStr::from(info)))
}
_ => event,
}
@@ -195,7 +207,8 @@ fn convert_quotes_to_curly(original_text: &str) -> String {
preceded_by_whitespace = original_char.is_whitespace();
converted_char
}).collect()
})
.collect()
}
/// Prints a "backtrace" of some `Error`.

View File

@@ -1,7 +1,4 @@
//! Integration tests to make sure alternate backends work.
extern crate mdbook;
extern crate tempfile;
//! Integration tests to make sure alternative backends work.
use mdbook::config::Config;
use mdbook::MDBook;

View File

@@ -1,8 +1,6 @@
extern crate mdbook;
mod dummy_book;
use dummy_book::DummyBook;
use crate::dummy_book::DummyBook;
use mdbook::book::Book;
use mdbook::config::Config;
use mdbook::errors::*;
@@ -52,7 +50,7 @@ fn mdbook_runs_preprocessors() {
let cfg = Config::default();
let mut book = MDBook::load_with_config(temp.path(), cfg).unwrap();
book.with_preprecessor(Spy(Arc::clone(&spy)));
book.with_preprocessor(Spy(Arc::clone(&spy)));
book.build().unwrap();
let inner = spy.lock().unwrap();

View File

@@ -1,8 +1,6 @@
extern crate mdbook;
mod dummy_book;
use dummy_book::DummyBook;
use crate::dummy_book::DummyBook;
use mdbook::preprocess::{CmdPreprocessor, Preprocessor};
use mdbook::MDBook;
@@ -36,7 +34,7 @@ fn ask_the_preprocessor_to_blow_up() {
let dummy_book = DummyBook::new();
let temp = dummy_book.build().unwrap();
let mut md = MDBook::load(temp.path()).unwrap();
md.with_preprecessor(example());
md.with_preprocessor(example());
md.config
.set("preprocessor.nop-preprocessor.blow-up", true)
@@ -52,7 +50,7 @@ fn process_the_dummy_book() {
let dummy_book = DummyBook::new();
let temp = dummy_book.build().unwrap();
let mut md = MDBook::load(temp.path()).unwrap();
md.with_preprecessor(example());
md.with_preprocessor(example());
md.build().unwrap();
}

View File

@@ -3,9 +3,6 @@
// Not all features are used in all test crates, so...
#![allow(dead_code, unused_variables, unused_imports, unused_extern_crates)]
extern crate mdbook;
extern crate tempfile;
extern crate walkdir;
use mdbook::errors::*;
use mdbook::utils::fs::file_to_string;
@@ -13,11 +10,9 @@ use std::fs::{self, File};
use std::io::{Read, Write};
use std::path::Path;
// The funny `self::` here is because we've got an `extern crate ...` and are
// in a submodule
use self::mdbook::MDBook;
use self::tempfile::{Builder as TempFileBuilder, TempDir};
use self::walkdir::WalkDir;
use mdbook::MDBook;
use tempfile::{Builder as TempFileBuilder, TempDir};
use walkdir::WalkDir;
/// Create a dummy book in a temporary directory, using the contents of
/// `SUMMARY_MD` as a guide.
@@ -58,8 +53,11 @@ impl DummyBook {
})?;
let sub_pattern = if self.passing_test { "true" } else { "false" };
let file_containing_test = temp.path().join("src/first/nested.md");
replace_pattern_in_file(&file_containing_test, "$TEST_STATUS", sub_pattern)?;
let files_containing_tests = ["src/first/nested.md", "src/first/nested-test.rs"];
for file in &files_containing_tests {
let path_containing_tests = temp.path().join(file);
replace_pattern_in_file(&path_containing_tests, "$TEST_STATUS", sub_pattern)?;
}
Ok(temp)
}

View File

@@ -7,6 +7,7 @@
- [Nested Chapter](first/nested.md)
- [Includes](first/includes.md)
- [Recursive](first/recursive.md)
- [Markdown](first/markdown.md)
- [Second Chapter](second.md)
- [Nested Chapter](second/nested.md)

View File

@@ -0,0 +1,29 @@
# Markdown tests
Tests for some markdown output.
## Tables
| foo | bar |
| --- | --- |
| baz | bim |
## Footnotes
Footnote example[^1], or with a word[^word].
[^1]: This is a footnote.
[^word]: A longer footnote.
With multiple lines.
Third line.
## Strikethrough
~~strikethrough example~~
## Tasklisks
- [X] Apples
- [X] Broccoli
- [ ] Carrots

View File

@@ -0,0 +1 @@
assert!($TEST_STATUS);

View File

@@ -7,3 +7,7 @@ assert!($TEST_STATUS);
```
## Some Section
```rust
{{#include nested-test.rs}}
```

View File

@@ -1,4 +1,8 @@
# Testing relative links for the print page
When we link to [the first section](../first/nested.md), it should work on
both the print page and the non-print page.
both the print page and the non-print page.
Link [outside](../../std/foo/bar.html).
![Some image](../images/picture.png)

View File

@@ -1,9 +1,8 @@
extern crate mdbook;
extern crate tempfile;
use mdbook::config::Config;
use mdbook::MDBook;
use std::fs;
use std::fs::File;
use std::io::prelude::*;
use std::path::PathBuf;
use tempfile::Builder as TempFileBuilder;
@@ -27,6 +26,36 @@ fn base_mdbook_init_should_create_default_content() {
}
}
/// Run `mdbook init` in a directory containing a SUMMARY.md should create the
/// files listed in the summary.
#[test]
fn run_mdbook_init_should_create_content_from_summary() {
let created_files = vec!["intro.md", "first.md", "outro.md"];
let temp = TempFileBuilder::new().prefix("mdbook").tempdir().unwrap();
let src_dir = temp.path().join("src");
fs::create_dir_all(src_dir.clone()).unwrap();
static SUMMARY: &str = r#"# Summary
[intro](intro.md)
- [First chapter](first.md)
[outro](outro.md)
"#;
let mut summary = File::create(src_dir.join("SUMMARY.md")).unwrap();
summary.write_all(SUMMARY.as_bytes()).unwrap();
MDBook::init(temp.path()).build().unwrap();
for file in &created_files {
let target = src_dir.join(file);
println!("{}", target.display());
assert!(target.exists(), "{} doesn't exist", file);
}
}
/// Set some custom arguments for where to place the source and destination
/// files, then call `mdbook init`.
#[test]

View File

@@ -1,10 +1,6 @@
//! Some integration tests to make sure the `SUMMARY.md` parser can deal with
//! some real-life examples.
extern crate env_logger;
extern crate error_chain;
extern crate mdbook;
use mdbook::book;
use std::fs::File;
use std::io::Read;

View File

@@ -1,13 +1,9 @@
extern crate mdbook;
#[macro_use]
extern crate pretty_assertions;
extern crate select;
extern crate tempfile;
extern crate walkdir;
mod dummy_book;
use dummy_book::{assert_contains_strings, assert_doesnt_contain_strings, DummyBook};
use crate::dummy_book::{assert_contains_strings, assert_doesnt_contain_strings, DummyBook};
use mdbook::config::Config;
use mdbook::errors::*;
@@ -22,16 +18,21 @@ use std::path::Path;
use tempfile::Builder as TempFileBuilder;
use walkdir::{DirEntry, WalkDir};
const BOOK_ROOT: &'static str = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/dummy_book");
const TOC_TOP_LEVEL: &[&'static str] = &[
const BOOK_ROOT: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/dummy_book");
const TOC_TOP_LEVEL: &[&str] = &[
"1. First Chapter",
"2. Second Chapter",
"Conclusion",
"Dummy Book",
"Introduction",
];
const TOC_SECOND_LEVEL: &[&'static str] =
&["1.1. Nested Chapter", "1.2. Includes", "2.1. Nested Chapter", "1.3. Recursive"];
const TOC_SECOND_LEVEL: &[&str] = &[
"1.1. Nested Chapter",
"1.2. Includes",
"1.3. Recursive",
"1.4. Markdown",
"2.1. Nested Chapter",
];
/// Make sure you can load the dummy book and build it without panicking.
#[test]
@@ -119,7 +120,11 @@ fn check_correct_relative_links_in_print_page() {
assert_contains_strings(
first.join("print.html"),
&[r##"<a href="second/../first/nested.html">the first section</a>,"##],
&[
r##"<a href="second/../first/nested.html">the first section</a>,"##,
r##"<a href="second/../../std/foo/bar.html">outside</a>"##,
r##"<img src="second/../images/picture.png" alt="Some image" />"##,
],
);
}
@@ -183,7 +188,7 @@ fn chapter_files_were_rendered_to_html() {
let chapter_files = WalkDir::new(&src)
.into_iter()
.filter_entry(|entry| entry_ends_with(entry, ".md"))
.filter_map(|entry| entry.ok())
.filter_map(std::result::Result::ok)
.map(|entry| entry.path().to_path_buf())
.filter(|path| path.file_name().and_then(OsStr::to_str) != Some("SUMMARY.md"));
@@ -323,7 +328,10 @@ fn able_to_include_files_in_chapters() {
let includes = temp.path().join("book/first/includes.html");
let summary_strings = &["<h1>Summary</h1>", ">First Chapter</a>"];
let summary_strings = &[
r##"<h1><a class="header" href="#summary" id="summary">Summary</a></h1>"##,
">First Chapter</a>",
];
assert_contains_strings(&includes, summary_strings);
assert_doesnt_contain_strings(&includes, &["{{#include ../SUMMARY.md::}}"]);
@@ -386,7 +394,7 @@ fn by_default_mdbook_use_index_preprocessor_to_convert_readme_to_index() {
"First README",
];
assert_contains_strings(&first_index, &expected_strings);
assert_doesnt_contain_strings(&first_index, &vec!["README.html"]);
assert_doesnt_contain_strings(&first_index, &["README.html"]);
let second_index = temp.path().join("book").join("second").join("index.html");
let unexpected_strings = vec!["Second README"];
@@ -399,7 +407,7 @@ fn theme_dir_overrides_work_correctly() {
let book_dir = book_dir.path();
let theme_dir = book_dir.join("theme");
let mut index = ::mdbook::theme::INDEX.to_vec();
let mut index = mdbook::theme::INDEX.to_vec();
index.extend_from_slice(b"\n<!-- This is a modified index.hbs! -->");
write_file(&theme_dir, "index.hbs", &index).unwrap();
@@ -411,10 +419,55 @@ fn theme_dir_overrides_work_correctly() {
dummy_book::assert_contains_strings(built_index, &["This is a modified index.hbs!"]);
}
#[test]
fn no_index_for_print_html() {
let temp = DummyBook::new().build().unwrap();
let md = MDBook::load(temp.path()).unwrap();
md.build().unwrap();
let print_html = temp.path().join("book/print.html");
assert_contains_strings(print_html, &[r##"noindex"##]);
let index_html = temp.path().join("book/index.html");
assert_doesnt_contain_strings(index_html, &[r##"noindex"##]);
}
#[test]
fn markdown_options() {
let temp = DummyBook::new().build().unwrap();
let md = MDBook::load(temp.path()).unwrap();
md.build().unwrap();
let path = temp.path().join("book/first/markdown.html");
assert_contains_strings(
&path,
&[
"<th>foo</th>",
"<th>bar</th>",
"<td>baz</td>",
"<td>bim</td>",
],
);
assert_contains_strings(&path, &[
r##"<sup class="footnote-reference"><a href="#1">1</a></sup>"##,
r##"<sup class="footnote-reference"><a href="#word">2</a></sup>"##,
r##"<div class="footnote-definition" id="1"><sup class="footnote-definition-label">1</sup>"##,
r##"<div class="footnote-definition" id="word"><sup class="footnote-definition-label">2</sup>"##,
]);
assert_contains_strings(&path, &["<del>strikethrough example</del>"]);
assert_contains_strings(
&path,
&[
"<li><input disabled=\"\" type=\"checkbox\" checked=\"\"/>\nApples",
"<li><input disabled=\"\" type=\"checkbox\" checked=\"\"/>\nBroccoli",
"<li><input disabled=\"\" type=\"checkbox\"/>\nCarrots",
],
);
}
#[cfg(feature = "search")]
mod search {
extern crate serde_json;
use dummy_book::DummyBook;
use crate::dummy_book::DummyBook;
use mdbook::utils::fs::file_to_string;
use mdbook::MDBook;
use std::fs::File;
@@ -423,12 +476,13 @@ mod search {
fn read_book_index(root: &Path) -> serde_json::Value {
let index = root.join("book/searchindex.js");
let index = file_to_string(index).unwrap();
let index = index.trim_left_matches("window.search = ");
let index = index.trim_right_matches(";");
let index = index.trim_start_matches("Object.assign(window.search, ");
let index = index.trim_end_matches(");");
serde_json::from_str(&index).unwrap()
}
#[test]
#[allow(clippy::float_cmp)]
fn book_creates_reasonable_search_index() {
let temp = DummyBook::new().build().unwrap();
let md = MDBook::load(temp.path()).unwrap();
@@ -457,7 +511,7 @@ mod search {
assert_eq!(docs[&some_section]["body"], "");
assert_eq!(
docs[&summary]["body"],
"Dummy Book Introduction First Chapter Nested Chapter Includes Recursive Second Chapter Nested Chapter Conclusion"
"Dummy Book Introduction First Chapter Nested Chapter Includes Recursive Markdown Second Chapter Nested Chapter Conclusion"
);
assert_eq!(docs[&summary]["breadcrumbs"], "First Chapter » Summary");
assert_eq!(docs[&conclusion]["body"], "I put &lt;HTML&gt; in here!");

File diff suppressed because it is too large Load Diff

View File

@@ -1,8 +1,6 @@
extern crate mdbook;
mod dummy_book;
use dummy_book::DummyBook;
use crate::dummy_book::DummyBook;
use mdbook::MDBook;