Thread overview
Generate PDF or HTML of source
March 16

I want to generate PDFs of the individual source files of my project. Preferably with syntax highlighting, but if pressed I could live without it for this particular case. I would like line numbers though.

HTML is fine too as I could just print them to PDF.

dub build -b docs and ddox and adrdox etc can all generate API summary documentation, but I have a need for the source files themselves.

So far the best I've managed is to browse to the pages for the source files on GitHub and print those to PDF. It works, but you get the top of the page with the menu etc included, and it's put simply a pain to manually do when you have 75 source files.

Is there any elegant solution I'm missing?

March 16

On Sunday, 16 March 2025 at 16:26:55 UTC, Anonymouse wrote:

>

adrdox [...] but I have a need for the source files themselves.

adrdox --help
-u --genSource Generate annotated source

use that -u thing and it spits out source too with links everywhere just like you see at

https://opendlang.org/library/arsd.characterencodings.convertToUtf8.html

"see implementation"

https://opendlang.org/library/source/arsd.characterencodings.d.html#L71

March 16

On Sunday, 16 March 2025 at 17:07:45 UTC, Adam D. Ruppe wrote:

>

On Sunday, 16 March 2025 at 16:26:55 UTC, Anonymouse wrote:

>

adrdox [...] but I have a need for the source files themselves.

adrdox --help
-u --genSource Generate annotated source

use that -u thing and it spits out source too with links everywhere just like you see at

https://opendlang.org/library/arsd.characterencodings.convertToUtf8.html

"see implementation"

https://opendlang.org/library/source/arsd.characterencodings.d.html#L71

Oh, neat! I missed that option.

Is getting rid of the sidebar non-trivial? I get https://i.imgur.com/ropgZWj.png when printing to PDF.

March 16

On Sunday, 16 March 2025 at 17:27:22 UTC, Anonymouse wrote:

>

Is getting rid of the sidebar non-trivial? I get https://i.imgur.com/ropgZWj.png when printing to PDF.

I never even considered someone would try to print it lol. Should be easy enough to add some css like

@media print {
    #page-nav { display: none !important; }
}

to the end of style.css in your generated docs folder then refresh it in your browser. Can add other things to hide there too if you want.

March 16

On Sunday, 16 March 2025 at 17:33:43 UTC, Adam D. Ruppe wrote:

>

On Sunday, 16 March 2025 at 17:27:22 UTC, Anonymouse wrote:

>

Is getting rid of the sidebar non-trivial? I get https://i.imgur.com/ropgZWj.png when printing to PDF.

I never even considered someone would try to print it lol.

The use-case is that I want to put it all on an e-ink reader to pore over and annotate it as if it were written out on paper. This particular one doesn't do HTML, but PDF works very well.

>

Should be easy enough to add some css like

@media print {
    #page-nav { display: none !important; }
}

to the end of style.css in your generated docs folder then refresh it in your browser. Can add other things to hide there too if you want.

That solved that, thanks.

Lastly then, is there any CSS wizardry to be used to make it word-wrap? The final hurdle is that it's cutting off text, like in https://i.imgur.com/fWCVdYn.png.

Looking at it in a browser and shrinking the window, I guess maybe it doesn't wrap to begin with.

March 16

On Sunday, 16 March 2025 at 17:50:44 UTC, Anonymouse wrote:

>

Lastly then, is there any CSS wizardry to be used to make it word-wrap?

Yeah, I specifically disabled word wrap for code blocks because I prefer horizontal scrolling them in a browser.

Add this either to that same media print block, or right under it (if you want it to affect in the browser too) and you should get OK results:

pre {
 white-space: pre-wrap !important;
}

This tells it to use the pre-formatted whitespace, but allow wrapping as needed, with important there to override any previous commands.

March 16

On Sunday, 16 March 2025 at 18:02:54 UTC, Adam D. Ruppe wrote:

>

On Sunday, 16 March 2025 at 17:50:44 UTC, Anonymouse wrote:

>

Lastly then, is there any CSS wizardry to be used to make it word-wrap?

Yeah, I specifically disabled word wrap for code blocks because I prefer horizontal scrolling them in a browser.

Add this either to that same media print block, or right under it (if you want it to affect in the browser too) and you should get OK results:

pre {
 white-space: pre-wrap !important;
}

This tells it to use the pre-formatted whitespace, but allow wrapping as needed, with important there to override any previous commands.

The wrapping looks a bit funky but I think I can work with this. Thanks!

March 17

On Sunday, 16 March 2025 at 16:26:55 UTC, Anonymouse wrote:

>

I want to generate PDFs of the individual source files of my project. Preferably with syntax highlighting, but if pressed I could live without it for this particular case. I would like line numbers though.

HTML is fine too as I could just print them to PDF.

dub build -b docs and ddox and adrdox etc can all generate API summary documentation, but I have a need for the source files themselves.

So far the best I've managed is to browse to the pages for the source files on GitHub and print those to PDF. It works, but you get the top of the page with the menu etc included, and it's put simply a pain to manually do when you have 75 source files.

Is there any elegant solution I'm missing?

dub run dscanner -- --highlight source/app.d
or
highlight -o html -i source/app.d -o test.html

Andrea