Coverage for e2xgrader/exporters/filters/highlight.py: 100%

7 statements  

« prev     ^ index     » next       coverage.py v7.4.2, created at 2024-03-14 13:22 +0100

1from nbconvert.filters.highlight import Highlight2HTML, _pygments_highlight 

2 

3 

4class Highlight2HTMLwithLineNumbers(Highlight2HTML): 

5 def __call__(self, source, language=None, metadata=None): 

6 """ 

7 Return a syntax-highlighted version of the input source as html output. 

8 Same as Highlight2HTML but with inline line numbers 

9 

10 Parameters 

11 ---------- 

12 source : str 

13 source of the cell to highlight 

14 language : str 

15 language to highlight the syntax of 

16 metadata : NotebookNode cell metadata 

17 metadata of the cell to highlight 

18 """ 

19 from pygments.formatters import HtmlFormatter 

20 

21 if not language: 

22 language = self.pygments_lexer 

23 

24 return _pygments_highlight( 

25 source if len(source) > 0 else " ", 

26 # needed to help post processors: 

27 HtmlFormatter(cssclass=" highlight hl-" + language, linenos="inline"), 

28 language, 

29 metadata, 

30 )