Skip to content

Conversation

@nik9000
Copy link
Member

@nik9000 nik9000 commented Mar 1, 2017

This macro allows you to include a portion of a file like this:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests}/DeleteDocumentationIT.java[delete-request]
--------------------------------------------------
<1> Index name
<2> Type
<3> Document id

Which can be used to extract a section of a file like this:

        // tag::delete-request
        DeleteRequest request = new DeleteRequest(
            "index",    // <1>
            "type",     // <2>
            "id");      // <3>
        // end::delete-request

This macro allows you to include a portion of a file like this:
```
["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests}/DeleteDocumentationIT.java[delete-request]
--------------------------------------------------
<1> Index name
<2> Type
<3> Document id
```

Which can be used to extract a section of a file like this:
```
        // tag::delete-request
        DeleteRequest request = new DeleteRequest(
            "index",    // <1>
            "type",     // <2>
            "id");      // <3>
        // end::delete-request
```
@nik9000 nik9000 added the enhancement Something we'd like to improve label Mar 1, 2017
@nik9000 nik9000 requested a review from clintongormley March 1, 2017 18:29
@dadoonet
Copy link

dadoonet commented Mar 1, 2017

I gave a quick look at it (well I'm not a Python guy :) ). It looks good.

I guess that automatically find what is the indentation of the tag with indentation = m.group(1).

@nik9000
Copy link
Member Author

nik9000 commented Mar 1, 2017

I guess that automatically find what is the indentation of the tag with indentation = m.group(1).

Right. We copy the indentation of the tag and strip it from all the other fields. At least, that is what I tried to do.

</phrase>

[include-tagged-inlinemacro]
# it is a nightmare to get this to work with eval3 so we're forking a new process every time....
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think eval3 should be sys3 actually.

@nik9000
Copy link
Member Author

nik9000 commented Mar 15, 2017

@clintongormley, do you want to have a look at this?

Copy link
Contributor

@clintongormley clintongormley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've improved the error reporting a bit to give the user more context. With that change in place, it's good to merge

indentation = m.group(1)


if __name__ == '__main__':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd tidy up the error output a bit, to look more like this:

if __name__ == '__main__':
    from sys import argv, stdout, stderr
    try:
      result = extract_tagged(argv[1], argv[2])
      if result:
          stdout.write(result)
      else:
          raise Exception("Couldn't find tag")
    except Exception as e:
      stderr.write("asciidoc: ERROR: Extracting tag `" + argv[2] + "` from file `" + argv[1]+ "`: " + e.__str__() + "\n")
      exit(1)

@nik9000 nik9000 merged commit d6a9bbe into elastic:master Mar 20, 2017
@nik9000
Copy link
Member Author

nik9000 commented Mar 20, 2017

Thanks @clintongormley!

@nik9000 nik9000 deleted the include_tag_macro branch February 19, 2019 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Something we'd like to improve

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants