【问题标题】:Is it possible to turn off syntax highlighting in Asciidoctor?是否可以在 Asciidoctor 中关闭语法突出显示?
【发布时间】:2017-10-12 16:12:44
【问题描述】:

我使用Asciidoctor 创建了我的JHipster Mini-Book。它在 PDF、MOBI、EPUB 和 HTML 中看起来很棒。我还创建了一个可打印的 (PDF) 版本。可打印版本通过 Lulu,并以黑白打印。

可打印的 PDF 的代码列表是彩色的,这会导致代码列表在打印时难以阅读,尤其是在它们是浅灰色的情况下(例如 cmets)。有没有办法在 Asciidoctor 中关闭语法高亮显示?

【问题讨论】:

标签: asciidoc asciidoctor asciidoctor-pdf


【解决方案1】:

一个简单的方法是不说代码使用哪种语言。直接替换

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

[source]
----
require 'sinatra'
----

【讨论】:

  • 对,但这会关闭其他工件(可下载的 PDF、MOBI 和 EPUB)中的所有语法高亮显示。这些文件中的语法突出显示效果很好。
【解决方案2】:

将属性source-highlighter 设置为html-pipeline,例如调用 asciidoctor 时在 CLI 上:

asciidoctor -a source-highlighter=html-pipeline FILE

【讨论】:

    【解决方案3】:

    我在 Twitter 上的 @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"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-20
      相关资源
      最近更新 更多