Changeset 17832
- Timestamp:
- Aug 10, 2020, 6:46:57 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mediawikipluginmacro/mediawiki/parser.py
r17387 r17832 15 15 16 16 17 class MediaWikiRenderer(Component): 18 """ 19 Renders plain text in MediaWiki format as HTML 20 """ 21 implements(IWikiMacroProvider) 22 23 def get_macros(self): 24 """Return a list of provided macros""" 25 yield 'mediawiki' 26 27 def get_macro_description(self, name): 28 return '''desc''' 29 30 def expand_macro(self, formatter, name, content): 31 if name == 'mediawiki': 32 return parse(content) 33 34 35 if __name__ == "__main__": 36 import sys 37 try: 38 file = open(sys.argv[1]) 39 print parse(file.read()) 40 except: 41 pass 17 if __name__ == "__main__": 18 import sys 19 try: 20 file = open(sys.argv[1]) 21 print parse(file.read()) 22 except: 23 pass 42 24 43 25 mTagHooks = {} … … 928 910 return u'/'.join(slugifyBit(t) for t in text.split(u'/')) 929 911 930 _linkPat = re.compile(ur'^([A-Za-z0-9\s]+:)?( [A-Za-z0-9_\.\-\s\/]+)(?:\|([^\n]+?))?\]\](.*)$', re.UNICODE | re.DOTALL)912 _linkPat = re.compile(ur'^([A-Za-z0-9\s]+:)?(#)?([A-Za-z0-9_\.\-\s\/\(\)]+)(?:\|([^\n]+?))?\]\](.*)$', re.UNICODE | re.DOTALL) 931 913 def replaceInternalLinks(text): 932 914 arr = text.split('[[') … … 934 916 sb.append(arr.pop(0)) 935 917 for bit in arr: 936 namespace, link, alt, rest =None, None, None, None918 namespace, anchorchar, link, alt, rest = None, None, None, None, None 937 919 match = _linkPat.match(bit) 938 920 if match: 939 namespace, link, alt, rest = match.groups()921 namespace, anchorchar, link, alt, rest = match.groups() 940 922 if link: 941 923 if not namespace: … … 956 938 #sb.append(namespace) 957 939 #sb.append(u'/') 958 sb.append(slugify(link)) 940 if anchorchar: 941 sb.append(u'#') 942 sb.append(slugifyBit(link)) 943 sb.append(u'">') 944 else: 945 sb.append(slugify(link)) 946 sb.append(u'/">') 959 947 if alt: 960 948 link = alt 961 sb.append(u'/">')962 949 sb.append(link) 963 950 sb.append(u'</a>') … … 979 966 return text, showToc 980 967 981 _bracketedLinkPat = re.compile(ur'(?:\[((?:https?://|ftp://|/)[^<>\]\[' + u "\x00-\x20\x7f"+ ur']+)\s*(.*?)\])', re.UNICODE)968 _bracketedLinkPat = re.compile(ur'(?:\[((?:https?://|ftp://|/)[^<>\]\[' + ur'\u0000-\u0020\u007f-\u009f' + ur']+)\s*(.*?)\])', re.UNICODE) 982 969 def replaceExternalLinks(text): 983 970 sb = [] … … 1006 993 1007 994 _protocolPat = re.compile(ur'(\b(?:https?://|ftp://))', re.UNICODE) 1008 _specialUrlPat = re.compile(ur'^([^<>\]\[' + u "\x00-\x20\x7f" + ur']+)(.*)$', re.UNICODE)995 _specialUrlPat = re.compile(ur'^([^<>\]\[' + ur'\u0000-\u0020\u007f-\u009f' + ur']+)(.*)$', re.UNICODE | re.DOTALL) 1009 996 _protocolsPat = re.compile(ur'^(https?://|ftp://)$', re.UNICODE) 1010 997 … … 1045 1032 sep += ')' 1046 1033 1047 i= len(url)-11048 while i>= 0:1049 char = url[ i]1034 j = len(url)-1 1035 while j >= 0: 1036 char = url[j] 1050 1037 if char not in sep: 1051 1038 break 1052 i-= 11053 i+= 11054 1055 if i!= len(url):1056 trail = url[ i:] + trail1057 url = url[0: i]1039 j -= 1 1040 j += 1 1041 1042 if j != len(url): 1043 trail = url[j:] + trail 1044 url = url[0:j] 1058 1045 1059 1046 url = cleanURL(url) … … 1064 1051 sb.append(url) 1065 1052 sb.append(u'</a>') 1066 sb.append(text)1067 1053 sb.append(trail) 1068 1054 else: … … 1077 1063 return "%%%02x" % num 1078 1064 1079 _controlCharsPat = re.compile(ur'[\]\[<>"' + u "\\x00-\\x20\\x7F"+ ur']]', re.UNICODE)1065 _controlCharsPat = re.compile(ur'[\]\[<>"' + ur'\u0000-\u0020\u007f-\u009f' + ur']]', re.UNICODE) 1080 1066 _hostnamePat = re.compile(ur'^([^:]+:)(//[^/]+)?(.*)$', re.UNICODE) 1081 1067 _stripPat = re.compile(u'\\s|\u00ad|\u1806|\u200b|\u2060|\ufeff|\u03f4|\u034f|\u180b|\u180c|\u180d|\u200c|\u200d|[\ufe00-\ufe0f]', re.UNICODE) … … 2343 2329 lastPrefixLength -= 1 2344 2330 if prefixLength <= commonPrefixLength and commonPrefixLength > 0: 2345 tmpOutput, tmpMDTopen = nextItem(pref[commonPrefixLength-1] )2331 tmpOutput, tmpMDTopen = nextItem(pref[commonPrefixLength-1], mDTopen) 2346 2332 output += tmpOutput 2347 2333 if tmpMDTopen is not None:
Note: See TracChangeset
for help on using the changeset viewer.