If you write about programming topics (if not, start now, writing makes you a better programmer), you often need to include code snippets in your posts. Let’s reviews what are the best tools for creating và sharing your own source code snippets online. We’ll use this simple PHP. code excerpt as an example in the rest of the post.
Bạn đang xem: Free source code
Let’s see what are the best alternatives to lớn nói qua a code excerpt online.
The simplest choice: Code as text
The simplest solution is lớn just copy và paste the code in your (WordPress) post editor surrounded by a pair of HTML tags.
The advantage is that this way the code stays within your site, it can be indexed together with the post và you can easily modify it at any time. The main nhỏ is that the visualization of the code is rather ugly và that there is no easy way to nói qua the code itself separately from the post.
Visualization can be improved by using a third-các buổi tiệc nhỏ plugin. In this blog, I use WP-syntax (rather old but still working). It provides clean syntax highlighting using GeSHi — supporting a wide range of popular languages.
An example of PHP code directly embedded in this post
|$day_parsed=date_parse($today->format("Ymd"));$args = array("post_type" => "post","post_status" => "any", // we also want the drafts"nopaging"=>true,"date_query" => array("relation" => "OR",array( // returns posts created today"year" => $day_parsed<"year">,"month" => $day_parsed<"month">,"day" => $day_parsed<"day">,),array( // returns posts modified today"column" => "post_modified","year" => $day_parsed<"year">,"month" => $day_parsed<"month">,"day" => $day_parsed<"day">,),));$query_day_posts = new WP_Query( $args );$posts=$query_day_posts->get_posts();|
Nothing really spectacular but if you just have sầu something small lớn show & don’t need lớn reuse it in other contexts, this works well enough.
The obvious choice: Gists
Gists are GitHub’s solution for sharing your code online. Every gist is a Git repository và therefore they can be forked & cloned as any other GitHub project. If your software project is already hosted on GitHub, Gists are a natural choice. But you can use Gist even if your project is hosted elsewhere.
See our PHP sample code as a Gist
Code as beautiful images
Carbon helps you transkhung any piece of code in a coloured image. Plenty of themes, fonts & colors are available. Carbon also recognizes your language and uses the language grammar lớn detect và higlight từ khóa and other special characters.
Xem thêm: mẹ bầu hay khóc
Once you’re done you can export the generated image and paste it in your post or nói qua it on social truyền thông media (in fact, you can directly tweet it from Carbon itself). By the way, Carbon itself is open source software. Obviously, in contrast with the two previous solutions, here you’ll need to lớn regenerate the image every time the source code you’re sharing changes.
Our sample code in Carbon
CodeZen is almost an exact replica of Carbon. You can show the line numbers so if this is important for you, give sầu it a try.
CodeGraphics is another similar tool. Here the difference is that CodeGraphics allows you to lớn enter additional text above sầu và below the code snippet.
Instead, Marmophối goes beyond previous tools & allows you khổng lồ add a huge number of filters & special effects to lớn your code (see below). Obviously, if you want the code lớn be readable, this tool may not be the best option. However, if you want to lớn make some spectacular representation of the code, experiment with this tool!.
Marmomix interface to add special effects to your code displays
The VS Code solution to mô tả code snippets
Given the huge popularity of the Visual Studio Code editor , it’s not a surprise lớn find an extension in the VS Code marketplace lớn share code: Polacode, the polaroid for your code.
It’s (on purpose) a very simple extension that, in short, allows you khổng lồ easily take a kind of “screenshot” of code you’re editing và store it as an image.
BONUS: Create a poster from your source code
Not exaclty the most convenient way lớn cốt truyện your code, but if your goal is more to display your code as a work of art (you know, some people believe programming is, more than anything, an artistic endeavour), take a look at commits.io.
Xem thêm: Dowload Tài Liệu Hướng Dẫn Sử Dụng Phần Mềm Zkbio Access Module (10 Door)
For a modic price you’ll be able khổng lồ point to your code, choose a background image và create (and get delivered) something lượt thích this.
Submit a Comment Cancel reply
Your email address will not be published. Required fields are marked *