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

insert spaces after inline comments explicitly without awk OFS #6

Open
vijithassar opened this issue Nov 16, 2018 · 0 comments
Open
Assignees

Comments

@vijithassar
Copy link
Owner

vijithassar commented Nov 16, 2018

When the --before/-b flags are used to comment out Markdown content, awk prints a space after the character that begins the comment. This is fine when there is a line to comment out:

# let's **create a variable** now
# ```python 
x = 'hello world'
# ```

But awk also inserts the space for line breaks when there is nothing to comment out, which is to say, for line breaks in the Markdown content:

# MY PROGRAM
# 
# let's **create a variable** now
# ```python
x = 'hello world'
# ```

This is happening because awk has a built in variable called OFS, for "output file separator," which is set to the space character by default.

Linters do not like the trailing space on empty comment lines, and often complain about empty space at the end of a line. Whether this problem occurs will depend on your language, your linter, and your specific linter configuration, but prohibiting this in developer tooling is very common.

Instead of relying on the awk OFS variable to supply the space, OFS should be set to an empty string so as not to pad empty comment lines, and then the space can be explicitly added.

This will require measuring the length of the Markdown content being commented out. If the length greater than 0 characters, then the space should be added before the Markdown content is appended to the. If the length of the Markdown content is zero characters, then it's just an empty line, and the space should not be appended.

This is related to the need to generally clean up the awk logic.

@vijithassar vijithassar self-assigned this Nov 16, 2018
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

No branches or pull requests

1 participant