saasmanual / ideas

You can share your ideas for SaaS Manual here.
https://saasmanual.com
2 stars 0 forks source link

Embed source code into posts. #10

Closed nonken closed 3 years ago

nonken commented 3 years ago

It would be great if it was possible to embed source code that is actually used in articles. Usually, we'd use examples that are at risk of getting out of date. This way source is never out of date as it is coming from actual code that gets deployed to production.

A way to do this could be to mark sections in code in a way and then allow to reference that in the markdown posts.

Code:

// [embed:article-123]
function foo() {}
// [/embed]

Markdown post:

::embed:article-123

At build time, the build tool would first go through the source and build a dictionary of snippets. And then inline them into the markdown posts.

The implementation could be simple for now, I could just run a regular expression over the source to identify embeddable code pieces.