From 3e7484cd704c1d473fc41c8bdcc9aefff718894b Mon Sep 17 00:00:00 2001 From: Andinus Date: Thu, 19 Nov 2020 12:05:15 +0530 Subject: Switch to Unicode::LineBreak from Text::Wrapper Unicode::LineBreak seems better. --- draco.1 | 5 +++-- draco.pl | 13 ++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/draco.1 b/draco.1 index 69efabc..d9ebeba 100644 --- a/draco.1 +++ b/draco.1 @@ -16,11 +16,12 @@ It'll also print comments along with their replies. It's limited by the reddit API. .Pp .Sh NOTES -Draco will add a space before every new line. Comments/Posts may +Draco will add 2 spaces before every new line. Comments/Posts may contain `*' at the start of line & that confuses Org. Org might interpret it as a new heading so we add a space before every new line. -All text will be wrapped at 72 characters. +All text will be wrapped at 76 characters, including 2 spaces before +every new line the maximum number of columns becomes 78. .Pp .Sh WHY? I reference things from the web in my Journal & don't want those links diff --git a/draco.pl b/draco.pl index 2599139..908f3de 100755 --- a/draco.pl +++ b/draco.pl @@ -7,12 +7,12 @@ use HTTP::Tiny; use JSON::MaybeXS; # For wrapping comment blocks. -use Text::Wrapper; -my $wrapper = Text::Wrapper->new(columns => 72 - 1, body_start => ''); +use Unicode::LineBreak; +my $lb = Unicode::LineBreak->new(ColMax => 76); # Default is 76. my $VERSION = "v0.1.0"; -# Priting UTF-8 to STDOUT. +# Printing UTF-8 to STDOUT. binmode(STDOUT, "encoding(UTF-8)"); die "usage: draco \n" unless scalar @ARGV; @@ -51,7 +51,8 @@ print ":END:\n"; # Add selftext/url if present. print "\n#+BEGIN_SRC markdown\n", - " ", $wrapper->wrap($post->{selftext}) =~ s/\n/\n\ /gr, + # Break the text at 76 column & add 2 space before every new line. + " ", $lb->break($post->{selftext}) =~ s/\n/\n\ \ /gr, "\n", "#+END_SRC\n" if scalar $post->{selftext}; print "$post->{url}\n" if scalar $post->{selftext}; @@ -83,7 +84,9 @@ sub print_comment_chain { print ":END:\n"; print "\n#+BEGIN_SRC markdown\n", - " ", $wrapper->wrap($comment->{body}) =~ s/\n/\n\ /gr, + # Break the text at 76 column & add 2 space before every new + # line. + " ", $lb->break($comment->{body}) =~ s/\n/\n\ \ /gr, "\n", "#+END_SRC\n"; # If the comment has replies then iterate over those too. -- cgit 1.4.1-2-gfad0