Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invalid output while include code using {{ #include <path> }} #2521

Open
BiswajitThakur opened this issue Jan 9, 2025 · 0 comments
Open
Labels
C-bug Category: A bug, incorrect or unintended behavior

Comments

@BiswajitThakur
Copy link

BiswajitThakur commented Jan 9, 2025

Problem

when i include code using {{ #include <path> }}
it does't produce valid output.Image

Steps

  1. mkdir dsa
  2. cd dsa
  3. mdbook init
  4. book.toml
[book]
authors = ["BiswajitThakur"]
language = "en"
multilingual = false
src = "src"
title = "DSA Rust"
  1. src/SUMMARY.md
# Summary

- [Chapter 1](./chapter_1.md)
  1. src/chapter_1.md
# Chapter 1

- This is demo
  ```rust
  {{ #include ./../code/linear_search.rs }}
  ```
- Hello World
  1. code/linear_search.rs
pub fn linear_search<T: PartialEq>(arr: &[T], value: &T) -> Option<usize> {
    let mut i = 0;
    while i < arr.len() {
        if &arr[i] == value {
            return Some(i);
        }
        i += 1;
    }
    None
}

#[test]
fn test_linear_search() {
    let arr = [1, 3, 5, 7, 9, 11, 15];
    assert_eq!(linear_search(&arr, &1), Some(0));
    assert_eq!(linear_search(&arr, &3), Some(1));
    assert_eq!(linear_search(&arr, &5), Some(2));
    assert_eq!(linear_search(&arr, &11), Some(5));
    assert_eq!(linear_search(&arr, &15), Some(6));
    assert_eq!(linear_search(&arr, &0), None);
    assert_eq!(linear_search(&arr, &-1), None);
    assert_eq!(linear_search(&arr, &-3), None);

    let arr1 = [1.5, 77.8, -5.3, 1.3, -9.0, 2.5, 5.3];
    assert_eq!(linear_search(&arr1, &1.5), Some(0));
    assert_eq!(linear_search(&arr1, &-5.3), Some(2));
    assert_eq!(linear_search(&arr1, &2.5), Some(5));
    assert_eq!(linear_search(&arr1, &-9.0), Some(4));
    assert_eq!(linear_search(&arr1, &0.0), None);
    assert_eq!(linear_search(&arr1, &1.4), None);
}

Possible Solution(s)

  • It generate valid output when i include like this
<no space>```rust
<no space>{{ #include ./../code/linear_search.rs }}
<no space>```
  • In generate invalid output when i include like this
<2 space>```rust
<2 space>{{ #include ./../code/linear_search.rs }}
<2 space>```

Notes

No response

Version

$ mdbook --version
mdbook v0.4.43
@BiswajitThakur BiswajitThakur added the C-bug Category: A bug, incorrect or unintended behavior label Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: A bug, incorrect or unintended behavior
Projects
None yet
Development

No branches or pull requests

1 participant