77from markdown_it import MarkdownIt
88from tabulate import tabulate
99
10+ from ..utils import filter_warnings , in_context
11+ from .utils import propagate_fence_exception
1012
13+
14+ @in_context (filter_warnings (["error" ]))
15+ @propagate_fence_exception
1116def fence (
1217 source : str ,
1318 language : str ,
@@ -27,32 +32,26 @@ def fence(
2732
2833 classes [:0 ] = ["tsv-table" , "index" if linenums else "noindex" ]
2934
30- try :
31- df = pd .read_csv (
32- io .StringIO (source ),
33- sep = "\t " ,
34- dtype = str ,
35- index_col = False ,
36- keep_default_na = False ,
37- header = None if "noheader" in attrs else "infer" ,
38- )
39- md_table = tabulate (
40- df , # type: ignore
41- tablefmt = "github" ,
42- showindex = linenums ,
43- headers = "keys" ,
44- numalign = "right" ,
45- )
46- html = MarkdownIt ("commonmark" ).enable ("table" ).render (md_table )
47- if "noheader" in attrs :
48- html = re .sub ("<thead>.+</thead>" , "" , html , flags = re .DOTALL )
49-
50- html = html .replace ("<table>" , f'<table class="{ " " .join (classes )} ">' )
51-
52- # Remove newlines from HTML to prevent copy-paste from inserting spaces
53- return html .replace ("\n " , "" )
54- except Exception :
55- import traceback
56-
57- exc = traceback .format_exc ()
58- return f"<pre>{ exc } </pre>"
35+ df = pd .read_csv (
36+ io .StringIO (source ),
37+ sep = "\t " ,
38+ dtype = str ,
39+ index_col = False ,
40+ keep_default_na = False ,
41+ header = None if "noheader" in attrs else "infer" ,
42+ )
43+ md_table = tabulate (
44+ df , # type: ignore
45+ tablefmt = "github" ,
46+ showindex = linenums ,
47+ headers = "keys" ,
48+ numalign = "right" ,
49+ )
50+ html = MarkdownIt ("commonmark" ).enable ("table" ).render (md_table )
51+ if "noheader" in attrs :
52+ html = re .sub ("<thead>.+</thead>" , "" , html , flags = re .DOTALL )
53+
54+ html = html .replace ("<table>" , f'<table class="{ " " .join (classes )} ">' )
55+
56+ # Remove newlines from HTML to prevent copy-paste from inserting spaces
57+ return html .replace ("\n " , "" )
0 commit comments