From 3e0a0222c426c794d6486dd4a9ba5422a54e2c8d Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Tue, 12 Apr 2011 07:15:52 +0300 Subject: [PATCH] Add script that changes Markdown links to use identifiers --- scripts/markdown-identifiers.py | 162 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 scripts/markdown-identifiers.py diff --git a/scripts/markdown-identifiers.py b/scripts/markdown-identifiers.py new file mode 100644 index 0000000..20752bd --- /dev/null +++ b/scripts/markdown-identifiers.py @@ -0,0 +1,162 @@ +# Encoding: UTF-8 +"""Rewrite Markdown strings to use identifiers instead of names + +This is an unmaintained one-shot script, only included in the repo for reference. + +""" + +from functools import partial +import sys +import re + +from sqlalchemy.orm.exc import MultipleResultsFound +from sqlalchemy.sql.expression import func + +from pokedex.db import connect, tables + +sanity_re = re.compile(ur"^[-A-Za-z0-9 é\[\]{}.%':;,×/()\"|–`—!*♂♀\\]$") + +# RE that matches anything that might look like a link +fuzzy_link_re = re.compile(r""" + \[ + [^]]+ + \] + \{ + [^}]+ + \}""", re.VERBOSE) + +# Very specific RE that matches links that appear in our Markdown strings +strict_link_re = re.compile(r""" + \[ + (?P