def link(self, context, span, basepath): pages = context.pages searcher = context.searcher # Don't bother if this object has already operated on this link # (for example, if it was included). # Only operate on links to other wiki pages. if "fields" in span or "fullpath" not in span: return fullpath = span["fullpath"] pagepath, fragment = paths.split_fragment(fullpath) spath = pages.source_path(pagepath) exists = span["exists"] = pages.exists(spath) # Look up the linked page in the index and copy its stored # fields onto the link if searcher and exists: stored = searcher.document(path=fullpath) if stored is not None: spanfields = span["fields"] = {} # Copy the stored fields onto the span for attrname in self.attrs: if attrname in stored: spanfields[attrname] = stored[attrname] title = stored.get("title") if not span.get("text") and title: span["text"] = [title]
def _read_labels(pages, basepath, labelspath, labels): labelspath = paths.join(basepath, labelspath) labelspath, section = paths.split_fragment(labelspath) section = section[1:] if section else "Labels" if pages.exists(labelspath): content = pages.content(labelspath, encoding=None) bio = BytesIO(content) parser = configparser.SafeConfigParser() parser.readfp(bio) if parser.has_section(section): labels.update(dict(parser.items(section)))
def source_path(self, path, locale=None): path, frag = paths.split_fragment(path) if ( not path.endswith("/") and self.store.exists(path) and self.store.is_dir(path) ): path += "/" if path.endswith("/"): path += self.index_page_name + self.wiki_ext basepath, ext = paths.split_extension(path) if not ext: if locale: path = "%s.%s%s" % (basepath, locale, ext) path += self.wiki_ext return path
def link(self, context, span, basepath): pages = context.pages # Don't bother if this object has already operated on this link # (for example, if it was included) if "fullpath" in span: return path = span.get("value") if not path or ":" in path: span["exists"] = True return fullpath = pages.full_path(basepath, path) span["fullpath"] = fullpath pagepath, fragment = paths.split_fragment(fullpath) if fragment: span["fragment"] = fragment
def full_path(self, origin, relpath): path = paths.join(origin, relpath) base, frag = paths.split_fragment(path) if base.endswith("/"): base += self.index_page_name return base + frag