فهرست منبع

중간 저장

ect (or 2du) 8 سال پیش
والد
کامیت
c6809e0a4c
5فایلهای تغییر یافته به همراه73 افزوده شده و 28 حذف شده
  1. 44 1
      set_mark/end.py
  2. 6 4
      set_mark/indent.py
  3. 6 4
      set_mark/link.py
  4. 16 18
      set_mark/mid_pas.py
  5. 1 1
      set_mark/text_help.py

+ 44 - 1
set_mark/end.py

@@ -1,4 +1,5 @@
 import re
+from urllib import parse
 
 def end(data, category):    
     if category:
@@ -6,13 +7,55 @@ def end(data, category):
             
     data = re.sub("\r\n(?P<in><h[0-6])", "\g<in>", data)
     data = re.sub("(\n<nobr>|<nobr>\n|<nobr>)", "", data)
-    data = re.sub("#no#(?P<in>.)#\/no#", "\g<in>", data)
     data = re.sub("&lt;space&gt;", " ", data)
 
+    com = re.compile('#base64#((?:(?!#\/base64#|%0A).)+)#\/base64#', re.DOTALL)
+    while 1:
+        m = com.search(data)
+        if m:
+            data = com.sub('<code>' + parse.unquote(m.groups()[0]).replace('&#95;', '_') + '</code>', data, 1)
+        else:
+            break
+
+    com = re.compile('#base64#((?:(?!#\/base64#).)+)#\/base64#', re.DOTALL)
+    while 1:
+        m = com.search(data)
+        if m:
+            data = com.sub('<pre>' + parse.unquote(m.groups()[0]).replace('&#95;', '_').replace('\r\n', '<br>') + '</pre>', data, 1)
+        else:
+            break
+
+    com = re.compile('#mini#((?:(?!#\/mini#).)+)#\/mini#', re.DOTALL)
+    while 1:
+        m = com.search(data)
+        if m:
+            data = com.sub(parse.unquote(m.groups()[0]).replace('&#95;', '_'), data, 1)
+        else:
+            break
+
+    com3 = re.compile('#mid2#((?:(?!#\/mid2#).)+)#\/mid2#', re.DOTALL)
+    m = com3.search(data)
+    while 1:
+        m = com3.search(data)
+        if m:
+            data = com3.sub('{{{' + m.groups()[0] + '}}}', data, 1)
+        else:
+            break
+
+    com3 = re.compile('#mid#((?:(?!#\/mid#).)+)#\/mid#', re.DOTALL)
+    m = com3.search(data)
+    while 1:
+        m = com3.search(data)
+        if m:
+            data = com3.sub('{{{' + m.groups()[0] + '}}}', data, 1)
+        else:
+            break
+
     data = re.sub('<\/blockquote>(?:(?:\r)?\n){2}<blockquote>', '</blockquote><blockquote>', data)
     data = re.sub('<\/blockquote>(?:(?:\r)?\n)<br><blockquote>', '</blockquote><blockquote>', data)
 
     data = re.sub('\n', '<br>', data)
+    data = re.sub('<pre><br>', '<pre>', data)
     data = re.sub('<hr id="under_bar"([^>]*)><br>', '<hr id="under_bar" style="margin-top: -5px;">', data)
     data = re.sub('&lt;isbr&gt;', '\r\n', data)
     data = re.sub('^(?:<br>|\r|\n| )+', '', data)

+ 6 - 4
set_mark/indent.py

@@ -1,14 +1,16 @@
 import re
 
 def indent(data):
+    data = re.sub('\n \|\|', '\n||', data)
+
     while 1:
-        m = re.search("(\n(?:(?:( *)\* (?:[^\n]*))\n?)+)", data)
+        m = re.search("(\n(?:(?:( *)\* ?(?:[^\n]*))\n?)+)", data)
         if m:
             result = m.groups()
             end = str(result[0])
 
             while 1:
-                isspace = re.search("\n( *)\* ([^\n]*)", end)
+                isspace = re.search("\n( *)\* ?([^\n]*)", end)
                 if isspace:
                     spacebar = isspace.groups()
                     if len(spacebar[0]) == 0:
@@ -16,12 +18,12 @@ def indent(data):
                     else:
                         up = len(spacebar[0]) * 20
 
-                    end = re.sub("\n( *)\* ([^\n]*)", "<li style='margin-left:" + str(up) + "px'>" + spacebar[1] + "</li>", end, 1)
+                    end = re.sub("\n( *)\* ?([^\n]*)", "<li style='margin-left:" + str(up) + "px'>" + spacebar[1] + "</li>", end, 1)
                 else:
                     break
 
             end = re.sub("\n", '', end)
-            data = re.sub("(\n(?:(?:( *)\* (?:[^\n]*))\n?)+)", '<ul style="margin-top: 10px; margin-bottom: 10px;" id="list">' + end + '</ul>', data, 1)
+            data = re.sub("(\n(?:(?:( *)\* ?(?:[^\n]*))\n?)+)", '<ul style="margin-top: 10px; margin-bottom: 10px;" id="list">' + end + '</ul>', data, 1)
         else:
             break
 

+ 6 - 4
set_mark/link.py

@@ -136,10 +136,10 @@ def link(conn, title, data, num, category, backlink):
                 
                 data = link.sub('<a class="out_link" rel="nofollow" href="' + re.sub('<([^>]*)>', '', d[0]) + '">' + view + '</a>', data, 1)
             else:
-                view = d[0].replace('\\\\', '<slash>').replace('\\', '').replace('<slash>', '\\')
+                view = d[0].replace('\\\\', '#slash#').replace('\\', '').replace('#slash#', '\\')
                 try:
                     if re.search('(.+)', d[1]):
-                        view = d[1].replace('\\\\', '<slash>').replace('\\', '').replace('<slash>', '\\')
+                        view = d[1].replace('\\\\', '#slash#').replace('\\', '').replace('#slash#', '\\')
                 except:
                     pass        
                     
@@ -156,7 +156,8 @@ def link(conn, title, data, num, category, backlink):
                 elif re.search('^#', d[0]):
                     data = link.sub('<a title="' + sh + '" href="' + sh + '">' + view + '</a>', data, 1)
                 else:                    
-                    a = re.sub('<([^>]*)>', '', href.replace('&#x27;', "'").replace('&quot;', '"').replace('\\\\', '<slash>').replace('\\', '').replace('<slash>', '\\'))
+                    a = re.sub('<([^>]*)>', '', href.replace('&#x27;', "'")).replace('&quot;', '"')
+                    a = a.replace('\\\\', '#slash#').replace('\\', '').replace('#slash#', '\\')
                     
                     if num == 1:
                         backlink += [[title, a, '']]
@@ -170,7 +171,8 @@ def link(conn, title, data, num, category, backlink):
                     else:
                         no = ''
                     
-                    data = link.sub('<a ' + no + ' title="' + re.sub('<([^>]*)>', '', href) + sh + '" href="/w/' + url_pas(a) + sh + '">' + view.replace('\\', '\\\\') + '</a>', data, 1)
+                    data = link.sub('<a ' + no + ' title="' + re.sub('<([^>]*)>', '', href) + sh + '" href="/w/' + url_pas(a) + sh + '">' + \
+                                    view.replace('\\', '\\\\') + '</a>', data, 1)
         else:
             break
             

+ 16 - 18
set_mark/mid_pas.py

@@ -1,14 +1,15 @@
 import re
+from urllib import parse
 
 def mid_pas(data, fol_num, include, in_c, toc_y):
     syntax = 0
     folding_test = 0
 
-    p = re.compile('{{{((?:(?:(?:\+|-)[0-5])|(?:#|@)(?:(?:[0-9a-f-A-F]{3}){1,2}|(?:\w+))|(?:#!(?:html|wiki|noin|folding|syntax)))(?:(?!{{{|}}}).)+)}}}', re.DOTALL)
+    p = re.compile('{{{((?!#mid#)(?:(?:(?:\+|-)(?:[^ ]+))|(?:#|@)(?:(?:[0-9a-f-A-F]{3}){1,2}|(?:\w+))|(?:#!(?:html|wiki|noin|folding|syntax)))(?:(?!{{{|}}}).)+)}}}', re.DOTALL)
     while 1:
         m = p.search(data)
         if m:
-            data = p.sub('###' + m.groups()[0] + '/###', data, 1)
+            data = p.sub('#mid#' + m.groups()[0] + '#/mid#', data, 1)
         else:
             break
 
@@ -16,11 +17,22 @@ def mid_pas(data, fol_num, include, in_c, toc_y):
     while 1:
         m = com.search(data)
         if m:
-            data = com.sub('<code>' + m.groups()[0] + '</code>', data, 1)
+            com4 = re.compile('#base64#((?:(?!#\/base64#).)+)#\/base64#', re.DOTALL)
+            test = com4.search(m.groups()[0])
+            if test:
+                test2 = com4.sub('#mid2#' + parse.unquote(test.groups()[0]).replace('&#95;', '_').replace('&#8208;', '-') + \
+                                '#/mid2#', m.groups()[0])
+            else:
+                test2 = m.groups()[0]
+                
+            data = com.sub('#base64#' + parse.quote(test2).replace('_', '&#95;').replace('-', '&#8208;').replace('%3C', '&lt;').replace('%3E', '&gt;') + \
+                            '#/base64#', data, 1)
         else:
             break
 
-    com3 = re.compile('###((?:(?!\/###).)+)\/###', re.DOTALL)
+        data = re.sub("{#base64#%7B%7B", "{{{#base64#", data)
+
+    com3 = re.compile('#mid#((?:(?!#\/mid#).)+)#\/mid#', re.DOTALL)
     m = com3.search(data)
     while 1:
         m = com3.search(data)
@@ -29,13 +41,6 @@ def mid_pas(data, fol_num, include, in_c, toc_y):
         else:
             break
 
-    com2 = re.compile("<code>((?:(?!(?:<code>|<\/code>)).)*)<\/code>", re.DOTALL)
-    da_com = com2.findall(data)
-    for com_da in da_com:
-        mid_data = com_da.replace('<', '&lt;').replace('>', '&gt;')
-        mid_data = re.sub("(?P<in>.)", "#no#\g<in>#/no#", mid_data)
-        data = com2.sub(mid_data, data, 1)
-
     while 1:
         is_it = com.search(data)
         if is_it:
@@ -131,12 +136,5 @@ def mid_pas(data, fol_num, include, in_c, toc_y):
                 data = com.sub(it_d, data, 1)
         else:
             break
-
-    com2 = re.compile("<code>((?:(?!(?:<code>|<\/code>)).)*)<\/code>", re.DOTALL)
-    da_com = com2.findall(data)
-    for com_da in da_com:
-        mid_data = com_da.replace('<', '&lt;').replace('>', '&gt;')
-        mid_data = re.sub("(?P<in>.)", "#no#\g<in>#/no#", mid_data)
-        data = com2.sub(mid_data, data, 1)
             
     return [data, fol_num]

+ 1 - 1
set_mark/text_help.py

@@ -10,7 +10,7 @@ def text_help(data):
 
     if re.search('&lt;math&gt;((?:(?!&lt;\/math&gt;).)*)&lt;\/math&gt;', data):
         data = re.sub('&lt;math&gt;(?P<in>(?:(?!&lt;\/math&gt;).)*)&lt;\/math&gt;', '[math]\g<in>[/math]', data)
-        data += '<script type="text/x-mathjax-config">MathJax.Hub.Config({tex2jax: { inlineMath: [ [\'[math]\', \'[/math]\'] ] } });</script> \
+        data += '<script type="text/x-mathjax-config">MathJax.Hub.Config({ tex2jax: { inlineMath: [["[math]","[/math]"], processEscapes: true } });</script> \
                 <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/MathJax.js?config=TeX-AMS_CHTML"></script>'
  
     data = re.sub('{{\|(?P<in>(?:(?:(?:(?!\|}}).)*)(?:\n?))+)\|}}', '<table><tbody><tr><td>\g<in></td></tr></tbody></table>', data)