mark.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. from set_mark.start import start
  2. from set_mark.mid_pas import mid_pas
  3. from set_mark.html_pas import html_pas
  4. from set_mark.include_pas import include_pas
  5. from set_mark.macro import macro
  6. from set_mark.redirect_pas import redirect_pas
  7. from set_mark.blockquote import blockquote
  8. from set_mark.toc_pas import toc_pas
  9. from set_mark.text_help import text_help
  10. from set_mark.link import link
  11. from set_mark.indent import indent
  12. from set_mark.footnote import footnote
  13. from set_mark.table import table
  14. from set_mark.end import end
  15. import re
  16. import html
  17. import sqlite3
  18. from urllib import parse
  19. import time
  20. import threading
  21. def send_p(d):
  22. d = html.escape(d)
  23. js_p = re.compile('javascript:', re.I)
  24. d = js_p.sub('', d)
  25. d = re.sub('&lt;a href="(?:[^"]*)"&gt;(?P<in>(?:(?!&lt;).)*)&lt;\/a&gt;', '<a href="' + url_pas('\g<in>') + '">\g<in></a>', d)
  26. return d
  27. def url_pas(data):
  28. return parse.quote(data).replace('/','%2F')
  29. def plusing(conn, name, link, backtype):
  30. curs = conn.cursor()
  31. curs.execute("select title from back where title = ? and link = ? and type = ?", [link, name, backtype])
  32. if not curs.fetchall():
  33. curs.execute("insert into back (title, link, type) values (?, ?, ?)", [link, name, backtype])
  34. def namumark(conn, title, data, num, in_c, toc_y):
  35. data = start(data)
  36. data = html_pas(data)
  37. fol_num = 0
  38. a = mid_pas(data, fol_num, 0, in_c, toc_y)
  39. data = a[0]
  40. fol_num = a[1]
  41. a = include_pas(conn, data, title, in_c, num, toc_y, fol_num)
  42. data = a[0]
  43. category = a[1]
  44. fol_num = a[2]
  45. backlink = a[3]
  46. data = re.sub("\r\n##\s?([^\n]*)\r\n", "\r\n", data)
  47. a = redirect_pas(data, title, backlink)
  48. data = a[0]
  49. backlink = a[1]
  50. data = blockquote(data)
  51. data = toc_pas(data, title, num, toc_y)
  52. data = text_help(data)
  53. data = macro(data)
  54. a = link(conn, title, data, num, category, backlink)
  55. data = a[0]
  56. category = a[1]
  57. backlink = a[2]
  58. data = indent(data)
  59. data = footnote(data, fol_num)
  60. data = table(data)
  61. data = end(data, category)
  62. data += '<script>function folding(num) { var fol = document.getElementById(\'folding_\' + num); \
  63. if(fol.style.display == \'inline-block\' || fol.style.display == \'block\') { fol.style.display = \'none\'; } \
  64. else { if(num % 3 == 0) { fol.style.display = \'block\'; } else { fol.style.display = \'inline-block\'; } } } \
  65. </script>'
  66. if num == 1:
  67. for d4 in backlink:
  68. t = threading.Thread(target = plusing, args = [conn, d4[0], d4[1], d4[2]])
  69. t.start()
  70. t.join()
  71. conn.commit()
  72. return data