tensorflow / tensorboard

TensorFlow's Visualization Toolkit
Apache License 2.0
6.69k stars 1.66k forks source link

[Markdown Supports] Maths, Python code etc.. #2904

Open Rowing0914 opened 4 years ago

Rowing0914 commented 4 years ago

Hi,

Description

Thank you for providing us this great visualisation tool!! If possible, I'd like to make a Feature requrest regarding Markdown support on Tensorboard.

Currently, if you run the code below, you would get a super simple plot with a description next to the plot. But, unfortunatelly, Tensorboard doesn't render the text(in the code, description) as I use other Markdown editors, e.g., Typora. So, I'd like to know your thoughts on this feature request.

Sample Code

import tensorflow as tf

tf.compat.v1.enable_eager_execution()
writer = tf.compat.v2.summary.create_file_writer("./tmp/")

description = """

```python
print("hello world")

Table


Tables Are Cool
col 1 is left-aligned $1600
col 2 is centered $12
col 3 is right-aligned $1

sh push.sh

  1. asdf
  2. asdf

This is an example of an inline MathJax expression: \( 2 \times 2 = 4 \)

$\theta$,

$$ \theta $$

"""

with writer.as_default(): with tf.contrib.summary.always_record_summaries(): tf.compat.v2.summary.scalar(name="sample", data=tf.constant(1), step=0, description=description)



## Env
- OS: Ubuntu 18.04
- Python: 3.7.4
- TensorFlow: 1.14.0
- TensorBoard: 1.14.0

Sorry, since Github tries to render even the text in the python code, it doesn't look organised but I hope you'll get my point...
wchargin commented 4 years ago

Hi @Rowing0914! Thanks for the feature request. You’re correct that we don’t currently support MathJax or KaTeX, and we don’t have syntax highlighting. Fenced code blocks should render mostly correctly, except that the language tag will be treated as actual code. We use the PyPI markdown package for our Markdown parsing, and it looks like we might be able to fix the code blocks by enabling the fenced_code extension. KaTeX support would be an extra runtime dependency, but we can certainly consider that, too.

I’ll leave this open as a feature request; thanks!

Sorry, since Github tries to render even the text in the python code, it doesn't look organised but I hope you'll get my point...

Pro tip: you can use additional backticks to nest fenced code blocks, like this:

## Sample Code

``````python
import tensorflow as tf

tf.compat.v1.enable_eager_execution()
writer = tf.compat.v2.summary.create_file_writer("./tmp/")

description = """

```python
print("hello world")

Table

... """

with writer.as_default(): ...


## Env
- OS: ...
Rowing0914 commented 4 years ago

Hi @wchargin ,

Thank you for your prompt reply! I didn't know about the extra backticks technique,,, thank you for letting me know and editing my post!!

I am looking forward to the future dev so much!

Best,

Ir1d commented 4 years ago

Hi, is there any update on this feature request? I know these two plugins might help: Highlight for syntax highlight and Arithmatex for math parsing.

Rowing0914 commented 4 years ago

Hi, is there any update on this feature request? I know these two plugins might help: Highlight for syntax highlight and Arithmatex for math parsing.

Thank you for sharing, I will definitely have a look at those plugins!! Looks nice! Although I haven't got any notice, I hope they are somehow working on the improvement on this issue!!

nfelt commented 4 years ago

No update in terms of implementation.

As some context, we'd ultimately prefer to do our markdown rendering client-side in javascript (to avoid preprocessing overhead for markdown that the user doesn't actually ever see), but that's been blocked on arriving at a good enough HTML sanitizer story. Given that, I think we're unlikely to want to enable any Markdown extensions that only have a python implementation (especially those that involve extra pip package deps) since that wouldn't be portable.

The fenced code blocks are pretty standard and included in the existing markdown package, so if someone wants to send a PR that enables that extension I think we'd be happy to turn it on.