Skip to content

Set icon in sections/external links in the navigation #7514

Answered by joapuiib
joapuiib asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for your detailed answer! It is really inspiring!
I've managed to do it with awesome-pages-plugin and the filter idea.

  • First of all, I have written a plugin that creates two filters extract_icon and remove_icon:
from mkdocs.plugins import BasePlugin
import re

# This regex allows to match a icon with no text
ICON_RE = re.compile(r'^:(\S+):(?: ([^\n]+))?$')


def extract_icon(section_title):
    match = ICON_RE.match(section_title)
    if match:
        return match.group(1)
    return None


def remove_icon(section_title):
    match = ICON_RE.match(section_title)
    if match:
        return match.group(2) or ''
    return section_title


class SectionIconsPlugin(BasePlugin):
    d…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
5 replies
@joapuiib
Comment options

Answer selected by kamilkrzyskow
@kamilkrzyskow
Comment options

@joapuiib
Comment options

@joapuiib
Comment options

@joapuiib
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants