mirror of
https://github.com/The1Penguin/org-to-mafiauniverse.git
synced 2024-11-21 17:58:12 +00:00
Issues with links
This commit is contained in:
parent
813debec5d
commit
02da1f666a
@ -18,3 +18,6 @@ The name is pronounced like autumn.
|
||||
* Todo [0/2]
|
||||
- [ ] Image or Video parser
|
||||
- [ ] 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
|
||||
|
33
app/Main.hs
33
app/Main.hs
@ -11,7 +11,8 @@ import Text.Megaparsec.Char
|
||||
|
||||
type Parser = Parsec Void String
|
||||
|
||||
newtype URL = URL String
|
||||
data URL = Img String | Vid String | Website String
|
||||
deriving (Show)
|
||||
|
||||
data Info =
|
||||
Bread String |
|
||||
@ -32,10 +33,11 @@ instance Show Info where
|
||||
Header text -> "[TITLE]" ++ text ++ "[/TITLE]\n"
|
||||
Subheader text -> "[SIZE=4]" ++ text ++ "[/SIZE]\n"
|
||||
Subsubheader text -> "[SIZE=2]" ++ text ++ "[/SIZE]\n"
|
||||
Image (URL url) -> "[IMG]" ++ url ++ "[/IMG]\n"
|
||||
Video (URL url) -> "[VIDEO]" ++ url ++ "[/VIDEO]\n"
|
||||
Link (URL url) inf -> "[URL=\"" ++ url ++ "\"]" ++ show inf ++ "[/URL]\n"
|
||||
Image (Img url) -> "[IMG]" ++ url ++ "[/IMG]\n"
|
||||
Video (Vid url) -> "[VIDEO]" ++ url ++ "[/VIDEO]\n"
|
||||
Link (Website url) inf -> "[URL=\"" ++ url ++ "\"]" ++ show inf ++ "[/URL]\n"
|
||||
Spoiler inf -> "[SPOILER]" ++ concatMap show inf ++ "[/SPOILER]\n"
|
||||
_ -> error "Something went wrong with showing the parsed information"
|
||||
|
||||
newtype Post = Post [Info]
|
||||
|
||||
@ -67,16 +69,29 @@ fileParser =
|
||||
Subsubheader <$> (string' "*** " >> takeRest),
|
||||
List . (: []) . Bread <$> (string' "- " >> takeRest),
|
||||
-- Image and video needs to know if it is a image or video
|
||||
Image . URL <$> between (string' "[[") (string' "]]") (takeWhileP Nothing (/= ']')),
|
||||
Video . URL <$> between (string' "[[") (string' "]]") (takeWhileP Nothing (/= ']')),
|
||||
-- parseLink,
|
||||
Image <$> between (string' "[[") (string' "]]") parseLink,
|
||||
Video <$> between (string' "[[") (string' "]]") parseLink,
|
||||
-- (takeWhileP Nothing (/= ']')),
|
||||
Spoiler . (: []) . Bread <$> (string' "#+BEGIN" >> return ""),
|
||||
Spoiler . (: []) . Bread <$> (string' "#+END" >> return ""),
|
||||
Bread <$> takeRest
|
||||
]
|
||||
|
||||
parseLink :: Parser Info
|
||||
parseLink = undefined
|
||||
parseLink :: Parser URL
|
||||
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 [] = return $ Post [usage]
|
||||
|
@ -7,5 +7,7 @@ So based on this we should just kill Ikka
|
||||
|
||||
#+Begin
|
||||
[[https://media.discordapp.net/attachments/866979075360555033/1019126077542629436/Tumblr_l_204100096696723.jpg]]
|
||||
[[https://youtu.be/LkoGBOs5ecM]]
|
||||
[[https://acorneroftheweb.com][My website]]
|
||||
sdas
|
||||
#+end
|
||||
|
Loading…
Reference in New Issue
Block a user