summary refs log tree commit diff stats
path: root/draco.pl
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-11-19 11:27:16 +0530
committerAndinus <andinus@nand.sh>2020-11-19 11:27:16 +0530
commit20dd49106d6bc1dc847ff93ce48d0dec285f45e3 (patch)
treeae62cb64041738d2ab0c44434e511b43770d309a /draco.pl
parent79a9c99ec8598b4e6c84118fc26298d201686055 (diff)
downloaddraco-20dd49106d6bc1dc847ff93ce48d0dec285f45e3.tar.gz
Wrap text at 72 characters & put a space before each line
Space before each line was done because some text may contain `*' at
the start of line which confuses Org & it presents that as a new
heading. Inserting a space before every new line fixes this.
Diffstat (limited to 'draco.pl')
-rwxr-xr-xdraco.pl18
1 files changed, 16 insertions, 2 deletions
diff --git a/draco.pl b/draco.pl
index da7f89a..2599139 100755
--- a/draco.pl
+++ b/draco.pl
@@ -6,6 +6,12 @@ use warnings;
 use HTTP::Tiny;
 use JSON::MaybeXS;
 
+# For wrapping comment blocks.
+use Text::Wrapper;
+my $wrapper = Text::Wrapper->new(columns => 72 - 1, body_start => '');
+
+my $VERSION = "v0.1.0";
+
 # Priting UTF-8 to STDOUT.
 binmode(STDOUT, "encoding(UTF-8)");
 
@@ -28,6 +34,10 @@ my $json_data = decode_json($response->{content});
 # $post contains post data
 my $post = $json_data->[0]->{data}->{children}->[0]->{data};
 
+# Start the Org document.
+print "#+", "STARTUP:content\n";
+
+# Print the post title.
 print "* ", "$post->{title}\n";
 
 # Add various details to :PROPERTIES:.
@@ -40,7 +50,9 @@ foreach my $detail (qw( subreddit created_utc author permalink
 print ":END:\n";
 
 # Add selftext/url if present.
-print "\n#+BEGIN_SRC markdown\n", "$post->{selftext}\n", "#+END_SRC\n"
+print "\n#+BEGIN_SRC markdown\n",
+    " ", $wrapper->wrap($post->{selftext}) =~ s/\n/\n\ /gr,
+    "#+END_SRC\n"
     if scalar $post->{selftext};
 print "$post->{url}\n" if scalar $post->{selftext};
 
@@ -70,7 +82,9 @@ sub print_comment_chain {
     }
     print ":END:\n";
 
-    print "\n#+BEGIN_SRC markdown\n", "$comment->{body}\n", "#+END_SRC\n";
+    print "\n#+BEGIN_SRC markdown\n",
+        " ", $wrapper->wrap($comment->{body}) =~ s/\n/\n\ /gr,
+        "#+END_SRC\n";
 
     # If the comment has replies then iterate over those too.
     if (scalar $comment->{replies}) {