This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!

Untitled

By: NecklaceOfShadow on Jun 24th, 2011  |  syntax: Python  |  size: 1.33 KB  |  views: 69  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/env python
  2.  
  3. import re
  4. import sys
  5.  
  6. #\{\\it .*?\} -- to replace italics; run with flag S
  7. #\\begin\{center*?\}.*?\\end\{center*?} -- to replace center tags
  8. #\\chapter\{.*?\} -- to replace chapter tags
  9. #\{\\bf .*?\} -- to replace boldfaces; run with flag S
  10. #\\underline\{.*?\} -- to replace underlines; run with flag S
  11. #\\sps\{.*?\} -- to replace superscripts; run with flag S
  12. #\\sbs\{.*?\} -- to replace subscripts; run with flag S
  13. #\\sout\{.*?\} -- to replace strikethroughs; run with flag S
  14. #\\'e -- to replace escaped \'e in LaTeX
  15.  
  16.  
  17. eaccent = re.compile(r"\\'e")
  18. italics = re.compile(r"\{\\it (.*?)\}", re.S)
  19. center = re.compile(r"\\begin\{center\}(.*?)\\end\{center}")
  20. chapter = re.compile(r"\\chapter\{(.*?)\}")
  21. bold = re.compile(r"\{\\bf (.*?)\}", re.S)
  22. strike = re.compile(r"\\sout\{(.*?)\}", re.S)
  23. super = re.compile(r"\\sps\{(.*?)\}", re.S)
  24. sub = re.compile(r"\\sbs\{(.*?)\}", re.S)
  25.  
  26. passage = raw_input().decode(sys.stdout.encoding)
  27.  
  28. passage = eaccent.sub(r"\u00E9", passage)
  29. passage = italics.sub(r"[i]\1[/i]", passage)
  30. passage = center.sub(r"[center]\1[/center]", passage)
  31. passage = chapter.sub(r"[b]\1[/b]", passage)
  32. passage = bold.sub(r"[b]\1[/b]", passage)
  33. passage = strike.sub(r"[s]\1[/s]", passage)
  34. passage = super.sub(r"[sup]\1[/sup]", passage)
  35. passage = sub.sub(r"[sub]\1[/sub]", passage)
  36.  
  37. print passage
clone this paste RAW Paste Data