dbrgn / tealdeer

A very fast implementation of tldr in Rust.
https://dbrgn.github.io/tealdeer/
Apache License 2.0
4.09k stars 124 forks source link

how to render `{{` and `}}`? #317

Closed hxzhao527 closed 1 year ago

hxzhao527 commented 1 year ago

The input text for a template is UTF-8-encoded text in any format. "Actions"--data evaluations or control structures--are delimited by "{{" and "}}"; all text outside actions is copied to the output unchanged.

docker command like inspect use Go template format that "Actions"--data evaluations or control structures--are delimited by "{{" and "}}".

In the old discuss https://github.com/tldr-pages/tldr/issues/731 , it seems that it is up to client how to deal with {{.

I notice in tealdeer, https://github.com/dbrgn/tealdeer/blob/94d56c01a787f574fc380c5fb9fcced767efccea/src/formatter.rs#L71-L84

{{ jus as a delimiter.

so how to show a command, like this:

`docker ps -q | xargs -n 1 docker inspect --format '{{ .Name }} {{range .NetworkSettings.Networks}} {{.IPAddress}}{{end}}' | sed 's#^/##';`
niklasmohrin commented 1 year ago

Good catch, that is indeed a problem. I think I wouldn't want to implement any particular behavior as long as this isn't manifested in the client specification. As far as I can tell, it currently only says that these {{ markers exist. Your exact problem has come up before though, see this other issue: https://github.com/tldr-pages/tldr/issues/6155#issuecomment-865317156

The way I read the end of the discussion there is that nothing will be done for now - it could be time to talk about this again though. So there isn't much I can tell you other than redirecting you towards tldr-pages/tldr to ask for action there. I personally think that introducing escaping syntax \{ would be the only way to fix this, but there were some concerns about that in the other discussion

dbrgn commented 1 year ago

Thanks @niklasmohrin, I agree, there would need to be a solution in the tldr project / client specification itself.