【问题标题】:In asciidoc how do I execute a macro only for pdf generation?在 asciidoc 中,我如何只为 pdf 生成执行宏?
【发布时间】:2016-12-28 06:52:48
【问题描述】:

在 asciidoc 中有一个图像,我只想包含用于 PDF 输出。是否有一种属性可以传递给 image:: 以便处理图像以生成 PDF,并在生成 epub 等时忽略?或者更可能使用 ifdef,但究竟如何?

【问题讨论】:

    标签: asciidoctor asciidoctor-pdf


    【解决方案1】:

    您可以像这样使用ifdef directive

    Some text for all outputs.
    
    ifdef::backend-pdf[]
    This is only displayed in the PDF document, you can use image:
    image::mypict.png[]
    endif::[]
    

    【讨论】:

      【解决方案2】:

      如果您需要一个简单而小型的解决方案,我更喜欢 Jminis 的答案。

      对于需要更多区分的情况,您可以定义自己的过滤器参数,用于不同类型的输出,可以在命令行调用中定义为参数。您可以按如下方式过滤您的内容,例如如果您还想在不同的受众之间有所不同。

      Some text for all outputs.
      
      ifeval::["{myfilter1}"=="pdf"]
        This content is pdf-only!
      
        ifeval::["{myfilter2}"=="adminpdf"]
          This content is admin-pdf-only!
        endif::[]
      endif::[]
      

      可以在命令行调用中添加参数如下:

      --attribute myfilter1='pdf'
      

      该命令的确切表达式取决于您的系统。以下语法可以工作(我目前无法在没有 asciidoc-setup 的情况下对其进行测试)。

      OS X asciidoc -> 文档:

      SCRIPT=${...path to asciidoc installation...}/asciidoc.py
      INPUT=myAsciidocInput.ad
      OUTPUT=MyDocBookOutput.xml
      MYFILTER="--attribute myfilter1='pdf' --attribute myfilter2='adminpdf'"
      python "$SCRIPT" -o "$OUTPUT" "$MYFILTER "$INPUT"
      

      WIN asciidoc -> 文档:

      set SCRIPT=%{...path to asciidoc installation...}%\asciidoc.py
      set INPUT=myAsciidocInput.ad
      set OUTPUT=MyDocBookOutput.xml
      set MYFILTER=--attribute myfilter1='pdf' --attribute myfilter2='adminpdf'
      python "%SCRIPT%" -o "%OUTPUT%" 
      

      【讨论】:

      • 我通过 Java / Maven 使用 asciidoc 但无论如何这很有趣! :-)
      • 经过短暂尝试,AsciiDoctor 不支持嵌套条件。 (或者我太笨了,无法直接运行。:-D)以下示例适用于我在 maven 的 AsciiDoctor 中:MySourceFile.ad: ifeval::[{myfilter1}==pdf] 此内容仅限 pdf! endif::[] ifeval::[{myfilter2}==adminpdf] 此内容仅限 admin-pdf! endif::[] pom.xml: pdf ... pdf 抱歉格式错误:/
      猜你喜欢
      • 2020-08-21
      • 1970-01-01
      • 2018-11-01
      • 1970-01-01
      • 2019-04-28
      • 1970-01-01
      • 2010-09-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多