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

attr_list values are included in social card's title, if set for h1 header #7913

Closed
4 tasks done
Andre601 opened this issue Jan 17, 2025 · 3 comments
Closed
4 tasks done
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open

Comments

@Andre601
Copy link
Contributor

Context

No response

Bug description

When using the attr_list extension alongside the Social plugin and then set a attribute for the h1 header (i.e. a custom header ID) does the social plugin include the attribute in the title of the image.

Example (From reproduction):

# Hello world! { #hello }

Lorem ipsum dolor.

Resulting card:
Image

Related links

Reproduction

9.5.49-social-cards-display-issue.zip

Steps to reproduce

  1. Add social to the plugins option
  2. Add attr_list to the markdown_extensions option
  3. Build docs
  4. Check generated image in .ache folder.

Browser

Firefox

Before submitting

@squidfunk
Copy link
Owner

squidfunk commented Jan 18, 2025

Thanks for reporting. So, I've investigated, and it seems that this comes from MkDocs mutating the Page.title in between on_page_markdown and on_page_content, replacing it with Page._title_from_render. First, the Markdown page title is used, which is also used by the social plugin, but later, it returns the rendered title.

We can mitigate the issue on our side by switching to on_page_content, as we now do in 6d1ef25.

IMHO, this is misleading, as the same property has different values depending on the hook used, and must thus be fixed in MkDocs. It tries to do a best effort to return any title, not carrying about the specifics. Since this possibly impacts a lot of plugins, may I kindly ask you to create an upstream issue? Here's a hook with a minimal reproduction:

def on_page_markdown(markdown, page, config, files):
    print("on_page_markdown", page.title)

def on_page_content(html, page, config, files):
    print("on_page_content", page.title)
INFO    -  Cleaning site directory
INFO    -  Building documentation to directory: 9.5.49-social-cards-display-issue/site
on_page_markdown <em>Hello</em> *world!!!* { #hello }
on_page_content Hello world!!!
INFO    -  Documentation built in 0.14 seconds

@squidfunk squidfunk added bug Issue reports a bug resolved Issue is resolved, yet unreleased if open labels Jan 18, 2025
@squidfunk
Copy link
Owner

squidfunk commented Jan 18, 2025

Note that inconsistent title handling is one of the major pain points of MkDocs:

The first issue is the second-most commented issue for MkDocs, but IMHO, it is still unfixed albeit the issue being closed, so I think the maintainers will probably tackle this as part of the next iteration of MkDocs they are currently working on. It might be good for them to know a few other corner cases that break, including this one, so reporting it could be beneficial.

@squidfunk
Copy link
Owner

Released as part of 9.5.50.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open
Projects
None yet
Development

No branches or pull requests

2 participants