Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asciidoctor: Fix Elastic's include-tagged with empty lines #693

Merged

Conversation

nik9000
Copy link
Member

@nik9000 nik9000 commented Mar 8, 2019

Elastic has has tagged include support in AsciiDoc for years now. Once
we've migrated to Asciidoctor we can start using its native tagged
include support, but while we're in the process of migrating we need to
perfectly emulate Elastic's tagged include in Asciidoctor. We've had
this emulation for a while and this change fixes a bug which caused
empty lines to be throw out. Let's look at an example:

Say you have some file like this:

...
    // tag::foo
    String foo = "bar";

    System.err.println("ASDFDAF " + foo);
    // end::foo
...

Elastic's AsciiDoc include tagged support would extract the foo tag
as:

    String foo = "bar";

    System.err.println("ASDFDAF " + foo);

The bug in our Asciidoctor include tagged support is that it'd extract
the foo tag as:

    String foo = "bar";
    System.err.println("ASDFDAF " + foo);

Those empty lines can be quite useful in examples! We should preserve
them.

Elastic has has tagged include support in AsciiDoc for years now. Once
we've migrated to Asciidoctor we can start using its native tagged
include support, but while we're in the process of migrating we need to
perfectly emulate Elastic's tagged include in Asciidoctor. We've had
this emulation for a while and this change fixes a bug which caused
empty lines to be throw out. Let's look at an example:

Say you have some file like this:
```
...
    // tag::foo
    String foo = "bar";

    System.err.println("ASDFDAF " + foo);
    // end::foo
...
```

Elastic's AsciiDoc include tagged support would extract the `foo` tag
as:
```
    String foo = "bar";

    System.err.println("ASDFDAF " + foo);
```

The bug in our Asciidoctor include tagged support is that it'd extract
the `foo` tag as:
```
    String foo = "bar";
    System.err.println("ASDFDAF " + foo);
```

Those empty lines can be quite useful in examples! We should preserve
them.
@nik9000 nik9000 requested a review from estolfo March 8, 2019 21:47
@nik9000 nik9000 mentioned this pull request Mar 8, 2019
@nik9000 nik9000 changed the title Asciidoctor: Fix Elastic's include-tagged Asciidoctor: Fix Elastic's include-tagged with empty lines Mar 8, 2019
@nik9000
Copy link
Member Author

nik9000 commented Mar 12, 2019

@estolfo, could you have a look at this one when you get a chance?

Copy link
Contributor

@estolfo estolfo left a comment

Choose a reason for hiding this comment

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

It's probably not necessary to freeze the regexp's.

start_match = /^(\s*).+tag::#{tag}\b/
end_match = /end::#{tag}\b/
start_match = /^(\s*).+tag::#{tag}\b/.freeze
end_match = /end::#{tag}\b/.freeze
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a specific reason why you are freezing the Regexp's?
I usually freeze Strings when I use them as constants, as they are mutable. Things like Regexp's, that are immutable, are probably not necessary to freeze.

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like regexes are technically mutable even if they don't have any mutation methods. Weird. I suspect some of this weirdness is how I got here. I'll stop freezing them.

included_lines << line if line
next
end
next unless start_match =~ line
start_match_data = start_match.match(line)
next unless start_match_data
Copy link
Contributor

Choose a reason for hiding this comment

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

You could also write this like next unless start_match_data = start_match.match(line)
But some people might disagree : )

Copy link
Member Author

Choose a reason for hiding this comment

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

Dan didn't like that too much so I'm avoiding it. Asciidoctor uses this sort of thing in the extreme and I think it is fairly hard to read. So for the most part I've swung the other way....

Copy link
Contributor

Choose a reason for hiding this comment

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

It's purely a style thing, so no problem


found_tag = true
indentation = $1.size
indentation = /^#{start_match_data[1]}/.freeze
Copy link
Contributor

Choose a reason for hiding this comment

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

Regexp's are immutable so it's probably not necessary to freeze it.

@nik9000
Copy link
Member Author

nik9000 commented Mar 13, 2019

@estolfo this one is ready for you again when you get a chance.

Copy link
Contributor

@estolfo estolfo left a comment

Choose a reason for hiding this comment

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

Looks good!

@nik9000 nik9000 merged commit 2d539fe into elastic:master Mar 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants