Skip to content

Easily include a file setting the syntax highlighting and also showing the name of the file #2663

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
szabgab opened this issue Apr 13, 2025 · 4 comments
Labels
C-enhancement Category: Enhancement or feature request

Comments

@szabgab
Copy link
Contributor

szabgab commented Apr 13, 2025

Problem

Right now if I would like to include a source file I need to use something like this: {{#include file.rs}} I also need to wrap it with

```rust
```

I would also like to add the name of the file above the included file
And maybe even make it a link to the file in my github repository.

Proposed Solution

It would be nice to be able to write something like:

{% include file.rs %}

That would be expanded to something like this:

    ```rust
    [**examples/intro/hello/src/main.rs**](https://github.com/szabgab/rust.code-maven.com/blob/main/slides/rust/examples/intro/hello/src/main.rs)
    {{#include examples/intro/hello/src/main.rs }}
    ```

The programming language would be deducted from the file-extension.

It would be nice if mdbook had all kinds of extension like this using the liquid-like format, but for quicker solution it might be a preprocessors. Maybe it could be added to embedify.
What do you think @MR-Addict ?

@szabgab szabgab added the C-enhancement Category: Enhancement or feature request label Apr 13, 2025
@szabgab szabgab changed the title Easily include a file Easily include a file setting the syntax highlighting and also showing the name of the file Apr 13, 2025
@MR-Addict
Copy link

Hi! Thanks for the suggestion — I’d love to help with this, but I’m not sure I fully understand the problem you're trying to solve. Could you clarify what the current workflow looks like for you, and what exactly you’d like embedify to do differently?

From what I gather, it seems you're trying to simplify how you include source files in your markdown, and also automatically generate a filename (optionally as a link) above the code block. Is that correct?

Any extra detail or an example of the input and expected output would be super helpful! 😊

@szabgab
Copy link
Contributor Author

szabgab commented Apr 14, 2025

Sure, here is what I have now with my own site generator:

Source of the page: https://raw.githubusercontent.com/szabgab/rust.code-maven.com/refs/heads/main/pages/hello-world.md it has

{% include file="examples/hello-rust/src/main.rs" %}

Resulting page: https://rust.code-maven.com/hello-world

@MR-Addict
Copy link

Thanks for the clarification! That example helps a lot — I understand what you're going for now.

I'll take a look and see how this could fit into embedify. Once I have something working, I’ll let you know!

@MR-Addict
Copy link

I've just updated embedify to support the {% include file="..." %} macro! You can find the documentation for it here.

From the preprocessor’s perspective, I decided not to add automatic links to the included file. Since raw Markdown works perfectly for that, it's more flexible to let the user add the link manually if needed — that way you're not locked into a specific format.

This update is still in pre-release, as I’ve done some internal refactoring. So please test it well before using it in production, and feel free to report any issues you run into!

Let me know what you think, and if you have any feedback or ideas for further improvements!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement or feature request
Projects
None yet
Development

No branches or pull requests

2 participants