Do you write blog-posts about programming and software development? Great! That means you’re sharing your knowledge with fellow developers. In your technical post, you’ll want to include source code snippets. And of course, you want your source code to work. But when you co-develop your post and your code, your code is not yet finished when you start writing. When the source code changes, the struggle of keeping the snippets up-to-date begins. It’s a challenge but there is a way out.

Let’s dive in!

Let’s say that this is the source code of your index.ts:

/**
 * @helloTag
 * Call `sayHello` to greet a person by her name.
 */
function sayHello (name: string) {
 return `Hello ${name}!` 
}

With Publishable, you can refer to your code in your article (in Markdown):

Have a look at the source code: 
<Source source="index" tag="helloTag"/> 
<Comment source="index" tag="helloTag"/>

This is the result (in Markdown):

function sayHello (name: string) {
return Hello ${name}!
}

Call `sayHello` to greet a person by her name.

And this is the rendered result (it looks different depending on the renderer):

Image for post

Screenshot taken from Publishable

#web-development #javascript #markdown #typescript

How to Reference Your JavaScript Source Code in Markdown
6.10 GEEK