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

CLIENT-SPECIFICATION: fix typo, add a way to escape the placeholder syntax #10730

Merged
merged 4 commits into from
Nov 17, 2023

Conversation

acuteenvy
Copy link
Member

Examples proposed by @mrnossiom in #10148 (comment).
Closes #10125.

@acuteenvy acuteenvy added the clients Issues pertaining to a particular client or the clients as whole. label Sep 17, 2023
@github-actions github-actions bot added the documentation Issues/PRs modifying the documentation. label Sep 17, 2023
### Examples

- `ping {{example.com}}` MUST be rendered as "ping example.com"
- `docker inspect --format '\{\{range.NetworkSettings.Networks\}\}\{\{.IPAddress\}\}\{\{end\}\}' {{container}}` MUST be rendered as "docker inspect --format '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would personally lighten the syntax to only one backslash:
docker inspect --format '\{{range.NetworkSettings.Networks\}}\{{.IPAddress\}}\{{end\}}' {{container}}.

This is maybe easier to parse than what I had proposed, but still not too heavy for reading source pages (even though this isn't done often). The drawback could if we needed to render something like \{{ <...> }}

But since I've seen only 3 occurrences of this problem, maybe this change is not needed. 🤷🏻

Copy link
Member

@SethFalco SethFalco Sep 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I favor a backslash for each curly brace. I think it's much more intuitive to treat things per character, rather than by our special definition attributed to combinations of characters.

In Markdown, \{ already means a literal {. So we should run with it. This will also be more backward compatible. When we don't mean the placeholder syntax, {{ is never found, so even if the client doesn't know to ignore it, it'll inadvertently ignore it anyway.

This will be simpler than giving {{ conditional meaning based on an escape sequence multiple characters away.

If a client finds \{{range.NetworkSettings.Networks\}}, and processes placeholders before delegating to the CommonMark library, it's probably going to mess up unless it knows to check for a backslash. If a client finds \{\{range.NetworkSettings.Networks\}\} without any special handling, it knows it's not a placeholder, and the CommonMark library will just do its magic.

For nested curly braces inside the placeholder syntax:

Syntax Arg (curly braces removed) Rendered
{{uwu}} uwu uwu
{{\{uwu\}}} \{uwu\} {uwu}
{{\{\{uwu\}\}}} \{\{uwu\}\} {{uwu}}

The main difference, here, is that having a single escape sequence affect multiple characters would require special handling from clients, while doing one escape sequence per character is already supported/expected by clients and CommonMark parsers. The benefits assume the client is using a CommonMark library to parse the page.

@kbdharun kbdharun self-requested a review September 17, 2023 19:14
CLIENT-SPECIFICATION.md Outdated Show resolved Hide resolved
@acuteenvy
Copy link
Member Author

I found a big issue with this. Currently, everything inside an example is treated literally, so rendering backslashes in any position is not a problem. But if we want to allow every { and } to be escaped, then what about Windows paths?

For example, how would this be rendered (Windows page for mount)?
mount \\{{computer_name}}\{{share_name}} {{Z:}}

One solution is to only allow double brackets to be escaped (\{\{) and treat everything else literally. But then putting a single pair of curly brackets inside a placeholder is impossible, because {{{...}}} is undefined even by the current specification. Are the literal brackets inside or outside the placeholder? Some clients even render one inside, and one outside, because they use the first braces they encounter as placeholder marks ( i.e. {{{ ... }}} ):

this is the official C client, trying to render {{{something}}}

rendered_triple_brace


No page requires a single pair of curly braces inside a placeholder as of now, but it would be great to cover everything. The PR as it is now would require escaping every brace that is supposed to be literal, but then also every backslash must be escaped, resulting in the need to rewrite all Windows pages like this:

\\{{path\to\file}} => \\\\{{path\\to\\file}}

and to complicate every client's page parser to allow for this, which is not a very good solution at all.

@blueskyson
Copy link
Member

I think \{ and \} are special cases to escape {{ and }} syntax. As for path\to\file for Windows should remain the same for clarity. After all, a client is a tldr parser, not a standard markdown parser.

@sebastiaanspeck
Copy link
Member

Is this one ready to be merged?

@kbdharun
Copy link
Member

kbdharun commented Oct 19, 2023

Is this one ready to be merged?

Nope, Client specification PRs (especially new requirement ones) are usually kept open the longest (in some cases months) to allow maintainers and community members (client authors, etc) to comment and propose additions/removals to the PR.

We can set a tentative merge date for this next month probably on the 17th.

kbdharun and others added 2 commits November 6, 2023 14:41
Co-authored-by: Lena <126529524+acuteenvy@users.noreply.github.com>
@kbdharun
Copy link
Member

@acuteenvy Let me know if the applied changes are fine. I am planning to merge this tomorrow. Will work on some other related PRs for the Client Specification.

Copy link
Member Author

@acuteenvy acuteenvy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's still a problem with Windows paths. If \{\{ means escaping and \{{ should be a literal backslash, we have to make it unambiguous.

CLIENT-SPECIFICATION.md Outdated Show resolved Hide resolved
CLIENT-SPECIFICATION.md Show resolved Hide resolved
Co-authored-by: Lena <126529524+acuteenvy@users.noreply.github.com>
@kbdharun kbdharun merged commit 71a07e7 into tldr-pages:main Nov 17, 2023
4 checks passed
@acuteenvy acuteenvy deleted the client-spec-10125 branch November 17, 2023 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clients Issues pertaining to a particular client or the clients as whole. documentation Issues/PRs modifying the documentation. review needed Prioritized PRs marked for reviews from maintainers.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Curly braces not properly escaped on pages (e.g. docker, playerctl, fakedata)
6 participants