Issues with links

This commit is contained in:
thepenguin 2022-10-30 19:14:23 +01:00
parent 813debec5d
commit 02da1f666a
No known key found for this signature in database
GPG Key ID: F258C8C10D060D5E
3 changed files with 29 additions and 9 deletions

View File

@ -18,3 +18,6 @@ The name is pronounced like autumn.
* Todo [0/2] * Todo [0/2]
- [ ] Image or Video parser - [ ] Image or Video parser
- [ ] Properly support normal links - [ ] Properly support normal links
* Issues
- Link parser goes to the first one in line and never exits that and therefore errors when not receiving a proper file type in the end

View File

@ -11,7 +11,8 @@ import Text.Megaparsec.Char
type Parser = Parsec Void String type Parser = Parsec Void String
newtype URL = URL String data URL = Img String | Vid String | Website String
deriving (Show)
data Info = data Info =
Bread String | Bread String |
@ -32,10 +33,11 @@ instance Show Info where
Header text -> "[TITLE]" ++ text ++ "[/TITLE]\n" Header text -> "[TITLE]" ++ text ++ "[/TITLE]\n"
Subheader text -> "[SIZE=4]" ++ text ++ "[/SIZE]\n" Subheader text -> "[SIZE=4]" ++ text ++ "[/SIZE]\n"
Subsubheader text -> "[SIZE=2]" ++ text ++ "[/SIZE]\n" Subsubheader text -> "[SIZE=2]" ++ text ++ "[/SIZE]\n"
Image (URL url) -> "[IMG]" ++ url ++ "[/IMG]\n" Image (Img url) -> "[IMG]" ++ url ++ "[/IMG]\n"
Video (URL url) -> "[VIDEO]" ++ url ++ "[/VIDEO]\n" Video (Vid url) -> "[VIDEO]" ++ url ++ "[/VIDEO]\n"
Link (URL url) inf -> "[URL=\"" ++ url ++ "\"]" ++ show inf ++ "[/URL]\n" Link (Website url) inf -> "[URL=\"" ++ url ++ "\"]" ++ show inf ++ "[/URL]\n"
Spoiler inf -> "[SPOILER]" ++ concatMap show inf ++ "[/SPOILER]\n" Spoiler inf -> "[SPOILER]" ++ concatMap show inf ++ "[/SPOILER]\n"
_ -> error "Something went wrong with showing the parsed information"
newtype Post = Post [Info] newtype Post = Post [Info]
@ -67,16 +69,29 @@ fileParser =
Subsubheader <$> (string' "*** " >> takeRest), Subsubheader <$> (string' "*** " >> takeRest),
List . (: []) . Bread <$> (string' "- " >> takeRest), List . (: []) . Bread <$> (string' "- " >> takeRest),
-- Image and video needs to know if it is a image or video -- Image and video needs to know if it is a image or video
Image . URL <$> between (string' "[[") (string' "]]") (takeWhileP Nothing (/= ']')), Image <$> between (string' "[[") (string' "]]") parseLink,
Video . URL <$> between (string' "[[") (string' "]]") (takeWhileP Nothing (/= ']')), Video <$> between (string' "[[") (string' "]]") parseLink,
-- parseLink, -- (takeWhileP Nothing (/= ']')),
Spoiler . (: []) . Bread <$> (string' "#+BEGIN" >> return ""), Spoiler . (: []) . Bread <$> (string' "#+BEGIN" >> return ""),
Spoiler . (: []) . Bread <$> (string' "#+END" >> return ""), Spoiler . (: []) . Bread <$> (string' "#+END" >> return ""),
Bread <$> takeRest Bread <$> takeRest
] ]
parseLink :: Parser Info parseLink :: Parser URL
parseLink = undefined parseLink = try $ choice [
do
scheme <- string' "https://"
auth <- takeWhileP Nothing (/= '/')
path <- takeWhileP Nothing (/= '.')
typ <- try $ string' ".jpg" <|> string ".jpeg" <|> string' ".png" <|> string ".gif"
return $ Img $ scheme ++ auth ++ path ++ typ,
do
scheme <- string' "https://"
auth <- try $ string' "youtu.be" <|> string' "youtube.com"
path <- takeRest
return $ Vid $ scheme ++ auth ++ path,
Website <$> takeRest
]
parseCli :: [String] -> IO Post parseCli :: [String] -> IO Post
parseCli [] = return $ Post [usage] parseCli [] = return $ Post [usage]

View File

@ -7,5 +7,7 @@ So based on this we should just kill Ikka
#+Begin #+Begin
[[https://media.discordapp.net/attachments/866979075360555033/1019126077542629436/Tumblr_l_204100096696723.jpg]] [[https://media.discordapp.net/attachments/866979075360555033/1019126077542629436/Tumblr_l_204100096696723.jpg]]
[[https://youtu.be/LkoGBOs5ecM]]
[[https://acorneroftheweb.com][My website]]
sdas sdas
#+end #+end