]> www.wagner.pp.ru Git - oss/ljdump.git/commitdiff
now replace lj comm as well as lj-cut tags
authorgrahams <github@sean-graham.com>
Sat, 7 Feb 2009 18:31:02 +0000 (02:31 +0800)
committerGreg Hewgill <greg@hewgill.com>
Mon, 4 May 2009 11:34:19 +0000 (19:34 +0800)
Signed-off-by: Greg Hewgill <greg@hewgill.com>
convertdump.py

index 937403b43bf1b137fa8ecca42e795298613efd2f..c99fff9b7d8d33bf311056c5ee7419ba660eb313 100755 (executable)
@@ -176,10 +176,28 @@ def addCommentsForId(outDoc, entry, username, id):
             appendTextNode(outDoc, outComment, "parent_itemid", parentId)
 
 def replaceLJTags(entry):
-    # regex to replace <lj user="jeebus" /> tags
-    fixedUserTags = re.sub("<lj user=\"(.*?)\" ?/?>", "<a href=\"http://\\1.livejournal.com/\" class=\"lj-user\">\\1</a>", entry)
+    rv = entry
 
-    return fixedUserTags
+    # replace lj user tags
+    userRE = re.compile('<lj user="(.*?)" ?/?>', re.IGNORECASE)
+    rv = re.sub(userRE, '<a href="http://\\1.livejournal.com/" class="lj-user">\\1</a>', rv) 
+
+    # replace lj comm tags
+    commRE = re.compile('<lj comm="(.*?)" ?/?>', re.IGNORECASE)
+    rv = re.sub(commRE, '<a href="http://community.livejournal.com/\\1/" class="lj-comm">\\1</a>', rv) 
+
+    # replace lj-cut tags
+    namedCutRE = re.compile('<lj-cut +text="(.*?)" ?/?>', 
+                            re.IGNORECASE|re.DOTALL)
+    rv = re.sub(namedCutRE, '<!--more \\1-->', rv)
+    
+    cutRE = re.compile('<lj-cut>', re.IGNORECASE)
+    rv = re.sub(cutRE, '<!--more-->', rv)
+
+    cutRE = re.compile('</lj-cut>', re.IGNORECASE)
+    rv = re.sub(cutRE, '', rv)
+
+    return rv
 
 
 def usage():