2017-10-12 93 views
0

我用Asciidoctor來創建我的JHipster Mini-Book。它在PDF,MOBI,EPUB和HTML中看起來很棒。我還創建了可打印的(PDF)版本。可打印版本通過露露,並獲得黑白印刷。是否可以關閉Asciidoctor中的語法高亮顯示?

可打印的PDF文件的代碼清單是彩色的,這會導致代碼清單在打印時很難閱讀,特別是如果它們是淺灰色的(例如註釋)。有沒有辦法在Asciidoctor中關閉語法突出顯示?

+0

你看http://gist.asciidoctor.org/?github-asciidoctor%2Fasciidoctor-pdf%2F%2Fdocs%2Ftheming-guide.adoc? –

回答

0

我在推特上找到了@mojavelinux(Dan Allen)的幫助。關鍵是不要通過source-highlighter的論點。

這是我做了這個改變後的generate-pdf.sh腳本。

#!/bin/bash 
# Usage: `./generate-pdf.sh` to generate a printable 6x9" PDF with no syntax highlighting 
#  `./generate-pdf.sh screen` to generate a downloadable 8.5x11" PDF 

source $HOME/.rvm/scripts/rvm 

rvm use 2.3.1 --quiet 
if [ ! -d .bundle/gems ]; then 
    rm -f Gemfile.lock 
    bundle config --local github.https true 
    bundle --path=.bundle/gems --binstubs=.bundle/.bin 
fi 

if [ -f "$rvm_path/scripts/rvm" ] && [ -f ".ruby-version" ] && [ -f ".ruby-gemset" ]; then 
    source "$rvm_path/scripts/rvm" 
    rvm use `cat .ruby-version`@`cat .ruby-gemset` 
fi 

ASCIIDOCTOR_PDF="./.bundle/.bin/asciidoctor-pdf" 
OPTIMIZE_PDF="`bundle exec gem contents --show-install-dir asciidoctor-pdf`/bin/optimize-pdf" 

ROOT_DIR=$(realpath $(dirname $0)) 
MEDIA=prepress 
HIGHLIGHTING="" 
if [ ! -z "$1" ]; then 
    MEDIA=$1 
    HIGHLIGHTING="-a source-highlighter=coderay" 
fi 
BASE_DIR="$ROOT_DIR/src/docs/asciidoc" 
OUT_DIR="$ROOT_DIR/build/asciidoc/pdf-$MEDIA" 

$ASCIIDOCTOR_PDF --trace -B "$BASE_DIR" \ 
    -D "$OUT_DIR" \ 
    -S unsafe \ 
    -r "$ROOT_DIR/src/main/ruby/asciidoctor-pdf-extensions.rb" \ 
    -a media=$MEDIA \ 
    -a pdfmarks \ 
    -a pdf-style=infoq-$MEDIA \ 
    -a pdf-stylesdir="$BASE_DIR/styles/pdf" \ 
    -a pdf-fontsdir="$BASE_DIR/styles/pdf/fonts" \ 
    -a sourcedir=../../../main/webapp \ 
    $HIGHLIGHTING \ 
    -a imagesdir=images \ 
    -a toc \ 
    -a icons=font \ 
    -a idprefix \ 
    -a idseparator=- \ 
    -a projectdir=../../.. \ 
    -a rootdir=../../.. \ 
    -a project-name=jhipster-book \ 
    -a project-version=2.0.0-SNAPSHOT \ 
    -a attribute-missing=warn \ 
    "$BASE_DIR/index.adoc" 

$OPTIMIZE_PDF "$OUT_DIR/index.pdf" 
mv -f "$OUT_DIR/index-optimized.pdf" "$OUT_DIR/index.pdf" 
0

一個簡單的方法是不說代碼的語言。只需更換

[source,ruby] 
---- 
require 'sinatra' 
---- 

[source] 
---- 
require 'sinatra' 
---- 
+0

正確,但是這會關閉其他工件(可下載的PDF,MOBI和EPUB)中的所有語法高亮。語法突出顯示在這些文件中很棒。 –

0

組屬性source-highlighterhtml-pipeline,例如在CLI中調用asciidoctor時:

asciidoctor -a source-highlighter=html-pipeline FILE