I know you found an exact answer, but I thought I’d give an alternative. You could do this or something similar with pandoc [1] and a make file. I tend to write my files in markdown run a makefile that concatenates them and converts them with pandoc to pdf, html, or docx.
IMO every programming language definition should also define how documentation strings are associated to syntactical constructs and how they can be accessed programmatically.