# HG changeset patch # User Ludovic Chabant # Date 1539325446 25200 # Node ID 71114096433c51e0a50281c32411500f14ee15ce # Parent 0ecf8303a135f0d2082012207438aece93a5e6ed 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. diff -r 0ecf8303a135 -r 71114096433c wikked/assets/css/wikked/page.less --- a/wikked/assets/css/wikked/page.less Thu Oct 11 23:18:45 2018 -0700 +++ b/wikked/assets/css/wikked/page.less Thu Oct 11 23:24:06 2018 -0700 @@ -1,5 +1,7 @@ +@wikked-icon-font: "Font Awesome 5 Free"; @wikked-external-link-icon: @fa-var-external-link-alt; //@wikked-external-link-icon: @fa-var-external-link-square-alt; +@wikked-anchor-icon: @fa-var-paragraph; // Article @@ -28,15 +30,52 @@ color: @color-orange; &:hover { color: @color-orange; text-decoration: underline; } } + + table { + display: block; + margin-top: 0; + margin-bottom: 1.5em; + + th, td { padding: 0.5em 1em; border: 1px solid @color-gray-medium; } + th { font-weight: bold; } + th, tr:nth-child(2n) { background: darken(@color-gray-light, 5%); } + } } article.wiki-page { - a { - &::after { font-family: 'Font Awesome 5 Free'; font-weight: 900; content: ' @{wikked-external-link-icon}'; } + a[href] { + &::after { + font-family: @wikked-icon-font; + font-size: 0.6em; + font-weight: 900; + vertical-align: middle; + content: ' @{wikked-external-link-icon}'; + } } a.wiki-link, a.wiki-meta-link { &::after { content: none; } } + + h1>a.wiki-header-link::after, + h2>a.wiki-header-link::after, + h3>a.wiki-header-link::after, + h4>a.wiki-header-link::after, + h5>a.wiki-header-link::after, + h6>a.wiki-header-link::after { + font-family: @wikked-icon-font; + font-size: 0.8em; + font-weight: 900; + content: ' @{wikked-anchor-icon}'; + visibility: hidden; + } + h1:hover>a.wiki-header-link::after, + h2:hover>a.wiki-header-link::after, + h3:hover>a.wiki-header-link::after, + h4:hover>a.wiki-header-link::after, + h5:hover>a.wiki-header-link::after, + h6:hover>a.wiki-header-link::after { + visibility: visible; + } } // Page title decorators diff -r 0ecf8303a135 -r 71114096433c wikked/formatter.py --- a/wikked/formatter.py Thu Oct 11 23:18:45 2018 -0700 +++ b/wikked/formatter.py Thu Oct 11 23:24:06 2018 -0700 @@ -4,7 +4,8 @@ import logging import jinja2 from io import StringIO -from .utils import get_meta_name_and_modifiers, html_escape, split_page_url +from .utils import ( + get_meta_name_and_modifiers, html_escape, split_page_url, get_url_tail) RE_FILE_FORMAT = re.compile(r'\r\n?', re.MULTILINE) @@ -18,13 +19,15 @@ re.MULTILINE | re.DOTALL) RE_LINK_ENDPOINT = re.compile( - r'\[\[(\w[\w\d]+)?\:([^\]]*/)?([^\]]+)\]\]') + r'(?%s\n' % ( mod_attr, '|'.join(processed_args)) - def _formatFileLink(self, ctx, endpoint, display, value): + def _formatFileLink(self, ctx, endpoint, display, value, fragment): if value.startswith('./'): abs_url = os.path.join('/pagefiles', ctx.url.lstrip('/'), value[2:]) @@ -223,40 +231,27 @@ abs_url = os.path.normpath(abs_url).replace('\\', '/') return abs_url - def _formatImageLink(self, ctx, endpoint, display, value): - abs_url = self._formatFileLink(ctx, endpoint, display, value) + def _formatImageLink(self, ctx, endpoint, display, value, fragment): + abs_url = self._formatFileLink(ctx, endpoint, display, value, fragment) return ('%s' % (abs_url, display)) - def _formatEndpointLink(self, ctx, endpoint, display, local_url): - if True: # endpoint: - endpoint = endpoint or '' - url = '%s:%s' % (endpoint, local_url) - ctx.out_links.append(url) - return ('%s' % (url, endpoint, - display)) - else: - # Endpoint link was actually: `[[:/Something/Blah]]`, which - # forces going back out of the endpoints. - # Render this like a normal wiki link. - ctx.out_links.append(local_url) - return '%s' % ( - local_url, display) + def _formatEndpointLink(self, ctx, endpoint, display, local_url, fragment): + endpoint = endpoint or '' + url = '%s:%s' % (endpoint, local_url) + fragpart = (' data-wiki-fragment="%s"' % fragment) if fragment else '' + ctx.out_links.append(url) + return ('%s' % + (url, fragpart, endpoint, display)) - def _formatWikiLink(self, ctx, display, url): - if True: # not ctx.endpoint: - ctx.out_links.append(url) - return '%s' % ( - url, display) - else: - # The link is a relative link from a page that lives in an - # endpoint, so the generated link must be in the same endpoint. - url = '%s:%s' % (ctx.endpoint, url) - ctx.out_links.append(url) - return ('%s' % (url, ctx.endpoint, - display)) + def _formatWikiLink(self, ctx, display, url, fragment): + fragpart = (' data-wiki-fragment="%s"' % fragment) if fragment else '' + ctx.out_links.append(url) + return ('%s' % + (url, fragpart, display)) @staticmethod def parseWikiLinks(text): diff -r 0ecf8303a135 -r 71114096433c wikked/resolver.py --- a/wikked/resolver.py Thu Oct 11 23:18:45 2018 -0700 +++ b/wikked/resolver.py Thu Oct 11 23:24:06 2018 -0700 @@ -23,6 +23,7 @@ re_wiki_link = re.compile( r'\n')