-
Notifications
You must be signed in to change notification settings - Fork 17.5k
Render list items in rendered fields view #22854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -483,20 +483,37 @@ def pygment_html_render(s, lexer=lexers.TextLexer): | |
| return highlight(s, lexer(), HtmlFormatter(linenos=True)) | ||
|
|
||
|
|
||
| def render(obj, lexer): | ||
| def render(obj: Any, lexer, handler=None): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to also annotate |
||
| """Render a given Python object with a given Pygments lexer""" | ||
| out = "" | ||
|
|
||
| if isinstance(obj, str): | ||
| out = Markup(pygment_html_render(obj, lexer)) | ||
| elif isinstance(obj, (tuple, list)): | ||
| return Markup(pygment_html_render(obj, lexer)) | ||
|
|
||
| if isinstance(obj, (tuple, list)): | ||
| out = "" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of repeatedly call def _render_parts(obj, lexer, handler):
...
yield Markup(...)
...
def render(obj, lexer, handler):
return "".join(_render_parts(obj, lexer, handler)) |
||
| for i, text_to_render in enumerate(obj): | ||
| if lexer == lexers.PythonLexer: | ||
| text_to_render = repr(text_to_render) | ||
|
|
||
| out += Markup("<div>List item #{}</div>").format(i) | ||
| out += Markup("<div>" + pygment_html_render(text_to_render, lexer) + "</div>") | ||
| elif isinstance(obj, dict): | ||
| return out | ||
|
|
||
| if isinstance(obj, dict): | ||
| out = "" | ||
| for k, v in obj.items(): | ||
| if lexer == lexers.PythonLexer: | ||
| v = repr(v) | ||
|
|
||
| out += Markup('<div>Dict item "{}"</div>').format(k) | ||
| out += Markup("<div>" + pygment_html_render(v, lexer) + "</div>") | ||
| return out | ||
| return out | ||
|
|
||
| if obj and handler: | ||
| return Markup(pygment_html_render(handler(obj), lexer)) | ||
|
|
||
| # Return empty string otherwise | ||
| return "" | ||
|
|
||
|
|
||
| def json_render(obj, lexer): | ||
|
|
@@ -536,8 +553,8 @@ def get_attr_renderer(): | |
| 'mysql': lambda x: render(x, lexers.MySqlLexer), | ||
| 'postgresql': lambda x: render(x, lexers.PostgresLexer), | ||
| 'powershell': lambda x: render(x, lexers.PowerShellLexer), | ||
| 'py': lambda x: render(get_python_source(x), lexers.PythonLexer), | ||
| 'python_callable': lambda x: render(get_python_source(x), lexers.PythonLexer), | ||
| 'py': lambda x: render(x, lexers.PythonLexer, get_python_source), | ||
| 'python_callable': lambda x: render(x, lexers.PythonLexer, get_python_source), | ||
| 'rst': lambda x: render(x, lexers.RstLexer), | ||
| 'sql': lambda x: render(x, lexers.SqlLexer), | ||
| 'tsql': lambda x: render(x, lexers.TransactSqlLexer), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably add CSS to style
h5instead of adding astrong? Or maybe this does not really matter at this point. cc @bbovenzi