(self, formatter: Formatter, page: Page)
Replace Meson refman tags

        Links of the form [[function]] are automatically replaced
        with valid links to the correct URL. To reference objects / types use the
        [[@object]] syntax.
Replace Meson refman tags
Replace Meson refman tags
def _formatting_page_cb(self, formatter: Formatter, page: Page) -> None:
        ''' Replace Meson refman tags

        Links of the form [[function]] are automatically replaced
        with valid links to the correct URL. To reference objects / types use the
        [[@object]] syntax.
        '''
        link_regex = re.compile(r'\[\[#?@?([ \n\t]*[a-zA-Z0-9_]+[ \n\t]*\.)*[ \n\t]*[a-zA-Z0-9_]+[ \n\t]*\]\]', re.MULTILINE)
        for m in link_regex.finditer(page.formatted_contents):
            i = m.group()
            obj_id: str = i[2:-2]
            obj_id = re.sub(r'[ \n\t]', '', obj_id)  # Remove whitespaces

            # Marked as inside a code block?
            in_code_block = False
            if obj_id.startswith('#'):
                in_code_block = True
                obj_id = obj_id[1:]

            if obj_id not in self._data:
                warn('unknown-refman-link', f'{Path(page.name).name}: Unknown Meson refman link: "{obj_id}"')
                continue

            # Just replaces [[!file.id]] paths with the page file (no fancy HTML)
            if obj_id.startswith('!'):
                page.formatted_contents = page.formatted_contents.replace(i, self._data[obj_id])
                continue

            # Fancy links for functions and methods
            text = obj_id
            if text.startswith('@'):
                text = text[1:]
            else:
                text = text + '()'
            if not in_code_block:
                text = f'<code>{text}</code>'
            link = f'<a href="{self._data[obj_id]}"><ins>{text}</ins></a>'
            page.formatted_contents = page.formatted_contents.replace(i, link)
def _formatting_page_cb ( self , formatter : Formatter , page : Page ) -> None : link_regex = re . compile ( r'\[\[#?@?([ \n\t]*[a-zA-Z0-9_]+[ \n\t]*\.)*[ \n\t]*[a-zA-Z0-9_]+[ \n\t]*\]\]' , re . MULTILINE ) for m in link_regex . finditer ( page . formatted_contents ) : i = m . group ( ) obj_id : str = i [ 2 : - 2 ] obj_id = re . sub ( r'[ \n\t]' , '' , obj_id ) # Remove whitespaces # Marked as inside a code block? in_code_block = False if obj_id . startswith ( '#' ) : in_code_block = True obj_id = obj_id [ 1 : ] if obj_id not in self . _data : warn ( 'unknown-refman-link' , f'{Path(page.name).name}: Unknown Meson refman link: "{obj_id}"' ) continue # Just replaces [[!file.id]] paths with the page file (no fancy HTML) if obj_id . startswith ( '!' ) : page . formatted_contents = page . formatted_contents . replace ( i , self . _data [ obj_id ] ) continue # Fancy links for functions and methods text = obj_id if text . startswith ( '@' ) : text = text [ 1 : ] else : text = text + '()' if not in_code_block : text = f'<code>{text}</code>' link = f'<a href="{self._data[obj_id]}"><ins>{text}</ins></a>' page . formatted_contents = page . formatted_contents . replace ( i , link )