Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

strikethrough code in markdown on github

I am talking about github markdown here, for files like README.md.

Question: Is it possible to strikethrough a complete code block in markdown on github?

I know how to mark text as a block of code

this is multiline code 

and this

this

also

by indenting by 4 spaces or by using ``` or `...

I also know how to strike through texts using

  • del tag
  • s tag
  • ~~

Temporary solution:

Independently they work fine, but together not as expected or desired. I tried several combinations of the above mentioned.

For now, I use this:

striked

through

by using ~~ and ` for every single line.

Requirement:

I would like to have a code formatted text striked through, where the code block is continuous:

unfortunately, this is not striked through 

or at least with only a small paragraph in between:

unfortunately, also not striked through

Is this possible at all?

I found some old posts and hints on using jekyll, but what I was searching for is a simple way, preferably in markdown.

like image 304
rocksteady Avatar asked Dec 30 '16 10:12

rocksteady


People also ask

How do I strikethrough in GitHub Markdown?

Strikethroughs. In order to create a crossed-out text, use the tilde in Markdown twice in a row, followed by the respective text and then another two tildes. ~~This text is struckthrough.

How do you strike out text in Markdown?

The strikethrough is the line that we can create horizontally in the middle of the text like this strikethrough. The Markdown allows us to create the strikethrough by putting two tildes ~~ at the start of the line or word and two at the end, where we want to add the strikethrough.

Does Markdown have strikethrough?

Strikethrough in Markdown is used to create a horizontal line on the middle of the text. It is different from the underline command. The underline command creates a line below the text, while the strikethrough command creates a line in the middle of the text. We can use this command for any text.

How do you underline in GitHub Markdown?

Just use the HTML <u> tag (recommended) or the <ins> tag inside your markdown for this. The HTML tag <ins> is the HTML "insert tag", and is usually displayed as underlined.


2 Answers

This would only be possible with raw HTML, which GitHub doesn't allow. But you may be able to use a diff instead.

Code blocks are for "pre-formatted" text only. The only formatting you can get in a code block is the formatting that can be represented in plain text (indentation, capitalization, etc). There is no mechanism to mark up the content of a code block (as bold, italic, stricken, underlined, etc). This was an intentional design decision. Otherwise, how would you be able to show Markdown text in a code block? If you want formatted text, then you need to use something other than a code block.

As the rules state:

HTML is a publishing format; Markdown is a writing format. Thus, Markdown’s formatting syntax only addresses issues that can be conveyed in plain text.

For any markup that is not covered by Markdown’s syntax, you simply use HTML itself.

Therefore you would need to format your own custom HTML code block with the various bits marked up properly:

<pre><code><del>some stricken code</del> <del>A second line of stricken code</del> </pre></code> 

However, for security reasons, GitHub will strip out any such raw HTML in your Markdown. So while this works where you have full control of the entire stack, on a hosted service it is most likely not possible.

However, I'm assuming you want to show some changes made to a block of code. As it turns out, a specific format already exists for that, namely, a diff. Just use a fenced code block with diff as the language and GitHub will format it correctly:

```diff   Unchanged Line - Removed Line + Added Line ``` 

You can see how GitHub displays the above code block live (you can also see that in raw), but I've included a screenshot below for convenience.

enter image description here

I realize that the formatting does not use strike-through, but it does use a commonly used and understood format. For more complex blocks, you should probably use the diff utility program to generate the diff for you.

like image 113
Waylan Avatar answered Oct 03 '22 01:10

Waylan


Expanding on Waylan's answer:

This may be obvious to others, but it caught me. When you have indented lines, be sure + or - is the first character on the line or it won't highlight.

```diff <div>   Unchanged Line   <ul>     - <li>This won't work</li> -    <li>This will</li> +    <li>1st character, then indent</li>   </ul> </div> ``` 
like image 30
Jason Deppen Avatar answered Oct 03 '22 01:10

Jason Deppen