Effortless export from github wiki (?)

前端 未结 7 1103
悲&欢浪女
悲&欢浪女 2021-01-30 12:36

I am collecting quite a lot of material in a GitHub wiki. I really like to use the wiki to cooperate with other people and IMHO the platform is really nice, I like it!

S

相关标签:
7条回答
  • 2021-01-30 13:29

    I found many of the solutions difficult to reproduce/get the right version/understand/fix/etc... So instead, I'll present a patchwork docker solution to effortlessly convert on Windows(using git bash)/MacOS/Linux in 5 "easy" commands

    git clone {project_url}.wiki .
    
    # Convert *.md to *.md.html using the actual github pipeline
    docker run --rm -e DOCKER_USER_ID=`id -u` -e DOCKER_GROUP_ID=`id -u` \
                v "`pwd`:/src" -v "`pwd`:/out" andyneff/github-markdown-preview
    
    # Fix hyperlinks, since wkhtmltopdf is stricter than github servers
    docker run --rm -v `pwd`:/src -w /src perl \
        perl -p -i -e 's|(<a href=")([^/"#]+?)(#[^"]*)?(">.*?</a>)|\1\L\2\E.md.html\L\3\E\4|g'\
                      *.html
    
    # Lowercase all filename so that hyperlink match
    docker run --rm -v `pwd`:/src -w /src python \
        python -c 'import sys;import os; [os.rename(f, f.lower()) for f in sys.argv[1:]]' \
                   *.md.html
    
    #Convert html to pdf using QT webkit
    docker run -it --rm -e DOCKER_USER_ID=`id -u` -e DOCKER_GROUP_ID=`id -u`\
               -v `pwd`:/work -w /work andyneff/wkhtmltopdf \
               wkhtmltopdf --encoding utf-8 --minimum-font-size 14 \
               --footer-left "[date]" --footer-right "[page] / [topage]" \
               --footer-font-size 10 \
               toc \
               *.html document.pdf
    

    The perl is the main part that may fail without a better solution. Pandoc has a really good filter solution, but isn't using the github pipeline.

    Bugs:

    • Extra wide code blocks will be rendered with a scroll bar, and essentially cut off in the pdf. It would be best to make the code block not overflow, but you can add --user-style-sheet user.css to the wkhtmltopdf command (before toc/cover), and add to your user.css

      .markdown-body .highlight pre,
      .markdown-body pre{
        overflow:visible !important;
      }
      
    • Some link in the final pdf are off by +1 page, some are not. Not sure what the pattern is. But anchors with ids (#) do not appear to have this problem

    0 讨论(0)
提交回复
热议问题