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

feat: stylize text inside backticks when appearing in example description #254

Merged
merged 4 commits into from
Oct 4, 2024

Conversation

kyluca
Copy link
Contributor

@kyluca kyluca commented Oct 2, 2024

Closes #253

Hoping I've understood the brief correctly :)

This change will check for the presence of backticks (`) and replace them with the ANSI escape characters for italics (and a matching reset to close the pairs).

This appears to match the desired output from the Rust CLI from the issue.

Example output:
screenshot_from_2024_10_02_16_50_05

Copy link
Member

@owenvoke owenvoke left a comment

Choose a reason for hiding this comment

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

Hi @kyluca, thanks for looking into this. It looks like this seems to reset the styling after the back ticks (it resets from being green). Would we be able to reapply the styles after this? 🤔

@kyluca
Copy link
Contributor Author

kyluca commented Oct 2, 2024

Ah of course, good catch 👍

@kyluca
Copy link
Contributor Author

kyluca commented Oct 2, 2024

Updated to reapply default or user styles, as well as a hardcoded yellow for further emphasis (matching Rust client output).

Default style:
screenshot_from_2024_10_02_23_40_43

Custom style: To show I didn't cheat and use "green" as the reset haha
screenshot_from_2024_10_02_23_41_03

@@ -414,6 +417,11 @@ def colors_of(key: str) -> Tuple[str, str, List[str]]:


def output(page: str, plain: bool = False) -> None:
def emphasise_example(x: str) -> str:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Opted for a def to avoid a lambda exceeding the line length.

if '`' in line:
elements = ['\n', ' ' * LEADING_SPACES_NUM]

for item in EXAMPLE_SPLIT_REGEX.split(line):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Followed the pattern for example commands below, using regex to pull out the substrings using backticks.

Copy link
Member

@owenvoke owenvoke left a comment

Choose a reason for hiding this comment

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

Looks great to me, but I'll leave this for someone with more Python knowledge to merge. 👍🏻

@kyluca
Copy link
Contributor Author

kyluca commented Oct 3, 2024

I noted the builds are failing due to an unrelated error, so have put up a separate PR to fix them first: #256

@kyluca kyluca changed the title Stylize italics in helptext using ANSI escapes feat: Stylize italics in helptext using ANSI escapes Oct 3, 2024
@kyluca kyluca changed the title feat: Stylize italics in helptext using ANSI escapes feat: Stylize text inside backticks when appearing in example description Oct 3, 2024
@kbdharun kbdharun changed the title feat: Stylize text inside backticks when appearing in example description feat: stylize text inside backticks when appearing in example description Oct 4, 2024
@kbdharun kbdharun merged commit 38fe118 into tldr-pages:main Oct 4, 2024
8 checks passed
@kbdharun kbdharun added this to the 3.4.0 milestone Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stylize text inside backticks when appearing in example description
4 participants