def __init__(self, sitedir, project): self.sitedir = sitedir self.filelist = project.filelist self.navlist = project.navlist self.taglist = project.taglist self.site = project.site dlclass = md_extensions.DLClassExtension() tableclass = md_extensions.TableClassExtension() projectref = md_extensions.ProjectReferenceExtension() extractanchors = md_extensions.ExtractAnchorsExtension() # there is a strange interaction between smarty and reference links that start on a new line # disabling smarty for now... # extensions = ['extra', 'codehilite', 'headerid', 'toc', 'smarty', tableclass, projectref] extensions = ["extra", "codehilite", "toc", dlclass, tableclass, projectref, extractanchors] extension_configs = {"codehilite": [("guess_lang", "False"), ("linenums", "False")], "toc": [("baselevel", 2)]} self.md = markdown.Markdown(extensions=extensions, extension_configs=extension_configs) self.md.site = self.site self.md.anchors = project.anchors env = self.env = jinja2.Environment( loader=jinja2.FileSystemLoader(layoutdir), lstrip_blocks=True, trim_blocks=True ) env.filters.update(project.filters) self.templates = {} for layout in project.layouts: self.templates[layout] = self.env.get_template(layout + ".html") # layout for tags is optional, triggers index file generation per tag try: self.templates[tag_layout] = self.env.get_template(tag_layout + ".html") except jinja2.exceptions.TemplateNotFound: if self.taglist: urubu_warn(_warning.undef_tag_layout, msg=tag_layout)
def handleMatch(self, m): try: ref = m.group(9) except IndexError: ref = None shortref = False if not ref: # if we got something like "[Google][]" or "[Google]" # we'll use "google" as the id ref = m.group(2) shortref = True # Clean up linebreaks in ref ref = self.NEWLINE_CLEANUP_RE.sub(' ', ref) text = m.group(2) id = ref.lower() if id in self.markdown.references: href, title = self.markdown.references[id] else: anchor = None if '#' in ref: ref, anchor = ref.split('#', 1) this = self.markdown.this if not posixpath.isabs(ref): # treat empty ref as reference to current page if not ref: ref = this['components'][-1] rootrelpath = '/' + '/'.join(this['components'][:-1]) id = posixpath.normpath(posixpath.join(rootrelpath, ref)) id = id.lower() else: id = ref.lower() ref = ref.lower() if ref in self.markdown.site['reflinks']: if (ref != id) and (id in self.markdown.site['reflinks']): raise UrubuError(_error.ambig_ref_md, msg=ref, fn=this['fn']) id = ref if id in self.markdown.site['reflinks']: item = self.markdown.site['reflinks'][id] href, title = item['url'], item['title'] if shortref: text = title if anchor is not None: text = anchor if anchor is not None: anchor = toc.slugify(anchor, '-') href = '%s#%s' % (href, anchor) anchorref = '%s#%s' % (id, anchor) self.markdown.this['_anchorrefs'].add(anchorref) else: # ignore undefined refs urubu_warn(_warning.undef_ref_md, msg=ref, fn=this['fn']) return None return self.makeTag(href, title, text)
def handleMatch(self, m, data): text, index, handled = self.getText(data, m.end(0)) if not handled: return None, None, None ref, end, shortref, handled = self.evalRef(data, index, text) if not handled: return None, None, None # Clean up linebreaks in ref ref = self.NEWLINE_CLEANUP_RE.sub(' ', ref) id = ref.lower() if id in self.md.references: href, title = self.md.references[id] else: anchor = None if '#' in ref: ref, anchor = ref.split('#', 1) this = self.md.this if not posixpath.isabs(ref): # treat empty ref as reference to current page if not ref: ref = this['components'][-1] rootrelpath = '/' + '/'.join(this['components'][:-1]) id = posixpath.normpath(posixpath.join(rootrelpath, ref)) id = id.lower() else: id = ref.lower() ref = ref.lower() if ref in self.md.site['reflinks']: if (ref != id) and (id in self.md.site['reflinks']): raise UrubuError(_error.ambig_ref_md, msg=ref, fn=this['fn']) id = ref if id in self.md.site['reflinks']: item = self.md.site['reflinks'][id] href, title = item['url'], item['title'] if shortref: text = title if anchor is not None: text = anchor if anchor is not None: anchor = toc.slugify(anchor, '-') href = '%s#%s' % (href, anchor) anchorref = '%s#%s' % (id, anchor) self.md.this['_anchorrefs'].add(anchorref) else: # ignore undefined refs urubu_warn(_warning.undef_ref_md, msg=ref, fn=this['fn']) return None, None, None return self.makeTag(href, title, text), m.start(0), end
def __init__(self, sitedir, project): self.sitedir = sitedir self.filelist = project.filelist self.navlist = project.navlist self.taglist = project.taglist self.site = project.site dlclass = md_extensions.DLClassExtension() tableclass = md_extensions.TableClassExtension() projectref = md_extensions.ProjectReferenceExtension() extractanchors = md_extensions.ExtractAnchorsExtension() marktag = md_extensions.MarkTagExtension() # there is a strange interaction between smarty and reference links # that start on a new line # disabling smarty for now... # extensions = ['extra', 'codehilite', 'headerid', # 'toc', 'smarty', tableclass, projectref] extensions = ['markdown.extensions.extra', 'markdown.extensions.codehilite', 'markdown.extensions.toc', dlclass, tableclass, projectref, extractanchors] if self.site['mark_tag_support']: extensions.append(marktag) extension_configs = {'markdown.extensions.codehilite': [('guess_lang', 'False'), ('linenums', 'False')], 'markdown.extensions.toc': [('baselevel', 2)] } self.md = markdown.Markdown(extensions=extensions, extension_configs=extension_configs) self.md.site = self.site self.md.anchors = project.anchors if 'strict_undefined' in self.site and self.site['strict_undefined']: undefined_class = jinja2.StrictUndefined else: undefined_class = jinja2.Undefined env = self.env = jinja2.Environment( loader=jinja2.FileSystemLoader(layoutdir), lstrip_blocks=True, trim_blocks=True, undefined=undefined_class) env.filters.update(project.filters) self.templates = {} for layout in project.layouts: self.templates[layout] = self.env.get_template(layout + '.html') # layout for tags is optional, triggers index file generation per tag try: self.templates[tag_layout] = self.env.get_template( tag_layout + '.html') except jinja2.exceptions.TemplateNotFound: if self.taglist: urubu_warn(_warning.undef_tag_layout, msg=tag_layout)
def __init__(self, sitedir, project): self.sitedir = sitedir self.filelist = project.filelist self.navlist = project.navlist self.taglist = project.taglist self.site = project.site dlclass = md_extensions.DLClassExtension() tableclass = md_extensions.TableClassExtension() projectref = md_extensions.ProjectReferenceExtension() extractanchors = md_extensions.ExtractAnchorsExtension() marktag = md_extensions.MarkTagExtension() # there is a strange interaction between smarty and reference links that start on a new line # disabling smarty for now... # extensions = ['extra', 'codehilite', 'headerid', 'toc', 'smarty', tableclass, projectref] extensions = [ 'markdown.extensions.extra', 'markdown.extensions.codehilite', 'markdown.extensions.toc', dlclass, tableclass, projectref, extractanchors ] if self.site['mark_tag_support']: extensions.append(marktag) extension_configs = { 'markdown.extensions.codehilite': [('guess_lang', 'False'), ('linenums', 'False')], 'markdown.extensions.toc': [('baselevel', 2)] } self.md = markdown.Markdown(extensions=extensions, extension_configs=extension_configs) self.md.site = self.site self.md.anchors = project.anchors if 'strict_undefined' in self.site and self.site['strict_undefined']: undefined_class = jinja2.StrictUndefined else: undefined_class = jinja2.Undefined env = self.env = jinja2.Environment( loader=jinja2.FileSystemLoader(layoutdir), lstrip_blocks=True, trim_blocks=True, undefined=undefined_class) env.filters.update(project.filters) self.templates = {} for layout in project.layouts: self.templates[layout] = self.env.get_template(layout + '.html') # layout for tags is optional, triggers index file generation per tag try: self.templates[tag_layout] = self.env.get_template(tag_layout + '.html') except jinja2.exceptions.TemplateNotFound: if self.taglist: urubu_warn(_warning.undef_tag_layout, msg=tag_layout)
def get_contentinfo(self): """Get info from the markdown content files.""" pattern = '*.md' ignore_patterns = self.get_ignore_patterns() for path, dirnames, filenames in os.walk(self.cwd): relpath = get_relpath(path, self.cwd) if any(fnmatch.fnmatch(relpath, ip) for ip in ignore_patterns): continue content_found = index_found = False for fn in filenames: if fnmatch.fnmatch(fn, pattern): # normalize to convert ./foo into foo # to avoid problems with ignore_patterns matching relfn = os.path.normpath(os.path.join(relpath, fn)) if any( fnmatch.fnmatch(relfn, ip) for ip in ignore_patterns): continue meta = readers.get_yamlfm(relfn) if meta is None: urubu_warn(_warning.no_yamlfm, fn=relfn) continue fileinfo = self.make_fileinfo(relfn, meta) self.filelist.append(fileinfo) self.process_info(fileinfo, self.site) # validate after file info has been added so it can be used self.validate_fileinfo(fileinfo) self.add_reflink(fileinfo['id'], fileinfo) if fn == 'index.md': index_found = True # start from fileinfo of index file navinfo = self.make_navinfo(relpath, fileinfo) self.navlist.append(navinfo) self.validate_navinfo(navinfo) self.add_reflink(navinfo['id'], navinfo) # add nav info to tag map self.add_info_to_tagmap(navinfo) else: content_found = True # add id for non-index files to tag tags self.add_info_to_tagmap(fileinfo) # a folder with content but no index is an error if content_found and not index_found: raise UrubuError(_error.no_index, msg='', fn=relpath)
def get_contentinfo(self): """Get info from the markdown content files.""" pattern = '*.md' ignore_patterns = self.get_ignore_patterns() for path, dirnames, filenames in os.walk(self.cwd): relpath = get_relpath(path, self.cwd) if any(fnmatch.fnmatch(relpath, ip) for ip in ignore_patterns): continue content_found = index_found = False for fn in filenames: if fnmatch.fnmatch(fn, pattern): # normalize to convert ./foo into foo # to avoid problems with ignore_patterns matching relfn = os.path.normpath(os.path.join(relpath, fn)) if any(fnmatch.fnmatch(relfn, ip) for ip in ignore_patterns): continue meta = readers.get_yamlfm(relfn) if meta is None: urubu_warn(_warning.no_yamlfm, fn=relfn) continue fileinfo = self.make_fileinfo(relfn, meta) self.filelist.append(fileinfo) self.process_info(fileinfo, self.site) # validate after file info has been added so it can be used self.validate_fileinfo(fileinfo) self.add_reflink(fileinfo['id'], fileinfo) if fn == 'index.md': index_found = True # start from fileinfo of index file navinfo = self.make_navinfo(relpath, fileinfo) self.navlist.append(navinfo) self.validate_navinfo(navinfo) self.add_reflink(navinfo['id'], navinfo) # add nav info to tag map self.add_info_to_tagmap(navinfo) else: content_found = True # add id for non-index files to tag tags self.add_info_to_tagmap(fileinfo) # a folder with content but no index is an error if content_found and not index_found: raise UrubuError(_error.no_index, msg='', fn=relpath)
def check_anchor_links(self): for info in self.filelist: for ar in info['_anchorrefs']: if not ar in self.anchors: urubu_warn(_warning.undef_anchor, msg=ar, fn=info['id'])
def check_anchor_links(self): for info in self.filelist: for ar in info['_anchorrefs']: if not ar in self.anchors: urubu_warn(_warning.undef_anchor, msg=ar, fn=info['id'] )