Skip to content
New issue

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

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

Already on GitHub? # to your account

Add @@snip-like directive #305

Open
armanbilge opened this issue Jul 14, 2022 · 4 comments
Open

Add @@snip-like directive #305

armanbilge opened this issue Jul 14, 2022 · 4 comments
Milestone

Comments

@armanbilge
Copy link
Member

I'm migrating a project from Paradox to Laika and AFAIK there is no equivalent of this directive. Thanks!

https://developer.lightbend.com/docs/paradox/current/directives/snippets.html

@armanbilge
Copy link
Member Author

https://planet42.github.io/Laika/0.18/07-reference/01-standard-directives.html#inclusions

Inclusions are pretty close. This is a good reminder of the trickyness of this.

Keep in mind that all references in Laika are based on the Virtual Tree Abstraction.

I guess what @@snip would benefit from is setting up the code block and extract the content between the // #id. Or something similar.

@jenshalm
Copy link
Contributor

There are two simple reasons for this not being part of Laika:

  1. It has never been requested before 🙂
  2. It's not possible to get implemented as a standard directive as directives are not effectful, so it cannot be part of laika-core. There is a way how a theme could offer such a feature by combining a directive producing a description of the snippet with a TreeProcessor that does have access to effectful execution, so it could theoretically be part of Helium. However, it would introduce the first directive that only works with Helium which I find a bit confusing and inconsistent.

Given these limitations and the fact demand for it seems to be low I am currently not super-keen to add it.

@armanbilge
Copy link
Member Author

Ah, I hadn't realized its effectfulness is an issue as well. How does the current include directive work around this? I was thinking the sources should just be added to the virtual tree before you can use them in snippets.

Feel free to close or maybe make a discussion. So far I've only encountered one project that would benefit from this.

@jenshalm
Copy link
Contributor

jenshalm commented Jul 14, 2022

I'm personally happy to keep it open in the "backlog" milestone, so we can check whether we either see more demand from users in the future or better ideas how to implement it (although I really feel adding it to Helium is the only inconsistent option).

The @include directive is very trivial instead, ironically. All templates in the input tree are recognized by file suffix and pre-parsed into an AST. The directive just replaces the node with the AST matching the virtual path. This approach is not really feasible for code sources, as it's not very efficient to pre-parse them all for detecting snippet ranges.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants