Skip to content

Preserve HTML entities in headers #2122

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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

Conversation

josevalim
Copy link
Member

Closes #2114.
Closes #2120.

@josevalim
Copy link
Member Author

cc @garazdawi

Copy link

github-actions bot commented May 7, 2025

@josevalim
Copy link
Member Author

Btw, I think this is going to have some subtle issues, as we are using two different ways to compute headers (one using regexes and another without), so we may need to look into that before shipping this.

@garazdawi
Copy link
Contributor

Tested it for us and it solves the issue and I haven't found any regressions so far :)

@josevalim
Copy link
Member Author

@garazdawi please check again! I made a big refactoring that unified how we handle link headings, so we only do it once in a single place, using DocAST instead of relying too much on regexes.

Copy link
Contributor

@garazdawi garazdawi left a comment

Choose a reason for hiding this comment

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

Seems to work fine except for the small detail in map_tags.

Comment on lines +306 to +307
def map_tags({tag, attrs, inner, meta}, fun),
do: fun.({tag, attrs, Enum.map(inner, &map_tags(&1, fun)), meta})
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def map_tags({tag, attrs, inner, meta}, fun),
do: fun.({tag, attrs, Enum.map(inner, &map_tags(&1, fun)), meta})
def map_tags({tag, attrs, inner, meta}, fun) when is_list(inner),
do: fun.({tag, attrs, Enum.map(inner, &map_tags(&1, fun)), meta})
def map_tags({tag, attrs, inner, meta}, fun),
do: fun.({tag, attrs, inner, meta})

When edoc is used to generate the doc ast, inner can be a string without being wrapped in a list.

Copy link
Member Author

Choose a reason for hiding this comment

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

I basically wrote all of the traversal functions assuming that the contents is a list. :( Any chance we could normalize edoc in the long term? I will also improve the traversal functions here meanwhile.

@garazdawi
Copy link
Contributor

I basically wrote all of the traversal functions assuming that the contents is a list.

Maybe you could normalize the input in the retriever?

Any chance we could normalize edoc in the long term?

yes, I think that it is a mistake that it is like that today. I'm surprised that our own validators do not catch it...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Header with & in it renders as &
2 participants