Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for org-mode folgezettel links #481

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions neuron/src/app/Neuron/Reader/Org.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,35 @@ where
import qualified Data.Map as Map
import Data.TagTree (Tag (Tag))
import Data.Tagged
import Data.Text (toLower)
import Data.Text (append, isSuffixOf, toLower)
import Data.Time.DateMayTime (DateMayTime, parseDateMayTime)
import Neuron.Reader.Type (ZettelParseError, ZettelReader)
import Neuron.Zettelkasten.Zettel.Meta (Meta (..))
import Relude
import Relude.Extra.Map (lookup)
import Text.Pandoc (def, runPure)
import Text.Pandoc.Definition (Pandoc)
import Text.Pandoc.Definition (Inline (Link), Pandoc)
import Text.Pandoc.Readers.Org (readOrg)
import Text.Pandoc.Util (getH1)
import Text.Pandoc.Walk (walk)

parseOrg :: ZettelReader
parseOrg _ s = do
doc <- first show $ runPure $ readOrg def s
docWithChanges <- pure $ changeLinkTypes doc
meta <- extractMetadata doc
pure (meta, doc)
pure (meta, docWithChanges)

-- | Modifies links parsing to that pandoc AST has type/branch parameters
changeLinkTypes :: Pandoc -> Pandoc
changeLinkTypes = walk modLink
where
modLink :: Inline -> Inline
modLink (Link a b t) = Link a b (replaceTarget t)
modLink x = x
replaceTarget (url, title)
| not $ isSuffixOf "?cf" url = (append url "?type=branch", title)
| otherwise = (url, title)

-- | Extract metadata from the properties that are attached to the first headline
extractMetadata :: Pandoc -> Either ZettelParseError (Maybe Meta)
Expand Down