3/20/2023 0 Comments Django rest frameworkstyle, linenos = linenos, full = True, ** options ) self. linenos else False options = formatter = HtmlFormatter ( style = self. TextField () # new class Meta : ordering = ( "created" ,) def save ( self, * args, ** kwargs ): # new """ Use the `pygments` library to create a highlighted HTML representation of the code snippet. ForeignKey ( "auth.User", related_name = "snippets", on_delete = models. CharField ( choices = STYLE_CHOICES, default = "friendly", max_length = 100 ) owner = models. CharField ( choices = LANGUAGE_CHOICES, default = "python", max_length = 100 ) style = models. BooleanField ( default = False ) language = models. CharField ( max_length = 100, blank = True, default = "" ) code = models. DateTimeField ( auto_now_add = True ) title = models. # snippets/models.py from django.db import models from pygments import highlight # new from import HtmlFormatter # new from pygments.lexers import get_all_lexers, get_lexer_by_name # new from pygments.styles import get_all_styles LEXERS = ] LANGUAGE_CHOICES = sorted (, item ) for item in LEXERS ]) STYLE_CHOICES = sorted (( item, item ) for item in get_all_styles ()) class Snippet ( models. So we'll need some additional imports as well as a. We also want to ensure that when the model is saved, we use the pygments code highlighting library to populate our highlighted field.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |