diff --git a/Main.hs b/Main.hs
index 53971c0..66dc136 100644
--- a/Main.hs
+++ b/Main.hs
@@ -15,7 +15,8 @@ parse ("-d":[]) = usage
parse ("-d":n:[]) = usage
parse ("-d":n:fs) = do
htmlResult <- downloadHtmlDef n (head fs)
- printDef (E.decodeUtf8 htmlResult)
+ let n' = read n :: Int
+ printDef (E.decodeUtf8 htmlResult) n'
parse fs = do
htmlResult <- downloadHtmlAvailableDef (head fs)
printDifferentDef (E.decodeUtf8 htmlResult)
diff --git a/ParseHtml.hs b/ParseHtml.hs
index 3629d72..ac6128c 100644
--- a/ParseHtml.hs
+++ b/ParseHtml.hs
@@ -3,6 +3,7 @@ module ParseHtml (printDef, printDifferentDef) where
import Text.HTML.TagSoup
import Prelude
import WordDef
+import qualified Data.List as L
import qualified Data.Text.Lazy as T
@@ -37,17 +38,26 @@ differentDefTags =
filter (~== TagText "") . (takeWhile (~/= "
"))
. (dropWhile (~/= "
")) . parseTags . T.unpack
-printDef :: T.Text -> IO ()
-printDef = putStrLn . getDef
+printDef :: T.Text -> Int -> IO ()
+printDef t n = putStrLn (getDef t n)
-getDef :: T.Text -> String
-getDef = (renderFullDef . getFullDef . parseFullDefTags)
+getDef :: T.Text -> Int -> String
+getDef t n = renderFullDef (getFullDef t n)
-getFullDef :: [Tag String] -> WordFullDef
-getFullDef x = WordFullDef (WordDefHeader (WordName "lol") (WordType
- "Interjection")) [WordDefSentence "Laughing Out Loud",
- WordExampleSentence "ur wrong lol"]
+getFullDef :: T.Text -> Int -> WordFullDef
+getFullDef t n = WordFullDef header defList
+ where
+ header = ((parseDefTags . differentDefTags) t !! (n-1))
+ defList = map (WordDefSentence . renderTags) [parseFullDefTags t]
parseFullDefTags :: T.Text -> [Tag String]
-parseFullDefTags = filter (~== " [Tag String]
+findRelevantTags [] = []
+findRelevantTags (x:xs) = if x ~== " y:(f xs)) (L.find (~== TagText "") xs)
+ else (f xs)
+ where
+ f = findRelevantTags