def parseImport(f, m): cssPath = filefilter.findFile(f, m.group(2) + '.css') scssPath = filefilter.findFile(f, m.group(2) + '.scss') if cssPath is None: if scssPath is None: return '/* Neither the .scss or the .css file was found. */' return '/* .scss file found but corresponding .css file not found */' handle = open(cssPath, 'r', encoding='utf8') content = handle.read(-1).strip() handle.close() return content
def parseResource(f, m): url = m.group(2) resource = filefilter.findFile(f, url) if resource is None: resource = filefilter.findFile(f, url.replace('posts-img/', 'posts/')) if resource is None: return m.group(0) # Don't modify anything f = open(resource, 'rb') content = f.read(-1) f.close() extension = '' if '.' in url: extension = url[url.rfind('.'):] url = url[:url.rfind('.')] url = url + '-res-' + hashlib.md5(content).hexdigest()[:8] + extension return m.group(1) + '/' + url + m.group(3)
def parseImport(f, m): if ':' in m.group(2): return requests.get(m.group(2)).text else: jsPath = filefilter.findFile(f, m.group(2)) if jsPath is None: print('No .js file was found.', file=sys.stderr) return '/* No .js file was found. */' handle = open(jsPath, 'r', encoding='utf8') content = handle.read(-1).strip() handle.close() return content
def processInclude(f, m): toInclude = filefilter.findFile(f, m.group(2).strip()) if toInclude is None: return '<span class="error">Could not include file ' + m.group(2).strip() + '</span>' isMarkdown = 'markdown' in m.group(1).lower() handle = open(toInclude, 'r', encoding='utf8') content = handle.read(-1) handle.close() if isMarkdown: content = rLinkMatch.sub(handleLink, content) content = markdown.Markdown( extensions=['codehilite', 'meta', 'sane_lists'], extensions_configs={}, output_format='html5', smart_emphasis=True ).convert(content) return filefilter.process(f, content)