53

Is it possible to embed code snippets on Medium?

  • 2
    What about inline code snippets? – Joshua Pinter Mar 28 '16 at 17:37
52

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

  • 3
    Is there a way to enable syntax highlighting when inserting code like this? – DASKAjA Mar 20 '15 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 '15 at 3:00
  • 1
    @Anwar Medium has no support for inline code at this time unfortunately – John C May 8 '16 at 12:55
  • 1
    No button I'm afraid, just the keyboard shortcut @ShaharOr – John C Aug 9 '16 at 3:37
  • 1
    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: – igorsantos07 Dec 24 '16 at 3:10
32

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.

  • 1
    Looks like this is only possible for public gist's and does not work for secret gist's. – DASKAjA Jul 15 '15 at 10:14
  • 2
    Not true, see medium.com/@kirkstrobeck/… – Kirk Strobeck Oct 15 '15 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 '17 at 6:17
4

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

2

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

0

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

0

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
0

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

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, privacy policy and cookie policy

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