mark.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. from .set_mark.namumark import namumark
  2. from .set_mark.markdown import markdown
  3. from .set_mark.tool import *
  4. import re
  5. import os
  6. import html
  7. import sqlite3
  8. import asyncio
  9. import threading
  10. import urllib.parse
  11. if os.path.exists('route/tool/set_mark/custom.py'):
  12. from .set_mark.custom import custom_mark
  13. else:
  14. def custom_mark(conn, data, title, num, include):
  15. return [data, '', []]
  16. def load_conn2(data):
  17. global conn
  18. global curs
  19. conn = data
  20. curs = conn.cursor()
  21. def send_parser(data):
  22. if not re.search(r'^<br>$', data):
  23. data = html.escape(data)
  24. data = re.sub(r'javascript:', '', data, flags = re.I)
  25. data = data.replace('&lt;br&gt;', '')
  26. link_re = re.compile(r'&lt;a(?: (?:(?:(?!&gt;).)*))?&gt;(?P<in>(?:(?!&lt;).)*)&lt;\/a&gt;')
  27. link_data = link_re.findall(data)
  28. for i in link_data:
  29. data = link_re.sub('<a href="/w/' + urllib.parse.quote(i).replace('/','%2F') + '">' + i + '</a>', data, 1)
  30. return data
  31. def render_do(title, data, num, include):
  32. if num == 3:
  33. num = 1
  34. back_num = 3
  35. else:
  36. back_num = num
  37. curs.execute(db_change('select data from other where name = "markup"'))
  38. rep_data = curs.fetchall()
  39. if rep_data[0][0] == 'namumark':
  40. data = namumark(conn, data, title, include)
  41. elif rep_data[0][0] == 'markdown':
  42. data = markdown(conn, data, title, include)
  43. elif rep_data[0][0] == 'custom':
  44. data = custom_mark(conn, data, title, include)
  45. elif rep_data[0][0] == 'raw':
  46. data = [data, '', []]
  47. else:
  48. data = ['', '', []]
  49. if num == 1:
  50. if data[2] == []:
  51. curs.execute(db_change("insert into back (title, link, type) values ('test', ?, 'nothing')"), [title])
  52. else:
  53. curs.executemany(db_change("insert into back (link, title, type) values (?, ?, ?)"), data[2])
  54. curs.execute(db_change("delete from back where title = ? and type = 'no'"), [title])
  55. if back_num != 3:
  56. conn.commit()
  57. if num == 2:
  58. return [data[0], data[1]]
  59. else:
  60. return data[0] + '<script>' + data[1] + '</script>'