make regex more strict

nathaniel smith 2017-09-24 22:29:40 -07:00
parent 8f45008c7a
commit b4c14dd551
1 changed files with 2 additions and 2 deletions

View File

@ -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'<h([12])>(.*?)</h\1>')
TITLE_RE = re.compile(r'<title>.*?</title>')
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: