コード例 #1
0
    def print(self, pprint=True):
        """Print to screen (similar to __repr__ but with colors)"""
        lines = [click.style('# Note', fg='green')]

        types = ', '.join({['new', 'learning', 'review', 'relearning'][c.type]
                           for c in self.n.cards()})

        lines += [
            click.style('nid: ', fg='yellow') + f'{self.n.id}' +
            click.style('    card type(s): ', fg='yellow') + types
        ]

        lines += [
            click.style('model: ', fg='yellow') +
            f'{self.model_name} ({len(self.n.cards())} cards)'
        ]

        if self.a.n_decks > 1:
            lines += [click.style('deck: ', fg='yellow') + self.get_deck()]

        lines += [click.style('tags: ', fg='yellow') + self.get_tag_string()]

        flags = [c.template()["name"] for c in self.n.cards() if c.flags > 0]
        if flags:
            flags = [click.style(x, fg='magenta') for x in flags]
            lines += [
                f"{click.style('flagged:', fg='yellow')} {', '.join(flags)}"
            ]

        if not any([is_generated_html(x) for x in self.n.values()]):
            lines += [f"{click.style('markdown:', fg='yellow')} false"]

        if self.suspended:
            lines[0] += f" ({click.style('suspended', fg='red')})"

        lines += ['']

        latex_imgs = []
        for key, html in self.n.items():
            # Render LaTeX if necessary
            latex.render_latex(html, self.n.model(), self.a.col)
            latex_imgs += _get_imgs_from_html_latex(html, self.a,
                                                    self.n.model())

            lines.append(click.style('## ' + key, fg='blue'))
            lines.append(html_to_screen(html, pprint))
            lines.append('')

        if latex_imgs:
            lines.append(click.style('LaTeX sources', fg='blue'))
            for line in latex_imgs:
                lines.append('- ' + str(line))
            lines.append('')

        click.echo('\n'.join(lines))
コード例 #2
0
ファイル: note.py プロジェクト: ckp95/apy
    def print(self):
        """Print to screen (similar to __repr__ but with colors)"""
        lines = [
            click.style(f'# Note ID: {self.n.id}', fg='green'),
            click.style('model: ', fg='yellow')
            + f'{self.model_name} ({len(self.n.cards())} cards)',
        ]

        if self.a.n_decks > 1:
            lines += [click.style('deck: ', fg='yellow')+self.get_deck()]

        lines += [click.style('tags: ', fg='yellow')
                  + self.get_tag_string()]

        if not any([is_generated_html(x) for x in self.n.values()]):
            lines += [f"{click.style('markdown:', fg='yellow')} false"]

        if any([c.flags > 0 for c in self.n.cards()]):
            lines += [f"{click.style('flagged', fg='red')}"]

        if self.suspended:
            lines[0] += f" ({click.style('suspended', fg='red')})"

        lines += ['']

        latex_imgs = []
        for key, html in self.n.items():
            # Render LaTeX if necessary
            latex.render_latex(html, self.n.model(), self.a.col)
            latex_imgs += self.get_lateximg_from_field(html)

            lines.append(click.style('## ' + key, fg='blue'))
            lines.append(html_to_screen(html))
            lines.append('')

        if latex_imgs:
            lines.append(click.style('LaTeX sources', fg='blue'))
            for line in latex_imgs:
                lines.append('- ' + str(line))
            lines.append('')

        click.echo('\n'.join(lines))
コード例 #3
0
def note_loaded(editor):
    items = editor.note.items()
    model = editor.note.model()
    col = editor.note.col
    fldContentTexProcessed = [
        editor.mw.col.media.escapeImages(render_latex(val, model, col))
        for fld, val in items
    ]
    dumped = json.dumps(fldContentTexProcessed)
    editor.web.eval(f"""set_texs({dumped});""")
    editor.web.eval(f"on_focus_field(0);")
コード例 #4
0
def onBridgeCmd(handled, message, editor):
    if isinstance(editor, Editor) and message.startswith("blur"):
        ord = onBlur(editor, message)
        val = editor.note.fields[int(ord)]
        fldContent = editor.mw.col.media.escapeImages(val)
        fldContentTexProcessed = editor.mw.col.media.escapeImages(
            render_latex(val, editor.note.model(), editor.note.col))
        s = f"set_tex({ord}, {json.dumps(fldContent)}, {json.dumps(fldContentTexProcessed)});"
        editor.web.eval(s)
        return (True, None)
    # Handling does not actually change. Actual work for blur must still be done
    return handled
コード例 #5
0
ファイル: media.py プロジェクト: humbatoa/anki
 def filesInStr(
     self, mid: int, string: str, includeRemote: bool = False
 ) -> List[str]:
     l = []
     model = self.col.models.get(mid)
     # handle latex
     string = render_latex(string, model, self.col)
     # extract filenames
     for reg in self.regexps:
         for match in re.finditer(reg, string):
             fname = match.group("fname")
             isLocal = not re.match("(https?|ftp)://", fname.lower())
             if isLocal or includeRemote:
                 l.append(fname)
     return l
コード例 #6
0
ファイル: media.py プロジェクト: mgmanzella/anki
 def filesInStr(self,
                mid: Union[int, str],
                string: str,
                includeRemote: bool = False) -> List[str]:
     l = []
     model = self.col.models.get(mid)
     if model["type"] == MODEL_CLOZE and "{{c" in string:
         # if the field has clozes in it, we'll need to expand the
         # possibilities so we can render latex
         strings = self.col.backend.expand_clozes_to_reveal_latex(string)
     else:
         strings = string
     # handle latex
     string = render_latex(string, model, self.col)
     # extract filenames
     for reg in self.regexps:
         for match in re.finditer(reg, string):
             fname = match.group("fname")
             isLocal = not re.match("(https?|ftp)://", fname.lower())
             if isLocal or includeRemote:
                 l.append(fname)
     return l