Documentation 如何在ascidoc中包含使用标记的代码摘录?

Documentation 如何在ascidoc中包含使用标记的代码摘录?,documentation,literate-programming,asciidoc,Documentation,Literate Programming,Asciidoc,我可以包含完整的Greet.java文件 public class Greet { public static void main(String[] args) { System.out.println("Hello World!"); } } 从ascidoc文件中 == Hello Java This is how one greets in Java: [source,java] .Greet.java ---- include::Greet.java

我可以包含完整的
Greet.java
文件

public class Greet {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}
从ascidoc文件中

== Hello Java
This is how one greets in Java:

[source,java]
.Greet.java
----
include::Greet.java
----
制作文件

但是假设我只想包含由标记分隔的代码的摘录。在上面的代码中,假设我只想包含
main
函数

我在页面中没有看到符号标记,但页面表明它足以进行书写

public class Greet {
    // tag::helloMethod[]
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
    // end::helloMethod[]
}

这只会产生:


你能建议一种只包含摘录的方法吗?我使用的是Ascidoc 8.6.9。

您在(中)所做的工作应该很好,但不是()

请注意,获取语法高亮显示的机制不同

要使用ascidoc获得语法高亮显示,可以使用命令行开关
ascidoc-a source highlighter=pygments file.adoc

AscidActor不需要(也不可能)命令行开关。使用AscidActor,通过以下方式获得语法高亮显示:

  • 在每个源文件的顶部插入
    :source highlighter:pygments
    ,以及
  • 运行
    sudo gem install pygments.rb
    安装pygments
  • == Hello Java
    This is how one greets in Java:
    
    [source,java]
    .Greet.java
    ----
    include::Greet.java[tags=helloMethod]
    ----