dineshsonachalam/markdown-autodocs

Specify ranges of code to be inserted via inline comments

Closed this issue · 1 comments

Thanks for the great tool! I am wondering whether this feature would make sense.

Currently, the tool support using the code line numbers to take a piece of code. One problem is that if we change the source code somehow and forget to update the line number in the README file, we would end up with a misaligned README example.

Is it possible that the tool can interpret markers (behind comments) in the source code? I understood this would be language-specific, but maybe this can work for languages that support inline comments.

For example

# MARKDOWN-AUTO-DOCS:BLOCK-1-START
import example
# MARKDOWN-AUTO-DOCS:BLOCK-1-END

# MARKDOWN-AUTO-DOCS:BLOCK-2-START
def first_func():
    print("first")
# MARKDOWN-AUTO-DOCS:BLOCK-2-END
<!-- MARKDOWN-AUTO-DOCS:START (CODE:src=./relative/path/to/code.js&code-block=BLOCK-1) -->
<!-- MARKDOWN-AUTO-DOCS:END -->

After importing the library, you can then:

<!-- MARKDOWN-AUTO-DOCS:START (CODE:src=./relative/path/to/code.js&code-block=BLOCK-2) -->
<!-- MARKDOWN-AUTO-DOCS:END -->

This is an intersting use case. Mine is comparable: I'd like to extract version numbers from files where the position of that version is not static. How about using a regular expression instead of inline comments?