It may be possible, if you have 1 annotation by file you can retrieve the containingFile of annotated symbols and generate a string from that, also KSP is more about the structure (symbols) than the code inside (runtime).
You may be interested by
Knit that is generating example files from a markdown documentation, if ever your website is generated from markdown.