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

Support markdown in C++ doc comments. #800

Closed
emilio opened this issue Jul 8, 2017 · 4 comments
Closed

Support markdown in C++ doc comments. #800

emilio opened this issue Jul 8, 2017 · 4 comments
Labels

Comments

@emilio
Copy link
Contributor

emilio commented Jul 8, 2017

Followup from #426, and #791.

Right now if you are generating bindings to a C/C++ library that happens to use markdown blocks in its comments, will make rustdoc complain (because the comment probably isn't valid rust).

Right now the workaround is avoiding generating comments, but that's not ideal.

Testcase:

/**
 * Example usage:
 *
 * ```
 * struct Foo* my_foo = make_foo();
 * foo->random_member++;
 * ```
 */
struct Foo {
  int random_member;
};

Options I can think off-hand:

  • Make the generated comments non-doc comments.
  • Try to preprocess comments in the same way rustdoc does (presumably just looking at three backticks at the beginning of the line?) and annotate them (for markdown at least this would work).

Any other ideas @jethrogb?

@jethrogb
Copy link
Contributor

jethrogb commented Jul 8, 2017

I just don't think we should default to doc comments. For me, the only reason to use doc comments would be if rustdoc could do something sane with them. More often than not, that's not going to be the case with comments imported from C. From your comment in the other thread:

This PR also fixes the most common cases where people doesn't use markdown for their C/C++ docs.

Instead, sending the comments through rustdoc will either error or provide terrible-looking output. Why not just use regular comments?

In the future we can have code that detects doxygen or other common documentation styles and convert them to rust-compatible markdown.

Maybe there's a way to tell rustdoc "don't format this entire comment, escape it and include it as HTML text verbatim". That would also be ok I think.

@fitzgen
Copy link
Member

fitzgen commented Jul 10, 2017

I agree that the most practical thing to do is generate regular, non-doc comments.

@willglynn
Copy link

This just broke for me.

bindgen copies C comments into a Rust doc comments. One of the C comments has an indented section, which is another way to write a code block in Markdown. This causes cargo test to fail, because the indented text in the C source file comment isn't a valid test case for the generated Rust bindings.

@pvdrz
Copy link
Contributor

pvdrz commented Nov 22, 2022

now that #2347 landed. This can be solved by implementing ParseCallbacks::process_comments to either wrap the comment in backticks or replace all occurrences of

```c++ 

by

```c++,ignore 

@pvdrz pvdrz closed this as completed Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants