g                        -- ^ Pointer to the 'Config' for use with the @'toCategory'@ function.
       -> [Header]                      -- ^ List of the 'Table' 'Header's.
       -> [Category]                    -- ^ A list of 'Category' objects associated with this 'Course'.
       -> [Cursor]                      -- ^ The list of unprocessed rows in the 'Table'.
       -> ([Category], Maybe Course)    -- ^ A single row, containing 'Category's and the 'Course' data (if any).
getRow cnf@Config{..} headers cats cs = map (T.unwords . ($// content)) cs `go` head (cs !! 1 $| attribute "class")
  where
    go []        _       = (cats, Nothing)
    go (mc : vs) classes = case toCategory cnf mc of
            Just cat                        -> (accumCategory cnf cat cats, Nothing)
            Nothing | null vs               -> (cats, Nothing)
                    | T.null (normalize mc) -> (cats, Just $ toCourse cnf cats headers (classCur `T.isInfixOf` classes) vs)
                    | otherwise             -> (cats, Just $ toCourse cnf cats headers (classCur `T.isInfixOf` classes) vs)


-- =============================================================================
-- ** Courses and categories
-- =============================================================================


{- | Checks if the given 'Text' is a 'Category' listed in the /config.yaml/
    file. If it is, then it will return the name of the 'Category' otherwise
    it'll return an empty 'Text'.

    Because the Wiki Table column containing the categories also contains
    semester information or empty cells, the function has to exclude those
    cells before checking the 'Category' name.
-}
toCategory :: 
getRow :: Config                        -- ^ Pointer to the 'Config' for use with the @'toCategory'@ function.
       -> [Header]                      -- ^ List of the 'Table' 'Header's.
       -> [Category]                    -- ^ A list of 'Category' objects associated with this 'Course'.
       -> [Cursor]                      -- ^ The list of unprocessed rows in the 'Table'.
       -> ([Category], Maybe Course)
getRow cnf@Config{..} headers cats cs = map (T.unwords . ($// content)) cs `go` head (cs !! 1 $| attribute "class")
  where
    go []        _       = (cats, Nothing)
    go (mc : vs) classes = case toCategory cnf mc of
            Just cat                        -> (accumCategory cnf cat cats, Nothing)
            Nothing | null vs               -> (cats, Nothing)
                    | T.null (normalize mc) -> (cats, Just $ toCourse cnf cats headers (classCur `T.isInfixOf` classes) vs)
                    | otherwise             -> (cats, Just $ toCourse cnf cats headers (classCur `T.isInfixOf` classes) vs)


-- =============================================================================
-- ** Courses and categories
-- =============================================================================


{- | Checks if the given 'Text' is a 'Category' listed in the /config.yaml/
    file. If it is, then it will return the name of the 'Category' otherwise
    it'll return an empty 'Text'.

    Because the Wiki Table column containing the categories also contains
    semester information or empty cells, the function has to exclude those
    cells before checking the 'Category' name.
-}
getRow cnf@Config{..} headers cats cs = map (T.unwords . ($// content)) cs `go` head (cs !! 1 $| attribute "class")
  where
    go []        _       = (cats, Nothing)
    go (mc : vs) classes = case toCategory cnf mc of
            Just cat                        -> (accumCategory cnf cat cats, Nothing)
            Nothing | null vs               -> (cats, Nothing)
                    | T.null (normalize mc) -> (cats, Just $ toCourse cnf cats headers (classCur `T.isInfixOf` classes) vs)
                    | otherwise             -> (cats, Just $ toCourse cnf cats headers (classCur `T.isInfixOf` classes) vs)


-- =============================================================================
-- ** Courses and categories
-- =============================================================================


{- | Checks if the given 'Text' is a 'Category' listed in the /config.yaml/
    file. If it is, then it will return the name of the 'Category' otherwise
    it'll return an empty 'Text'.

    Because the Wiki Table column containing the categories also contains
    semester information or empty cells, the function has to exclude those
    cells before checking the 'Category' name.
-}