mark.py 2.1 KB

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