3

In Markdown, how do you highlight code <--- just like that. I don't know how to search for it because I'm not sure what it's called. I also don't know what the little dashes are called either. I tried doing what I would do in SO, but it just reads it as normal text


Update:

This is what I have:

  • foo in SO it actually shows the hilighting
    • bar whereas in iPython Notebook, it doesn't, it only changes the fontstyle
5
  • 3
    Use backticks (`) to wrap your code for inline code blocks and triple backticks or minimum of four spaces indentation (depending which parser you are using) for full code blocks. Commented Sep 3, 2015 at 0:20
  • 1
    daringfireball.net/projects/markdown/syntax#code Commented Sep 3, 2015 at 0:22
  • 1
    @Terry I tried using backticks in a list, but it didn't work. The font looks different, but it doesn't highlight it like it does in stackoverflow or like i've seen on some blogs Commented Sep 3, 2015 at 0:22
  • 1
    @AlanH Can you reproduce your issue here, or share the code that is problematic? Also, if all fails you can always fall back to using HTML, i.e. <code>—it would also work for Markdown. Commented Sep 3, 2015 at 0:27
  • @AlanH, you're not really "highlighting" code here, either. You're generating <code> tags which are a semantic way of representing source code. Stack Overflow happens to add a grey background to <code>, but that's incidental. If they chose to change the way they styles these tags tomorrow, they could. There is nothing inherent in backticks that suggests highlighting. Commented Sep 3, 2015 at 12:34

3 Answers 3

5

You're making <\code> sections. They're not styled the same way as SO. Add this cell to a notebook and they will have a similar style.

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

If you want more specificity then use .rendered_html code{... in a custom style sheet.

Sign up to request clarification or add additional context in comments.

Comments

2

Late answer but backtick ` is the way to go, just like here at SO.

Comments

0

In short: Use <code> tag

In normal cases backticks work for highlighting text but are printed as literal characters when inside html lists.

A part of tensorflow tutorial written using markdown

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>

Output

(As seen in jupyter notebook)

Training the neural network model requires the following steps:

  1. Feed the training data into the model. In this example, the training data is in the train_images and train_labels arrays.
  2. The model learns to associate the images and labels.
  3. You ask the model to make predictions about a test set -- in this example the test_images array.
  4. Verify the predictions match the labels from the test_labels array.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.