-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add WithSoftWraps
option
#36
Conversation
Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, some nits only, otherwise LGTM!
main.go
Outdated
@@ -23,6 +23,7 @@ var ( | |||
write = flag.Bool("w", false, "write result to (source) file instead of stdout") | |||
doDiff = flag.Bool("d", false, "display diffs instead of rewriting files") | |||
underlineHeadings = flag.Bool("u", false, "write underline headings instead of hashes for levels 1 and 2") | |||
hardWraps = flag.Bool("h", false, "hard wrap lines even on soft line breaks") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not add as h
- it's usually used for help. Let's use just hard-wraps
? ;p
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! 🙂
_, _ = r.w.Write(spaceChar) | ||
char := spaceChar | ||
if r.mr.hardWraps { | ||
char = newLineChar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was.... easy (:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! 😁
main.go
Outdated
@@ -62,6 +63,9 @@ func processFile(filename string, in io.Reader, out io.Writer) error { | |||
if *underlineHeadings { | |||
opts = append(opts, markdown.WithUnderlineHeadings()) | |||
} | |||
if *hardWraps { | |||
opts = append(opts, markdown.WithHardWraps()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think another 3rd option here would be to automatically change it to X chars wide. We can add that later, but wonder if this option would conflict. e.g if someone will use WithHardWraps
and WithMaxLineWidth(80)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it can be added later! I think a check might be needed for the conflict between them. Also, word wrapping needs to be implemented for this in a way(something like this) so that there are no formatting surprises! 🙂
markdown/renderer.go
Outdated
@@ -55,6 +56,12 @@ func WithUnderlineHeadings() Option { | |||
} | |||
} | |||
|
|||
func WithHardWraps() Option { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add comment?
Also ... technically we talk about soft wraps, no?
func WithHardWraps() Option { | |
func WithSoftWraps() Option { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! Will add a comment and rename it! So everything hardWrap -> softWrap.
Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! LGTM (:
This PR adds
WithHardWrap
option, which when enabled preserves soft line breaks. Addresses #29.Feedback is needed on whether this could be done via line widths, in which case some sort of word wrapping is needed and which might lead to further issues as it would override both hard and soft line breaks.
cc: @bwplotka