From b4c14dd5519f66aba792aa7cbd758a54c05d01e8 Mon Sep 17 00:00:00 2001 From: nathaniel smith Date: Sun, 24 Sep 2017 22:29:40 -0700 Subject: [PATCH] make regex more strict haxx --- tildewiki/compilation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tildewiki/compilation.py b/tildewiki/compilation.py index da10b11..c415cb3 100644 --- a/tildewiki/compilation.py +++ b/tildewiki/compilation.py @@ -8,14 +8,14 @@ from markdown import markdown DOUBLE_NEWLINE_RE = re.compile(r'\n\n', flags=re.MULTILINE|re.DOTALL) HEADER_TITLE_RE = re.compile(r'(.*?)') TITLE_RE = re.compile(r'.*?') -LINK_RE = re.compile(r'\/wiki') +LINK_RE = re.compile(r'href="\/wiki') def relativize_links(content:str, depth:int) -> str: """Given compiled html content, change URLs that start in "/wiki" to be relative instead of absolute. Depth indicates how many pairs of dots we should use to traverse upward.""" dots = os.path.join(*['..' for _ in range(depth)]) - repl = os.path.join(dots, 'wiki') + repl = 'href="{}'.format(os.path.join(dots, 'wiki')) return re.sub(LINK_RE, repl, content) def compile_wiki(source_path: str, dest_path: str) -> None: