mirror of
https://github.com/The1Penguin/org-to-mafiauniverse.git
synced 2024-11-22 02:08:13 +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]
|
* 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
|
||||||
|
33
app/Main.hs
33
app/Main.hs
@ -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]
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user