1

I am using Markdown Preprocessors to convert this specific tag

{{% notice success %}}**text**{{% /notice %}}

to this HTML tag:

<p class="callout success"\>**text**\</p\>

But inside my "text", I have some URLs that are not resolved by the Markdown converter. For example, this code:

{{% notice tip %}}
For information about the whole Turntable process, go [here](../../turntable).  
For information on how to setup a Sequence, go [here](../../turntable/sequence).
{{% /notice %}}

generates the following HTML page: enter image description here

I tried to catch the block with BlockProcessor but Markdown can't find it. I also tried to change my PreProcessor to a PostProcessor so it renders the success box after resolving URLs, but with no success.

PreProcessor code:

class HugoNoticeTagsPreprocessor(Preprocessor):
    notice_tag_re = re.compile(
        r"{{%\s*notice (?P<notice_type>.*?)\s*%}}(?P<notice_content>(.|\n)*?){{%\s*/notice\s*%}}"
    )
    notice_map = {
        "note": "info",
        "info": "warning",
        "tip": "success",
        "warning": "danger",
    }

    def repl(self, match: re.Match[str]) -> str:
        notice_type = match.group("notice_type") or "note"
        notice_content = match.group("notice_content")
        notice_content = (
            notice_content.lstrip("\n").rstrip("\n").replace("\n", "<br>")
        )
        return f'<p class="callout {self.notice_map[notice_type]}">{notice_content}</p>'

    def run(self, lines: List[str]) -> List[str]:
        content = "\n".join(lines)
        processed = self.notice_tag_re.sub(self.repl, content)
        return processed.split("\n")

0 Answers0