Skip to content

Commit

Permalink
Merge branch 'master' into feature/links_preprocessor
Browse files Browse the repository at this point in the history
  • Loading branch information
blandger committed Apr 18, 2024
2 parents 65f93b2 + c671c2e commit 51e13f1
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 57 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ The following are instructions for updating [highlight.js](https://highlightjs.o
1. Clone the repository at <https://github.com/highlightjs/highlight.js>
1. Check out a tagged release (like `10.1.1`).
1. Run `npm install`
1. Run `node tools/build.js :common apache armasm coffeescript d handlebars haskell http julia nginx nim properties r scala x86asm yaml`
1. Run `node tools/build.js :common apache armasm coffeescript d handlebars haskell http julia nginx nim nix properties r scala x86asm yaml`
1. Compare the language list that it spits out to the one in [`syntax-highlighting.md`](https://github.com/camelid/mdBook/blob/master/guide/src/format/theme/syntax-highlighting.md). If any are missing, add them to the list and rebuild (and update these docs). If any are added to the common set, add them to `syntax-highlighting.md`.
1. Copy `build/highlight.min.js` to mdbook's directory [`highlight.js`](https://github.com/rust-lang/mdBook/blob/master/src/theme/highlight.js).
1. Be sure to check the highlight.js [CHANGES](https://github.com/highlightjs/highlight.js/blob/main/CHANGES.md) for any breaking changes. Breaking changes that would affect users will need to wait until the next major release.
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions guide/src/format/theme/syntax-highlighting.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ your own `highlight.js` file:
- markdown
- nginx
- nim
- nix
- objectivec
- perl
- php
Expand Down
1 change: 1 addition & 0 deletions src/theme/highlight.js

Large diffs are not rendered by default.

71 changes: 19 additions & 52 deletions src/utils/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,12 @@ pub fn create_file(path: &Path) -> Result<File> {

/// Removes all the content of a directory but not the directory itself
pub fn remove_dir_content(dir: &Path) -> Result<()> {
for item in fs::read_dir(dir)? {
if let Ok(item) = item {
let item = item.path();
if item.is_dir() {
fs::remove_dir_all(item)?;
} else {
fs::remove_file(item)?;
}
for item in fs::read_dir(dir)?.flatten() {
let item = item.path();
if item.is_dir() {
fs::remove_dir_all(item)?;
} else {
fs::remove_file(item)?;
}
}
Ok(())
Expand Down Expand Up @@ -108,72 +106,41 @@ pub fn copy_files_except_ext(
}

for entry in fs::read_dir(from)? {
let entry = entry?;
let entry = entry?.path();
let metadata = entry
.path()
.metadata()
.with_context(|| format!("Failed to read {:?}", entry.path()))?;
.with_context(|| format!("Failed to read {entry:?}"))?;

let entry_file_name = entry.file_name().unwrap();
let target_file_path = to.join(entry_file_name);

// If the entry is a dir and the recursive option is enabled, call itself
if metadata.is_dir() && recursive {
if entry.path() == to.to_path_buf() {
if entry == to.as_os_str() {
continue;
}

if let Some(avoid) = avoid_dir {
if entry.path() == *avoid {
if entry == *avoid {
continue;
}
}

// check if output dir already exists
if !to.join(entry.file_name()).exists() {
fs::create_dir(&to.join(entry.file_name()))?;
if !target_file_path.exists() {
fs::create_dir(&target_file_path)?;
}

copy_files_except_ext(
&from.join(entry.file_name()),
&to.join(entry.file_name()),
true,
avoid_dir,
ext_blacklist,
)?;
copy_files_except_ext(&entry, &target_file_path, true, avoid_dir, ext_blacklist)?;
} else if metadata.is_file() {
// Check if it is in the blacklist
if let Some(ext) = entry.path().extension() {
if let Some(ext) = entry.extension() {
if ext_blacklist.contains(&ext.to_str().unwrap()) {
continue;
}
}
debug!(
"creating path for file: {:?}",
&to.join(
entry
.path()
.file_name()
.expect("a file should have a file name...")
)
);

debug!(
"Copying {:?} to {:?}",
entry.path(),
&to.join(
entry
.path()
.file_name()
.expect("a file should have a file name...")
)
);
copy(
entry.path(),
&to.join(
entry
.path()
.file_name()
.expect("a file should have a file name..."),
),
)?;
debug!("Copying {entry:?} to {target_file_path:?}");
copy(&entry, &target_file_path)?;
}
}
Ok(())
Expand Down
1 change: 1 addition & 0 deletions test_book/src/languages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ This Currently contains following languages
- markdown
- nginx
- nim
- nix
- objectivec
- perl
- php
Expand Down
9 changes: 9 additions & 0 deletions test_book/src/languages/highlight.md
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,15 @@ int main(int argc, const char * argv[]) {

```
## nix
```nix
let
world = "World!";
in
"Hello " + world
```

## perl

```perl
Expand Down

0 comments on commit 51e13f1

Please sign in to comment.