Build link from `wikilink`.
| 58 | |
| 59 | |
| 60 | class WikiLinksInlineProcessor(InlineProcessor): |
| 61 | """ Build link from `wikilink`. """ |
| 62 | |
| 63 | def __init__(self, pattern: str, config: dict[str, Any]): |
| 64 | super().__init__(pattern) |
| 65 | self.config = config |
| 66 | |
| 67 | def handleMatch(self, m: re.Match[str], data: str) -> tuple[etree.Element | str, int, int]: |
| 68 | if m.group(1).strip(): |
| 69 | base_url, end_url, html_class = self._getMeta() |
| 70 | label = m.group(1).strip() |
| 71 | url = self.config['build_url'](label, base_url, end_url) |
| 72 | a = etree.Element('a') |
| 73 | a.text = label |
| 74 | a.set('href', url) |
| 75 | if html_class: |
| 76 | a.set('class', html_class) |
| 77 | else: |
| 78 | a = '' |
| 79 | return a, m.start(0), m.end(0) |
| 80 | |
| 81 | def _getMeta(self) -> tuple[str, str, str]: |
| 82 | """ Return meta data or `config` data. """ |
| 83 | base_url = self.config['base_url'] |
| 84 | end_url = self.config['end_url'] |
| 85 | html_class = self.config['html_class'] |
| 86 | if hasattr(self.md, 'Meta'): |
| 87 | if 'wiki_base_url' in self.md.Meta: |
| 88 | base_url = self.md.Meta['wiki_base_url'][0] |
| 89 | if 'wiki_end_url' in self.md.Meta: |
| 90 | end_url = self.md.Meta['wiki_end_url'][0] |
| 91 | if 'wiki_html_class' in self.md.Meta: |
| 92 | html_class = self.md.Meta['wiki_html_class'][0] |
| 93 | return base_url, end_url, html_class |
| 94 | |
| 95 | |
| 96 | def makeExtension(**kwargs): # pragma: no cover |
no outgoing calls
no test coverage detected
searching dependent graphs…