def _generate(self, source): content = [] content.append( blocks.Html([ '<!DOCTYPE html>', '<html>', '<head>', '<title>{}</title>'.format(self._title), '<link rel="stylesheet" href="style.css">', '<link rel="stylesheet" href="highlight.css">', '<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">', '<script src="marked.js"></script>', '<script src="script.js"></script>', '<script src="highlight.js"></script>', '<script>hljs.initHighlightingOnLoad();</script>', MATHJAX_SCRIPTS, '</head>', '<body>', '<article>', ])) content.append(blocks.Code()) excluding = False # Range exclude. for lineno, line in enumerate(source.split('\n')): lineno += 1 # Line numbers are 1-based indices. line = line.rstrip() if isinstance(content[-1], blocks.Code) and line.startswith('"""'): line = line[3:] content.append(blocks.Text()) if isinstance(content[-1], blocks.Text) and line.endswith('"""'): line = line[:-3] content[-1].append(line) content.append(blocks.Code()) continue if isinstance(content[-1], blocks.Text): content[-1].append(line) elif line == '# handout: begin-exclude': excluding = True elif line == '# handout: end-exclude': excluding = False elif excluding: pass elif line.endswith('# handout: exclude'): pass else: content[-1].append(line) blocks_ = self._blocks[lineno] if blocks_: for block in blocks_: content.append(block) content.append(blocks.Code()) content.append(blocks.Html([ '</article>', '</body>', '</html>', ])) return ''.join(block.render() for block in content)
def _generate(self, source): content = [blocks.Html([ '<!doctype html>', '<html lang="zh-cn">', '<head>', '<meta charset="UTF-8">', '<meta name="viewport" content="width=device-width, initial-scale=1.0">', '<meta http-equiv="X-UA-Compatible" content="ie=edge">', '<title>{}</title>'.format(self._title), '<link rel="stylesheet" href="style.css">', '<link rel="stylesheet" href="highlight.css">', '<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">', '<script src="marked.js"></script>', '<script src="script.js"></script>', '<script src="highlight.js"></script>', '<script>hljs.initHighlightingOnLoad();</script>', '</head>', '<body>', '<article>', ]), blocks.Code()] for lineno, line in enumerate(source.split('\n')): lineno += 1 # Line numbers are 1-based indices. line = line.rstrip() if isinstance(content[-1], blocks.Code) and line.startswith('"""'): line = line[3:] content.append(blocks.Text()) if isinstance(content[-1], blocks.Text) and line.endswith('"""'): line = line[:-3] content[-1].append(line) content.append(blocks.Code()) continue if not line.endswith('# handout: exclude'): content[-1].append(line) blocks_ = self._blocks[lineno] if blocks_: for block in blocks_: content.append(block) content.append(blocks.Code()) content.append(blocks.Html([ '</article>', '</body>', '</html>', ])) return ''.join(block.render() for block in content)
def _generate(self, source): content = [] content.append( blocks.Html([ '<html>', '<head>', '<title>Handout</title>', '<link rel="stylesheet" href="style.css">', '<link rel="stylesheet" href="highlight.css">', '<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">', '<script src="marked.js"></script>', '<script src="script.js"></script>', '<script src="highlight.js"></script>', '<script>hljs.initHighlightingOnLoad();</script>', '</head>', '<body>', '<article>', ])) content.append(blocks.Code()) for lineno, line in enumerate(source.split('\n')): lineno += 1 # Line numbers are 1-based indices. line = line.rstrip() if isinstance(content[-1], blocks.Code) and line.startswith('"""'): line = line[3:] content.append(blocks.Text()) if isinstance(content[-1], blocks.Text) and line.endswith('"""'): line = line[:-3] content[-1].append(line) content.append(blocks.Code()) continue if not line.endswith('# handout=exclude'): content[-1].append(line) blocks_ = self._blocks[lineno] if blocks_: for block in blocks_: content.append(block) content.append(blocks.Code()) content.append(blocks.Html([ '</article>', '</body>', '</html>', ])) return ''.join(block.render() for block in content)
def add_html(self, string, show=False): block = blocks.Html([string]) self._pending.append(block) self._logger.info(string) if show: self.show()
def html(self, string): block = blocks.Html([string]) self._blocks[self._get_current_line()].append(block) self._logger.info(string)
def add_html(self, string): block = blocks.Html([string]) self._pending.append(block) self._logger.info(string)