Strikethrough code on markdown on github

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

Question: Is it possible to cross out the complete block of code in markdown on github?

I know how to mark text as a block of code

 this is multiline code 

and this

this

also

indent 4 spaces or with the help of `` or '...

I also know how to hit texts using

  • del tag
  • s tag
  • ~~

Workaround :

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

I am currently using this:

striked

through

using ~~ and `for each individual line.

Demand

I would like the text with the formatted code to scroll, where the block of code is continuous:

 unfortunately, this is not striked through 

or at least with a small paragraph between them:

unfortunately, also not striked through

Is this even possible?

I found some old posts and tips for using jekyll, but what I was looking for is an easy way, preferably in markdown.

+7
github markdown github-flavored-markdown strikethrough
source share
3 answers

This is only possible with raw HTML, which GitHub does not allow. But you can use diff instead.

Code blocks are for pre-formatted text only. The only formatting you can get in the code block is formatting, which can be represented as plain text (indentation, capitalization, etc.). There is no mechanism for marking up the contents of a code block (in bold, italics, broken, underlined, etc.). It was an intentional design decision. Otherwise, how could you show Markdown text in a block of code? If you want to format the text, you need to use something other than code.

Usually :

HTML - publication format; Markdown is a recording format. Thus, Markdowns formatting syntax resolves issues that can be transmitted as plain text.

For any markup that is not covered by Markdowns syntax, you simply use the HTML itself.

Therefore, you will need to format your own HTML block of code with various bits marked correctly:

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

However, for security reasons, GitHub will cross out any such raw HTML in your Markdown. Thus, although this works where you have full control over the entire stack, in a hosted service this is most likely not possible.

However, I assume that you want to show some changes made to the code block. As it turned out, a certain format already exists for this. Namely diff . Just use a fenced block of code 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 live code above (you can also see that in raw ), but for convenience I have added a screenshot below.

enter image description here

I understand that formatting does not use breakdown, but uses a widely used and understandable format. For more complex blocks, you should probably use the diff utility to generate diff for you.

+9
source share

Extension to Waylan Answer :

It may be obvious to others, but it caught me. If you have padding, make sure that + or - is the first character in the line or will not be highlighted.

 diff <div> Unchanged Line <ul> - <li>This won't work</li> - <li>This will</li> + <li>1st character, then indent</li> </ul> </div> 
+5
source share

As for labeling the contents of the code block, to bind an italic line to the end of the line of β€œcode”, try something like:

<code>id\_pn\_aside\_subscriber\_form\__form\_id_</code>

(You can see this in action at: https://github.com/devonostendorf/post-notif#how-do-you-use-the-stylesheet_filename-attribute-with-the-shortcode )

It was hard for me to find an example that matched this particular use case, so I hope this is useful to everyone who is trying to achieve a similar effect.

0
source share

All Articles