How can I make a word in a code sample bold? I only see asterisks around the expected bold text.
sample **sample** sample
How can I make a word in a code sample bold? I only see asterisks around the expected bold text.
sample **sample** sample
Use <pre>
formatting and HTML tags.
<pre>
sample <b>sample</b> sample
</pre>
Gives:
sample sample sample
Since you can use other HTML tags as well, this is nice for including inline documentation for commands or classes, etc.:
<pre>
<i><a href="http://manpages.ubuntu.com/manpages/dapper/man1/prename.1.html">rename</a></i> ’s/\.bak$//’ *.bak
</pre>
Gives:
rename 's/\.bak$//' *.bak
But, with any formatting tricks, please don't overdo it.
<pre>
approach just pushes to a second line and ruins the formatting. Is there a way around this?
Commented
Nov 16, 2015 at 21:06
<span class="pre">
instead of <code>
, and some parsers add additional CSS classes to <pre>
. If you don't match what the parser produces, the formatting of the code may be different than normal backtick code.
Disclaimer: I do not condone this, I'm just pointing out a possibility (for the sake of completion)
The basic idea is to apply bold/italic formatting to backtick-enclosed string (instead of applying within the backticks), then put the code spans side by side so that they render as a single code span.
Huge drawback: no syntax highlighting
Bold formatting
> `sample`**`sample`**`sample`
outputs as:
sample
sample
sample
Italics formatting
> *`rename`*`'s/\.bak$//' *.bak`
outputs as:
rename
's/\.bak$//' *.bak
Bold formatting
`one`**`two`**`three`
outputs as
one
two
three
Bold and italics side by side
`one`**`two`***`three`*
outputs as
one
two
three
You need a non-printing character or a zero-width character (e.g. zero width space ​
) to separate the markdown for bold and markdown for italics.
When you line up two code spans (with different formatting) side by side, there is always a space in between.
So it's not possible to apply say bold formatting to a string within double quotes like print "Hello world";
without a space between the string and quotes.
`print "`**`Hello world`**`";`
would render as
print "
Hello world
";
Others (left as exercise to the reader)
Make it an actual quote instead of a code fragment, by prefixing the text with >
instead of four spaces.
The following markdown:
> sample **sample** sample
Gives:
sample sample sample