33 lines
836 B
Nim
33 lines
836 B
Nim
|
import strutils, ../twtxt
|
||
|
from htmlgen import nil
|
||
|
|
||
|
type
|
||
|
TweetData* = seq[string]
|
||
|
|
||
|
proc `$`*(t: TweetData): string = t.join ""
|
||
|
|
||
|
proc prettyfyTweet*(t: string): TweetData =
|
||
|
result = newSeq[string]()
|
||
|
|
||
|
var tweet = t.replace("<", "<").replace(">", ">")
|
||
|
|
||
|
for word in tokenize(tweet):
|
||
|
if word.isSep:
|
||
|
result.add word.token
|
||
|
else:
|
||
|
if word.token.startsWith "@":
|
||
|
let
|
||
|
username = word.token.substr 1
|
||
|
ahref = htmlgen.a(href="/users/" & username & "/0", word.token)
|
||
|
result.add ahref
|
||
|
elif word.token.startsWith "http":
|
||
|
let ahref = htmlgen.a(href=word.token, word.token)
|
||
|
result.add ahref
|
||
|
else:
|
||
|
result.add word.token
|
||
|
|
||
|
when isMainModule:
|
||
|
const inp = "@reednj Yeah I was gonna work on that today http://foo.bar <b>foo</b>"
|
||
|
|
||
|
echo inp.prettyfyTweet
|