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

Fix: When using inline HTML styles, directly apply rules to anchors #3580

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

dottspina
Copy link

@dottspina dottspina commented Dec 3, 2024

Type of changes

  • Bug fix
  • New feature
  • Documentation / docstrings
  • Tests
  • Other

Checklist

  • I've run the latest black with default args on new code.
  • I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
  • I've added tests for new code.
  • I accept that @willmcgugan may be pedantic in the code review.

Description

When exporting captured output to HTML, using inline CSS styles, linked text is formatted as:

<span style="{rule}"><a href="{link}">text</a></span>

It seems that Web browsers will then render the linked text with the default style for unvisited links (typically blue).

The CSS rules are, however, correctly applied if put directly on the anchor element:

<a style="{rule}" href="{link}">text</a>

Tested with Firefox 128.4 and Google Chrome 131.

Thanks.

[Edit: I can squash the commits if preferred.]

When exporting captured output to HTML, using inline CSS styles,
linked text is formatted as:
       <span style="..."><a href="...">text</a></span>

It seems that Web browsers will then render the linked text
with the default style for unvisited links (typically blue).

The CSS rules are, however, correctly applied if put
directly on the anchor element:
       <a style="..." href="...">text</a>

Tested with Firefox 128.4 and Google Chrome 131.
@dottspina dottspina changed the title when using inline HTML styles, directly apply rules to anchors Fix: When using inline HTML styles, directly apply rules to anchors Dec 3, 2024
dottspina added a commit to dottspina/dtsh that referenced this pull request Dec 9, 2024
When appending a captured command output to an existing HTML file,
we asked the rich library Console.export_html() API to generate
inline CSS styles rather than:
- CSS class definitions in a <style> element
- which the <span>s making the actual output will later point to
  using class identifiers

This was handy: we didn't have to deal with "merging" existing classes
and new HTML elements, both 1-indexed and overlapping.

Unfortunately, the HTML generated by the rich library
will render linked texts (e.g. a compatible string linked
to a YAML binding file) with the Web browser's default style
for unvisited links (typically blue),
instead of the expected style (e.g. the one consistently used
for compatible strings).
This can produce ugly/confusing outputs [1].

We submitted a patch to the upstream rich library project [2].

This commit relies on dtsh.rich.html to decouple DTSh command
output redirection to HTML files from the inline styles generated
by the rich library.
We may keep this approach even if the initial issue is fixed upstream.

[1] #9
[2] Textualize/rich#3580
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.

1 participant