def html(self, renderer, settings): """ Call the right layout function from the renderer... """ renderer.settings = settings or {} html, _ = '', copy(renderer.settings) _ = self.control_character content = settings.replace(self.content) if _ in Config.nulls: html = '' elif _ in Config.setters: settings.read_settings_block(content) elif _ in Config.subheads: html = subhead_block(content, settings) elif _ in Config.quotes: html = quote_block(content, settings) elif _ in Config.notes: html = note_block(content, settings) elif _ in Config.caption: html = caption_block(content, settings) elif _ in Config.aligns: html = align_block(content, settings) elif _ in Config.lists: html = list_block(content, settings) elif _ in Config.tables: html = table_block(content, settings) elif _ in Config.glosses: html = gloss_block(content, settings) else: html = alert('Unrecognized control character: %s') return (html, settings)
def html(self, renderer): """ Get SVG for DOT content, embed in HTML. """ if len(self.options) < 1: self.options = [self._guess_format(self.text)] if len(self.options) > 1: return alert(self.syntax(renderer)) dot_format = self.options.pop() if dot_format == '': dot_format = self._guess_format(self.text) if dot_format not in self.acceptable_formats: return alert(self.syntax(renderer)) pattern = "<div classs=\"svg-wrapper\">%s</div>" return pattern % self._generate_svg(dot_format, self.text)
def _generate_svg(self, dot_format, dot_string): """ Perform the DOT system call, trimming first 6 lines; graphviz MUST be installed; see requirements_apt.txt; ONLY tested on *NIX. """ command = [ 'dot', '-K', dot_format, '-T' 'svg', '-Nfontname=Schoolbook', '-Nfontsize=11' ] file_in = dot_string.encode('utf-8') file_out = subprocess.run(command, stdout=subprocess.PIPE, input=file_in) result = file_out.stdout.decode('utf-8') parts = result.split('<svg', 1) if len(parts) == 2: img_tag = "<img src='data:image/svg+xml;utf8,<svg%s' />" html = img_tag % parts[1] return html return alert("Error generating SVG.")
def subhead_line(part): char, text = part if char == '@': return tag('p', text, 'subhead') else: return alert(content)
def note_line(part): char, text = part if char == '"': return tag('p', text, 'note') else: return alert(content)