67

Is it possible to bold a portion of text within a code block in a github readme?

5 Answers 5

113

This answer on StackExchange Meta works on Github too:

Use a <pre> tag (or <pre><code>) instead of ```, and use <b> tags around the part you want bold.

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

7 Comments

Note: You cannot use <pre lang="..."> AND <b>. The syntax highlighting will take precedence!
I can confirm this solution works at least in StackOverflow. The source code was detected automatically and colores properly, combining correctly with the bold section.
This doesn't seem to work in the Markdown Preview Plus browser plug-in, though. I hate Markdown—it's so nonstandard (like HTML in the 1990s) and I keep having to resort to HTML to make basic stuff like this work.
@MichaelScheper I agree. Someone needs to publish a new comprehensive standard and keep it up to date. Perhaps it could start out as a collection of all the different standards and extensions out there, and gradually move from descriptive to prescriptive. Maybe you!
@linesarefuzzy: I'm so glad somebody else recognises this! Clearly, you are one smart developer, and would follow my standard if I developed it. 😉 But are you the influential type, too? Can you help me convince the world to follow it, and help prevent this? xkcd.com/927
|
4

No you cannot style your code snippet with bold/emphasis/italics.

You can always make comments explaining parts of the code, if that's what you want to achieve by emphasizing bits of your code.

1 Comment

Comments there is a good remark. Thank you a bunch!
4

You can also use:

`sample`**`sample`**`sample`

Output:

samplesamplesample

Comments

1

For inline code, seamlessly:

<code>normal <strong>bold</strong> more normal</code>

Turns into: normal bold more normal (Stack Overflow does a bad job, but Gi).

Comments

0

The suggestions here didn't work for me, because the text I wanted to show included tags like <ref>, so I can't put them inside a <code> block, because they get handled like part of the code. So instead, I gave up, typed my example into Microsoft Word, formatted it exactly like I wanted, then clipped it out of a screen shot.

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.