From e60d56c203e53db09d3f33a6c1f9dcbfb625a7b5 Mon Sep 17 00:00:00 2001 From: Tim Vink Date: Wed, 11 Dec 2019 13:40:48 +0100 Subject: [PATCH] simplify code by using regex to replace tags --- .../plugin.py | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/mkdocs_git_revision_date_localized_plugin/plugin.py b/mkdocs_git_revision_date_localized_plugin/plugin.py index c249c42..0452b8a 100644 --- a/mkdocs_git_revision_date_localized_plugin/plugin.py +++ b/mkdocs_git_revision_date_localized_plugin/plugin.py @@ -1,9 +1,9 @@ +import re from os import environ from mkdocs.config import config_options from mkdocs.plugins import BasePlugin from mkdocs.utils import string_types -from jinja2 import Template from .util import Util from datetime import datetime @@ -64,5 +64,23 @@ def on_page_markdown(self, markdown, page, config, files): print('WARNING - macros plugin must be placed AFTER the git-revision-date-localized plugin. Skipping markdown modifications') return markdown else: - return Template(markdown).render({'git_revision_date_localized': revision_date}) + #print("TEST TEST") + # print() + # print(f"revision_date: {revision_date}") + # revision_date = "2019-21-12" + # markdown = "text with {{ git_revision_date_localized }} here" + + markdown = re.sub(r"\{\{(\s)*git_revision_date_localized(\s)*\}\}", + revision_date, + markdown, + flags=re.IGNORECASE) + + # print(markdown) + + markdown = re.sub(r"\{\{\s*page\.meta\.git_revision_date_localized\s*\}\}", + revision_date, + markdown, + flags=re.IGNORECASE) + + return markdown