Skip to content

Default language for code tag #370

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

Open
Songbird0 opened this issue Jul 2, 2017 · 10 comments
Open

Default language for code tag #370

Songbird0 opened this issue Jul 2, 2017 · 10 comments
Labels
A-Highlighting Area: Code colored syntax highlighting A-Tests Area: `mbdook test` related tests C-papercut Category: A small usability bug

Comments

@Songbird0
Copy link

Songbird0 commented Jul 2, 2017

Hi,

Basic code tag (without language name specified) is not supported by markdown interpreter when I put a piece of Rust code.

I tried this code:

(No language name specified in code tag)

|val| val + x

I expected to see this happen: No error thrown by mdbook test.

Instead, this happened: mdbook test throws an error.

Meta

Backtrace:

An error occured:

running 2 tests

test /home/travis/build/Songbird0/FR_RBE/src/chapitre8/closures.md - Les_closures (line 5) ... FAILED

test /home/travis/build/Songbird0/FR_RBE/src/chapitre8/closures.md - Les_closures (line 5) ... FAILED

failures:

---- /home/travis/build/Songbird0/FR_RBE/src/chapitre8/closures.md - Les_closures (line 5) stdout ----

	error[E0425]: cannot find value `x` in this scope

 --> <anon>:2:13

  |

2 | |val| val + x

  |             ^ not found in this scope

error[E0308]: mismatched types

 --> <anon>:2:1

  |

2 | |val| val + x

  | ^^^^^^^^^^^^^ expected (), found closure

  |

  = note: expected type `()`

             found type `[closure@<anon>:2:1: 2:14]`

error: aborting due to previous error(s)

You should "skip" code compilation when language name isn't specified in markdown code tag, maybe ? So:

(Specified language name: rust)

|val| var + x 

Ok !

(Specified language name: nothing, text by default)

|val| var + x

Compilation skipped, not enough information to test code tag content.

See here(my travis backtrace) for more.

Solution

I've added text language name in code tag to skip this test.

|val| val + x

Works properly.

Regards.

@azerupi
Copy link
Contributor

azerupi commented Jul 3, 2017

Thanks for the bug report!
I suppose this is because rustdoc assumes every code block is Rust unless told otherwise.

I'm not very very familiar with the options for rustdoc, but @steveklabnik will certainly be. Is there a conservative mode for rustdoc that onlyc checks codeblocks explicitely marked as Rust?

@steveklabnik
Copy link
Member

Is there a conservative mode for rustdoc that onlyc checks codeblocks explicitely marked as Rust?

There is not, or at least, not one I'm aware of.

@Songbird0
Copy link
Author

Songbird0 commented Jul 3, 2017

Hi,

I suppose this is because rustdoc assumes every code block is Rust unless told otherwise.

There is not, or at least, not one I'm aware of.

Ok, so I'll mark all of my piece of code (which isn't executable Rust code) with the text lang name for now.

@azerupi
Copy link
Contributor

azerupi commented Jul 3, 2017

There is not, or at least, not one I'm aware of.

Actually, now I wonder if I didn't already open an issue on rustdoc for this specific feature some time ago. This feels like déjà-vu.. 😄

@azerupi azerupi added A-Tests Area: `mbdook test` related tests C-papercut Category: A small usability bug labels Jul 29, 2017
@agauniyal
Copy link

Would it be possible to check for rust code explicitly since I'm thinking of using mdbook for other languages as well 😸

@budziq
Copy link
Contributor

budziq commented Sep 10, 2017

@agauniyal could you describe what is your problem exactly?
Currently you can add other language code snippets by specifying the language name in the markdown fenced block

```python
def main():
    print("hello")
```

You'll get syntax highlighting (not all languages are supported but particular one can be added on request).
mdbook test and play button will not work.

@agauniyal
Copy link

agauniyal commented Sep 10, 2017

Oh I misunderstood the issue then 😅. Its okay to use different codeblocks for different languages in single book, right? eg

```python
def main():
    print("hello")
```

```cpp
int main() {
    return 0;
}
```

@budziq
Copy link
Contributor

budziq commented Sep 10, 2017

Its okay to use different codeblocks for different languages in single book, right? eg

Sure! We also support highlighting several markups. You only loose the additional functionality available for rust codeblocks that I've mentioned.

@agauniyal
Copy link

agauniyal commented Sep 10, 2017

And expanding on that, is it possible to add similar play button for other services like - https://wandbox.org/ or embedding godbolt views. Wandbox provides similar play button service but for plethora of other languages throught same api (including rust) and godbolt is lang->asm converter for languages like c/c++, d, rust etc.

@budziq
Copy link
Contributor

budziq commented Sep 10, 2017

And expanding on that, is it possible to add similar play button for other services

Yep. We already have an issue for exactly that problem
https://github.com/azerupi/mdBook/issues/350 but I would not say it is of high priority at the moment.

@ehuss ehuss added the A-Highlighting Area: Code colored syntax highlighting label May 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Highlighting Area: Code colored syntax highlighting A-Tests Area: `mbdook test` related tests C-papercut Category: A small usability bug
Projects
None yet
Development

No branches or pull requests

6 participants