Commits

anatoly techtonik committed 4052582

Simple linkifying rule

  • Participants
  • Parent commits 9a18ca8

Comments (0)

Files changed (1)

 __license__ = "MIT | Public Domain"
 __version__ = "0.1"
 
+# --- define rules ---
+
+# rule is a function that takes text and returns either
+# None (not mathed) or a list of three text items:
+# [ not-matched, processed, the-rest ]
+
+import re
+
+def rule_linkify(text):
+  """ replace text links with HTML links """
+  linkre = re.compile('https?://\S+')
+  # [ ] test with commas and other URL escaped symbols
+  match = linkre.search(text)
+  if match == None:
+    return None
+  return (text[:match.start()], "[link]", text[match.end():])
+
+print rule_linkify("a web site http://google.com")
+
+# [ ] sets of common rules
+# [ ] configurable replacements
+# [ ] indented prints after every step