How can I convert programming ebooks to markdown format properly?

Hi there. I am trying to convert programming ebooks to markdown format for adding this books to my markdown notes and making changes(adding extra notes and adding my own codes) on it. My problem is conversion tools cannot convert code blocks properly.I know that a lot of techniques exist pdf, epub to markdown so I want to discuss which technique is better for converting cs books to markdown format.

EPUB->HTML->MARKDOWN
My technique is the following:

  • I use epub ebooks rather than pdf ebooks. Because epub format has a better structure for HTML, I have a lot of data loss when I tried to convert PDF to HTML because PDF format is a presenttation tool, not a structure tool.
  • I use calibre to convert EPUB to HTML because it is awesome for structure detection.
  • I use pandoc to convert html to markdown.My results are pretty good except for code blocks.Code blocks rendered as HTML paragraphs instead of markdown code blocks.

My main problem is that conversion tools lose code block style on PDF,EPUB to HTML conversion phase. I tried pandoc,calibre but neither of these programs maintain code block style.

Any advice for converting programming ebooks to markdown format appreciated.

Are you using preformated elements?

Do you mean that converted HTML file uses preformated elements for code blocks?

I meant have you tried putting the codeblocks inside of <pre> tags when editing the books as HTML.

I don’t know anything about pandoc. I’ve often edited epub books but just in their HTML form.

Thanks…I can put the code blocks inside of <pre> tag with HTML parser tool such as Jsoup but there is nothing exist to indicate where the code blocks are. Code blocks are surrounded by paragraph tags which is like the normal content.
It looks like this:

Which tool do you use for EPUB to HTML conversion?

I’ve done all my editing in either Calibre or Sigil.

You could share your accomplishments.
I want to move to MarKdown documentation that generates a PDF application.
In order to take it to version control