Browse Source

parse links into markdown

pull/1/head
Wesley Kerfoot 4 years ago
parent
commit
a3a514eedc
  1. 2
      README.md
  2. 15
      src/twit2blogpkg/twitter.nim

2
README.md

@ -7,3 +7,5 @@ A simple tool to help make it easier to turn your tweet rants into real blog pos
### Running
Requires `TWITTER_CONSUMER_KEY` and `TWITTER_CONSUMER_SECRET`, both of which you can only get if you have a registered developer account and an application created for twitter.
Example: `/twit2blog -t:1234 -u:alice | pandoc --from=markdown --to=html > thread.html`

15
src/twit2blogpkg/twitter.nim

@ -65,14 +65,23 @@ proc getThread*(tweetStart : string, user : string) : seq[string] =
else:
return nextTweetID.getThread(user)
proc stripAts(tweet : string) : string =
proc convertWords(tweet : string) : string =
let words = tweet.split(" ")
var stripped : seq[string]
for word in words:
if word[0] != '@':
if word.len > 3 and word[0..3] == "http":
let parsedUri = word.parseUri
let scheme = parsedUri.scheme
let hostname = parsedUri.hostname
let path = parsedUri.path
if (scheme.len > 0 and hostname.len > 0):
stripped &= fmt"[{scheme}://{hostname}{path}]({scheme}://{hostname}{path})"
elif word[0] != '@':
stripped &= word
else:
continue
stripped.join(" ")
proc renderThread*(tweetID : string, user : string) : string =
let thread = tweetID.getThread(user).map(stripAts).map(capitalizeAscii).join("\n\n")
let thread = tweetID.getThread(user).map(convertWords).map(capitalizeAscii).join("\n\n")
fmt"### By {user}" & "\n" & fmt"{thread}"

Loading…
Cancel
Save