57

Is it possible to embed code snippets on Medium?

1
  • 2
    What about inline code snippets? Mar 28, 2016 at 17:37

8 Answers 8

55

You can add a code block by using Ctrl + Alt + 6 (or + Alt + 6 on Mac)

Source: https://medium.com/help-center/writing-128f049a7ad#b41a

8
  • 3
    Is there a way to enable syntax highlighting when inserting code like this?
    – DASKAjA
    Mar 20, 2015 at 15:46
  • 2
    I've only looked briefly, but it doesn't look like it. You might be better off asking in a separate question rather than here though.
    – John C
    Mar 21, 2015 at 3:00
  • 1
    @Anwar Medium has no support for inline code at this time unfortunately
    – John C
    May 8, 2016 at 12:55
  • 1
    No button I'm afraid, just the keyboard shortcut @ShaharOr
    – John C
    Aug 9, 2016 at 3:37
  • 2
    why the hell something used a lot by coders around there doesn't sport a simple freaking button for this formatting option? Why's it a hidden feature? What other hidden features are there? :thinking_face: Dec 24, 2016 at 3:10
33

Medium also supports github gists which include syntax highlighting.

A lot of folks have asked for GitHub gist support. Now we have it. Simply paste your gist URL into your Medium story and hit return.

You can still also highlight text and hit command-6 for code snippets. Ctrl-6 on Windows.

3
  • 1
    Looks like this is only possible for public gist's and does not work for secret gist's.
    – DASKAjA
    Jul 15, 2015 at 10:14
  • 2
    Not true, see medium.com/@kirkstrobeck/… Oct 15, 2015 at 17:21
  • As I found we would need to use the JavaScript URL from the Gist embedded code to make this work.
    – imesh
    Feb 26, 2017 at 6:17
4

just use the ``` to create a new code block.

1
  • How about the comment section?
    – Dr.jacky
    Nov 8, 2020 at 14:55
2

I found the help article here: https://help.medium.com/hc/en-us/articles/224550008-Code-blocks-inline-code

Basically:

  1. type ``` or ` (triple or single backtick) in new line will trigger code block or inline code accordingly. (the keyboard shortcut mentioned by others works too)
  2. For syntax highlighting, it suggests Github Gists, Codepen.io, or JSfiddle
2

Yes. You can also go to gist.github.com . Type/paste your code there and paste the link in Medium, then press enter.

1

If you want to embed full working code, you can use https://www.codiva.io. Codiva is registered as an embedly provider, so just paste the project URL, medium-embedly-codiva will do the remaining magic. Codiva supports Java, C and C++. For example, https://medium.com/@jayaprabhakar/poorly-researched-clickbait-articles-in-dzone-cca19d1d0999

0

Copy/paste code from editors like Webstorm or VS Code. It should create a code block.

0

You can also add a code block by typing ``` (three backticks) on a new line, or create an inline bit of code by typing a single backtick at the beginning and end of the code. (Or select the text, and type a single backtick).

Source: https://help.medium.com/hc/en-us/articles/225168768-Write-post

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.