iPython Notebook中的Markdown:如何突出显示代码?

时间:2015-09-03 00:15:17

标签: syntax markdown ipython-notebook

在Markdown中,你如何highlight code< ---就像那样。我不知道如何搜索它,因为我不确定它叫什么。我也不知道这些小破折号是什么。我尝试过做我在SO中做的事情,但它只是将其视为普通文本

更新

这就是我所拥有的:

  • foo在SO中它实际上显示了朦胧
    • bar而在iPython Notebook中,它不会改变fontstyle

3 个答案:

答案 0 :(得分:5)

您正在制作< \ code>部分。它们的风格与SO不同。将此单元格添加到笔记本中,它们将具有类似的样式。

%%HTML
<style> code {background-color : lightgrey !important;} </style>

如果您想要更具体,请在自定义样式表中使用.rendered_html code{...

答案 1 :(得分:1)

迟到的答案,但反引号 `是要走的路,就像在这里一样。

答案 2 :(得分:0)

简而言之:使用<code>标签

在通常情况下,反引号适用于highlighting文本,但是在html列表中时会以打印为文字字符

使用markdown编写的tensorflow tutorial的一部分

Training the neural network model requires the following steps:

<ol>
    <li>Feed the training data into the model. In this example, the training data is in the <code>train_images</code> and <code>train_labels</code> arrays.</li>
    <li>The model learns to associate the images and labels.</li>
    <li>You ask the model to make predictions about a test set -- in this example the test_images array.</li>
    <li>Verify the predictions match the labels from the <code>test_labels</code> array.</li>
</ol>

输出

(在jupyter笔记本中看到)

训练神经网络模型需要执行以下步骤:

  1. 将训练数据输入模型。在此示例中,训练数据位于train_imagestrain_labels数组中。
  2. 模型学习将图像和标签关联起来。
  3. 您要求模型对测试集进行预测-在此示例中为test_images数组。
  4. 验证预测是否与test_labels数组中的标签匹配。