comparison wikked/resolver.py @ 476:71114096433c

core: Add support for Markdown extensions, add header anchor extension. - New configuration option to specify Markdown extensions. - Enable some extensions by default. - Add CSS to make tables pretty. - Add extension to generate anchors next to each HTML heading. - Provide CSS to show those anchors on mouse-hover.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 11 Oct 2018 23:24:06 -0700
parents db73b12ad212
children eacacee352f7
comparison
equal deleted inserted replaced
475:0ecf8303a135 476:71114096433c
21 re_wiki_tag_attr = re.compile( 21 re_wiki_tag_attr = re.compile(
22 r'data-wiki-(?P<name>[a-z]+)="(?P<value>[^"]+)"') 22 r'data-wiki-(?P<name>[a-z]+)="(?P<value>[^"]+)"')
23 re_wiki_link = re.compile( 23 re_wiki_link = re.compile(
24 r'<a class="wiki-link(?P<isedit>-edit)?" ' 24 r'<a class="wiki-link(?P<isedit>-edit)?" '
25 r'data-wiki-url="(?P<url>[^"]+)"' 25 r'data-wiki-url="(?P<url>[^"]+)"'
26 r'( data-wiki-fragment="(?P<frag>[^"]*)")?'
26 r'( data-wiki-endpoint="(?P<endpoint>[^"]*)")?') 27 r'( data-wiki-endpoint="(?P<endpoint>[^"]*)")?')
27 28
28 re_wiki_include_param = re.compile( 29 re_wiki_include_param = re.compile(
29 r'<div class="wiki-param" ' 30 r'<div class="wiki-param" '
30 r'data-name="(?P<name>\w[\w\d]*)?">' 31 r'data-name="(?P<name>\w[\w\d]*)?">'
228 final_text, parameters, error_url=self.page.url) 229 final_text, parameters, error_url=self.page.url)
229 230
230 # Resolve link states. 231 # Resolve link states.
231 def repl1(m): 232 def repl1(m):
232 raw_url = m.group('url') 233 raw_url = m.group('url')
234 fragment = m.group('frag') or ''
233 endpoint = m.group('endpoint') 235 endpoint = m.group('endpoint')
234 is_edit = bool(m.group('isedit')) 236 is_edit = bool(m.group('isedit'))
235 url = self.ctx.getAbsoluteUrl(raw_url, force_endpoint=endpoint) 237 url = self.ctx.getAbsoluteUrl(raw_url, force_endpoint=endpoint)
236 238
237 if endpoint != SPECIAL_ENDPOINT: 239 if endpoint != SPECIAL_ENDPOINT:
251 endpoint_markup = ' data-wiki-endpoint="%s"' % split_url[0] 253 endpoint_markup = ' data-wiki-endpoint="%s"' % split_url[0]
252 254
253 if validated_url: 255 if validated_url:
254 # The DB has confirmed that the target page exists, 256 # The DB has confirmed that the target page exists,
255 # so make a "real" link. 257 # so make a "real" link.
256 actual_url = '/%s/%s' % (action, quoted_url.lstrip('/')) 258 actual_url = '/%s/%s%s' % (action,
259 quoted_url.lstrip('/'),
260 fragment)
257 return ('<a class="wiki-link" data-wiki-url="%s" ' 261 return ('<a class="wiki-link" data-wiki-url="%s" '
258 'href="%s"' % (quoted_url, actual_url) + 262 'href="%s"' % (quoted_url, actual_url) +
259 endpoint_markup) 263 endpoint_markup)
260 264
261 # The DB doesn't know about the target page, so render 265 # The DB doesn't know about the target page, so render
262 # a link with the "missing" class so it shows up red and all. 266 # a link with the "missing" class so it shows up red and all.
263 actual_url = '/%s/%s' % (action, quoted_url.lstrip('/')) 267 actual_url = '/%s/%s%s' % (action,
268 quoted_url.lstrip('/'),
269 fragment)
264 return ('<a class="wiki-link missing" data-wiki-url="%s" ' 270 return ('<a class="wiki-link missing" data-wiki-url="%s" '
265 'href="%s"' % (quoted_url, actual_url) + 271 'href="%s"' % (quoted_url, actual_url) +
266 endpoint_markup) 272 endpoint_markup)
267 273
268 final_text = re_wiki_link.sub(repl1, final_text) 274 final_text = re_wiki_link.sub(repl1, final_text)