Skip to content

Conversation

@ggueret
Copy link

@ggueret ggueret commented Dec 30, 2018

I wanted to use a Font-Awesome icon as permalink for a project. So I defined TOC permalink as follows: <i class="fas fa-link"></i>. Currently, TocTreeprocessor.add_permalink treats permalink content as an etree.Element text, so the html tag will be escaped.

This patch aim to allows both text and html.

Copy link
Member

@waylan waylan left a comment

Choose a reason for hiding this comment

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

Interesting idea. I'm not 100% sure we want to do this, but I can see the usefulness of it. What if we allowed custom classes to be assigned to the link itself instead?

Either way, this needs a test and a comment in the release notes before it can be accepted.

@waylan
Copy link
Member

waylan commented Jan 8, 2019

Interesting change. By accepting a ElementTree object you eliminate the need to parse HTML, which can be problematic if invalid HTML is provided. However, I like this even less from a user's perspective. I still think the proper approach would be to simply add a permalink_class setting which defined a HTML class on the <a> tag for the permalink.

Then you could easily do permalink_class="fas fa-link", which would give you:

'<a class="fas fa-link" href="#header" title="Permanent link">&para;</a>'

I believe that would work fine with Font-Awesome's CSS.

Of course the default value of permalink_class would be headerlink to match the existing behavior.

if self.use_anchors:
self.add_anchor(el, el.attrib["id"])
if self.use_permalinks:
if self.use_permalinks or isinstance(self.use_permalinks, etree.Element):
Copy link
Author

Choose a reason for hiding this comment

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

Needed extra check, because a bool(etree.Element("a")) will return False

@ggueret
Copy link
Author

ggueret commented Jan 10, 2019

Closed because of irrelevant changes, continued in #776.

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.

2 participants