2
0

mark.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. from . import start
  2. from . import mid_pas
  3. from . import html_pas
  4. from . import include_pas
  5. from . import macro
  6. from . import redirect_pas
  7. from . import blockquote
  8. from . import toc_pas
  9. from . import text_help
  10. from . import link
  11. from . import indent
  12. from . import footnote
  13. from . import table
  14. from . import end
  15. import re
  16. import html
  17. import sqlite3
  18. from urllib import parse
  19. import time
  20. import asyncio
  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. async 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.start(data)
  36. data = html_pas.html_pas(data)
  37. fol_num = 0
  38. a = mid_pas.mid_pas(data, fol_num, 0, in_c)
  39. data = a[0]
  40. fol_num = a[1]
  41. a = include_pas.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.redirect_pas(data, title, backlink)
  48. data = a[0]
  49. backlink = a[1]
  50. data = blockquote.blockquote(data)
  51. data = toc_pas.toc_pas(data, title, num, toc_y)
  52. data = text_help.text_help(data)
  53. data = macro.macro(data)
  54. a = link.link(conn, title, data, num, category, backlink)
  55. data = a[0]
  56. category = a[1]
  57. backlink = a[2]
  58. data = indent.indent(data)
  59. data = footnote.footnote(data, fol_num)
  60. data = table.table(data)
  61. data = end.end(data, category)
  62. if(num == 1):
  63. asyncio.set_event_loop(asyncio.new_event_loop())
  64. loop = asyncio.get_event_loop()
  65. for d4 in backlink:
  66. loop.run_until_complete(plusing(conn, d4[0], d4[1], d4[2]))
  67. loop.close()
  68. conn.commit()
  69. return(data)