Discussion

Ask HN: Tool to convert JavaScript code comments into Markdown?

I would like a tool which takes code in a javascript project and generates markdown where the comments are taken as direct markdown and the code is wrapped in triple backticks. This would allow me to make a blog post from a javascript project without maintaining two separate files and updating the code in both.

For example if I have this in a javascript file:

  /*
  # Tutorial Title

  Welcome to the codebase tutorial.

  ## Add Function

  This function is used to add numbers. `1+2=3` is an example of some backquoted text.
  */
  function add(a,b) {
    return a + b;
  }

  /*
  ## Subtract Function

  This function is used to subtract! ***Use at your own risk***
  */
  function subtract(a,b) {
    return a - b;
  }
I would like the resulting markdown to be:

  # Tutorial Title

  Welcome to the codebase tutorial.

  ## Add Function

  This function is used to add numbers. `1+2=3` is an example of some backquoted text.
  ```
  function add(a,b) {
    return a + b;
  }
  ```

  ## Subtract Function

  This function is used to subtract! ***Use at your own risk***
  ```
  function subtract(a,b) {
    return a - b;
  }
  ```
Does anyone know of a tool which will do this?
2 points defaultcompany 5 years ago 2 comments

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton