The website content provides guidance on formatting code in Medium articles, including inline code, larger code blocks, and embedding GitHub Gists.
Abstract
The article "How to Format Code on Medium" outlines three primary methods for code formatting within Medium posts. For inline code snippets, the author advises using the backtick key to highlight code within paragraphs. When more extensive code examples are necessary, the article instructs on creating larger code blocks using specific key combinations or three backticks. Additionally, the article emphasizes the use of GitHub Gists for embedding code, which maintains syntax highlighting and allows for updates that automatically reflect in the article. The author also promotes their free Medium course and an AI service for content creation, suggesting a commitment to enhancing the reader's writing experience on Medium.
Opinions
The author believes that using GitHub Gists is a superior method for adding code to articles, as it preserves formatting and allows for easy updates.
Inline code formatting is presented as a simple and effective way to include code within text for quick references.
The author suggests that using the "Paste and Match Style" option when pasting code can help maintain the original formatting, indicating a preference for clean and readable code blocks.
The article implies that the use of GitHub Gists may be a requirement for programming articles in certain Medium publications, highlighting a standard practice within the community.
By offering a free Medium course and recommending an AI service, the author expresses a commitment to providing value to readers and supporting their growth as writers on the platform.
How to Format Code on Medium
Learn three most common ways to format code in your Medium articles
To format code inside a paragraph inline like this: <h1>Hello</h1>, simply highlight the code and press the backtick (`) key:
Remember: Inline code cannot be added to headings, quotes, or image captions.
👉 Join my Free Medium Course to learn how to grow your followers, reads, and earn more.
How to Create a Bigger Code Block
If inline code is not enough for your purposes, you can also create a bigger block of code like this:
while(1 < 2) {
print("Hello, world!")
}
To create a block of code, press one of these key combinations depending on your system:
Windows: ctrl+alt+6
Mac: command+option+6
Linux: ctrl+alt+6
OR type three backticks (```) in a new line to start a new code block and start typing code.
Hint: If you’re copy-pasting code from an editor, you may lose code formating, i.e. indentations and line breaks, etc. To fix this, you can use the Paste and Match Style property by right-clicking the code block when pasting:
Github Gists
This is a very common way to add chunks of code to your article.
Embedding your code as a Github Gist preserves the code style e.g. syntax highlighting, indentations, etc:
Furthermore, if you need to make changes to the code in the gist, the changes will automatically be reflected in the article.
Also, some publications accept programming articles only if Github Gists are used when embedding code.