在Markdown中的`
`标签内的Python代码。

huangapple go评论97阅读模式
英文:

python code inside details tag in markdown

问题

  1. <details>
  2. <summary><font size="4" color="darkred"><b>我的解决方案</b></font></summary>
  3. ```python
  4. import math
  5. %matplotlib inline
  6. plt.xlabel('三角形的面积')
  7. ```
  8. </details>
  9. ---
  10. 生成的代码片段在执行时不反映Python语法高亮
  11. (我不打算运行Python代码,只是为了隐藏和显示)
英文:

Hi I am using jupyter notebooks in sphinx to create documentation. Below is the code, i want to toggle for hide/show using details tag in a markdown cell.


  1. <details>
  2. <summary><font size="4" color="darkred"><b>My Solution</b></font></summary>
  3. ```python
  4. import math
  5. %matplotlib inline
  6. plt.xlabel('Area of triangle')
  7. ```
  8. </details>

The resulant snippet doesn't reflect python highlighting on execution
(I don't intend to run the python code, it is just to hide and show)

答案1

得分: 0

尝试这个。https://gist.github.com/pierrejoubert73/902cc94d79424356a8d20be2b382e1ab。
你的代码看起来是正确的,但也许在Jupyter笔记本中,你忘了选择Markdown选项?

英文:

Try this. https://gist.github.com/pierrejoubert73/902cc94d79424356a8d20be2b382e1ab.
Your code looks correct but maybe in Jupiter notebook are you missing to choose markdown option?

答案2

得分: 0

Point1: 需要在<summary>行后插入换行,即在<summary>行后添加空行

Point 2: 第二个问题是缩进。我不知道为什么,但当我使用少于4个空格来缩进python &#39;''python行时,它起作用。

要使用包含python块的嵌套隐藏/显示的details标签

我正在将更正后的代码图片添加如下:正确代码

英文:

Point1: There need to be an linebreak, i.e. an empty line after &lt;summary&gt; line

Point 2: The second problem is the indentation. I don't know why, but when I used less than 4 white spaces to indent the python &#39;''python line, it worked.

  1. &lt;details&gt;
  2. &lt;summary&gt;&lt;font size=&quot;4&quot; color=&quot;darkred&quot;&gt;&lt;b&gt;My Solution&lt;/b&gt;&lt;/font&gt;&lt;/summary&gt;
  3. ```python
  4. import math
  5. %matplotlib inline
  6. plt.xlabel(&#39;Area of triangle&#39;)
  7. ```
  8. &lt;/details&gt;

To use details tag with nested hide/show containing python blocks

  1. &lt;details&gt;
  2. &lt;summary&gt;&lt;font size=&quot;4&quot; color=&quot;darkred&quot;&gt;&lt;b&gt;My Solution&lt;/b&gt;&lt;/font&gt;&lt;/summary&gt;
  3. ```python
  4. import math
  5. %matplotlib inline
  6. plt.xlabel(&#39;Area of triangle&#39;)
  7. ```
  8. &lt;details&gt;
  9. &lt;summary&gt;&lt;font size=&quot;2&quot; color=&quot;Blue&quot;&gt;&lt;b&gt;See hints&lt;/b&gt;&lt;/font&gt;&lt;/summary&gt;
  10. ```python
  11. import math
  12. %matplotlib inline
  13. plt.xlabel(&#39;Area of triangle&#39;)
  14. ```
  15. &lt;/details&gt;
  16. &lt;/details&gt;

I am adding the image of the corrections below:Correct code

huangapple
  • 本文由 发表于 2023年7月6日 14:46:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76626147.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定