#!/usr/bin/python import os import tempfile import pyperclip from pygments import highlight from pygments.lexers import get_lexer_by_name from pygments.formatters import ImageFormatter from pygments.formatters.img import PilNotAvailable # Definir lenguaje (sintaxis) lenguaje = get_lexer_by_name("python", stripall=True) # Recoger el codigo del Portapapeles codigo = pyperclip.paste() # fichero temporal para nombre unico y no sobreescribir fichero = tempfile.NamedTemporaryFile() fichero.name += '.png' # Generar la imagen img = highlight(codigo, lenguaje, ImageFormatter(style='native'), outfile=fichero.name) # Abrir la imagen generada os.system('open ' + fichero.name)