Skip to content

Conversation

@mportiz08
Copy link
Contributor

@mportiz08 mportiz08 commented Apr 18, 2024

Bug/issue #, if applicable:

Summary

Fixes the following issues with block directive formatting

  • top-level/starting block directive has unnecessary preceding newline
  • top-level block directive is unexpectedly indented
  • nested block directive has unnecessary newline before "}" character

For example:

import Markdown
print(Document(
    BlockDirective(name: "Metadata", children: [
        BlockDirective(name: "TitleHeading", argumentText: "Example")
    ])
).format())

Expected output:

@Metadata {
    @TitleHeading(Example)
}

Actual output:


    @Metadata {
        @TitleHeading(Example)
    }

Testing

Steps:

  1. Create a new Snippet that calls format() on a document with block directives
  2. Verify that the printed markdown doesn't exhibit the noted issues

Checklist

Make sure you check off the following items. If they cannot be completed, provide a reason.

  • Added tests
  • Ran the ./bin/test script and it succeeded
  • Updated documentation if necessary

mportiz08 and others added 3 commits April 17, 2024 15:51
Issues:
* top-level/starting block directive has unecessary preceding newline
* top-level block directive is unexpectedly indented
* nested block directive child has unecessary newline before "}"

Example snippet:

```swift
import Markdown
print(Document(
    BlockDirective(name: "Metadata", children: [
        BlockDirective(name: "TitleHeading", argumentText: "Example")
    ])
).format())
```

Expected output:
```
@metadata {
    @TitleHeading(Example)
}
```

Actual output (before this commit):
```

    @metadata {
        @TitleHeading(Example)

    }
```
@mportiz08
Copy link
Contributor Author

@swift-ci test

@QuietMisdreavus
Copy link
Contributor

Can you also add a test for when a directive is after another element, like a heading?

@mportiz08
Copy link
Contributor Author

Can you also add a test for when a directive is after another element, like a heading?

Yep

@mportiz08
Copy link
Contributor Author

Added.

I also found another bug and fixed it as part of a more complex test.

@mportiz08
Copy link
Contributor Author

@swift-ci test

@mportiz08
Copy link
Contributor Author

@swift-ci test

@mportiz08 mportiz08 merged commit 49beeeb into swiftlang:main Apr 22, 2024
@mportiz08 mportiz08 deleted the fix-block-directive-formatting branch April 22, 2024 18:06
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