7

How can I strike through a code part (within code block) at Stack Overflow? Is that possible?

10
<!-- language: lang-default -->

<pre><code>System.Out.Println("<s>hello</s> world");
</code></pre>

Which turns into:

System.Out.Println("hello world");

You can put any valid markdown there, including <b>bold</b>, <i>italics</i> and even links. You do need to remember to include the <code> tags inside <pre> for syntax highlighting to work. The language: comment before the code block, however, is only needed here on Meta, or if you want to override the automatic choice of which highlighting rules to apply.

  • 1
    <b> and <i> also work within the code tag. Care is needed in combination with the <pre> tag to avoid stray gray space around the code block. – user213963 Nov 17 '15 at 15:54
  • @MichaelT thanks, I never used it myself to be honest, just saw it mentioned here from time to time. – Shadow The Princess Wizard Nov 17 '15 at 16:01
  • 1
    I've used it on rare occasions (example) when I want to be able to highlight a specific block of code and need to get into the html side rendering rather than markdown rendering... and that causes all sorts of fun with &lt; rather than < and future additional overhead in editing (if someone adds a < it breaks everything and they don't know why). – user213963 Nov 17 '15 at 16:06
  • 2
    Good thing to note is that no syntax highlighting when using the <pre> tag. – Zizouz212 Nov 17 '15 at 20:29
  • @Zizouz212 good point, added to the answer. Thanks! :) – Shadow The Princess Wizard Nov 17 '15 at 20:40
  • 4
    @Zizouz212: Actually, syntax highlighting does work, as long as you remember to use <pre><code> instead of just <pre>; see edit above. – Ilmari Karonen Nov 17 '15 at 20:54

You must log in to answer this question.