2016-12-28 60 views

回答

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::[] 
1

如果你需要一個簡單的小的解決方案,我寧願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 - >的DocBook:

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 - >的DocBook:

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%" 
+0

我用asciidoc通過Java/Maven的,但是這很有趣呢! :-) – seinecle

+0

短暫的嘗試,AsciiDoctor不支持嵌套條件。 (還是我太noobish讓它直接運行:-D) 下面的例子對我的作品在AsciiDoctor與Maven: 'MySourceFile.ad': ifeval :: [{} myfilter1 == PDF] 此內容僅限pdf! endif :: [] ifeval :: [{myfilter2} == adminpdf] This content is admin-pdf-only! ENDIF :: [] 'pom.xml': <結構> PDF ... PDF - adminpdf 對不起,格式不正確:/ –