2
0

mark.py 2.1 KB

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