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

Lines starting with an object literal are hidden by mdbook #10

Closed
PatchMixolydic opened this issue Sep 6, 2020 · 3 comments
Closed
Labels
book Issues related to the book. bug Something isn't working changelog Issue has been added to the changelog

Comments

@PatchMixolydic
Copy link
Contributor

Lines in a code block starting with a hash (#) are hidden by mdbook, which is generally good for hiding lines that are irrelevant while still allowing doctests/playground runs to build. However, this clashes with Rune object literals, which also start with a hash. This can be seen in the last example of the Pattern Matching chapter.

The example displays as:

fn describe_car(car) {
    match car {
        _ => "Can't tell 😞",
    }
}

fn main() {
    println(describe_car(#{"model": "Ford", "make": 2000}));
    println(describe_car(#{"model": "Honda", "make": 1980}));
    println(describe_car(#{"model": "Volvo", "make": 1910}));
}

with the output

$> cargo run -- scripts/book/pattern_matching/fast_cars.rn
Pretty fast!
Can't tell 😞
What, where did you get that?
== () (5.3533ms)

...which doesn't make very much sense, until you view the source file:

fn describe_car(car) {
    match car {
        #{"make": year, ..} if year < 1950 => "What, where did you get that?",
        #{"model": "Ford", "make": year, ..} if year >= 2000 => "Pretty fast!",
        _ => "Can't tell 😞",
    }
}

fn main() {
    println(describe_car(#{"model": "Ford", "make": 2000}));
    println(describe_car(#{"model": "Honda", "make": 1980}));
    println(describe_car(#{"model": "Volvo", "make": 1910}));
}
@PatchMixolydic PatchMixolydic changed the title Lines starting with an object are hidden by mdbook Lines starting with an object literal are hidden by mdbook Sep 6, 2020
@udoprog udoprog added book Issues related to the book. bug Something isn't working labels Sep 6, 2020
@udoprog
Copy link
Collaborator

udoprog commented Sep 6, 2020

Thanks for spotting that!

I'm... not sure how to fix it. Maybe it's possible to disable by adding a custom syntax? Would be great if someone more familiar with mdbook could help out!

@PatchMixolydic
Copy link
Contributor Author

mdBook itself has a demonstration of the hash-hiding syntax in their book, and they seem to use Bash highlighting to get around this issue. It's not a great fix, but it's at least a workaround.

@udoprog
Copy link
Collaborator

udoprog commented Sep 6, 2020

Thanks for the resources. Using a custom syntax seems to work.

Forked the rust language in highlight.js into the rune branch of rune-rs/rune and added instructions for how its built.

@udoprog udoprog closed this as completed in 7b33b11 Sep 6, 2020
@udoprog udoprog added the changelog Issue has been added to the changelog label Sep 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
book Issues related to the book. bug Something isn't working changelog Issue has been added to the changelog
Projects
None yet
Development

No branches or pull requests

2 participants