Change code style

This commit is contained in:
cuom1999 2021-12-17 21:51:15 -06:00
parent 36f05abaeb
commit cd91db4e71
3 changed files with 35 additions and 6 deletions

View file

@ -27,11 +27,12 @@ else:
def wrap(self, source, outfile):
return self._wrap_div(self._wrap_pre(_wrap_code(source)))
def highlight_code(code, language, cssclass='codehilite'):
def highlight_code(code, language, cssclass='codehilite', linenos=True):
try:
lexer = pygments.lexers.get_lexer_by_name(language)
except pygments.util.ClassNotFound:
return _make_pre_code(code)
# return mark_safe(pygments.highlight(code, lexer, HtmlCodeFormatter(cssclass=cssclass, linenos='table')))
if linenos:
return mark_safe(pygments.highlight(code, lexer, HtmlCodeFormatter(cssclass=cssclass, linenos='table')))
return mark_safe(pygments.highlight(code, lexer, HtmlCodeFormatter(cssclass=cssclass)))

View file

@ -111,7 +111,7 @@ class SubmissionSource(SubmissionDetailBase):
submission = self.object
context['raw_source'] = submission.source.source.rstrip('\n')
context['highlighted_source'] = highlight_code(
submission.source.source, submission.language.pygments)
submission.source.source, submission.language.pygments, linenos=False)
return context

View file

@ -107,9 +107,9 @@
white-space: pre-wrap;
word-wrap: break-word;
margin: 1.5em 0 1.5em 0;
padding: 1em;
border: 1px solid $border_gray;
background-color: #f8f8f8;
padding: 0.5em;
padding-right: 0;
background-color: hsla(0,0%,92.5%,.5);
color: black;
border-radius: $widget_border_radius;
}
@ -184,6 +184,34 @@
margin-right: auto;
}
.codehilitetable {
.linenos {
width: 4%;
pre {
color: rgba(0,0,0,.26);
background-color: rgba(0,0,0,.07);
width: 100%;
span {
margin-left: 0.4em;
}
}
}
.code {
padding-left: 0.2em;
pre {
padding-left: 1em;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
}
width: 100%;
}
@media (min-width: 700px) {
#common-content {
display: flex;