<commit_before>-- Body of the HTML page for a package
module Distribution.Server.Pages.Package (
    packagePage,
    renderDependencies,
    renderVersion,
    renderFields,
    renderDownloads
  ) where

import Distribution.Server.Features.Packages
import Distribution.Server.Packages.Preferred

import Distribution.Server.Pages.Package.HaddockParse (parseHaddockParagraphs)
import Distribution.Server.Pages.Package.HaddockLex  (tokenise)
import Distribution.Server.Pages.Package.HaddockHtml
import Distribution.Server.Packages.ModuleForest
import Distribution.Server.Users.Types (userStatus, userName, isActive)

import Distribution.Package
import Distribution.PackageDescription as P
import Distribution.Simple.Utils ( cabalVersion )
import Distribution.Version (Version (..), VersionRange (..))
import Distribution.Text        (display)
import Text.XHtml.Strict hiding (p, name, title, content)

import Data.Maybe               (maybeToList)
import Data.List                (intersperse, intercalate)
import System.FilePath.Posix    ((</>), (<.>))
import System.Locale            (defaultTimeLocale)
import Data.Time.Format         (formatTime)

packagePage :: PackageRender -> [Html] -> [Html] -> [(String, Html)] -> [(String, Html)] -> Maybe URL -> [Html]
packagePage render headLinks top sections bottom docURL =
    [ thediv ! [identifier "package-header"] << docHeader
    , thediv ! [identifier "content"] << docBody
    , thediv ! [identifier "footer"] << docFooter
    ]
  where
    pkgid = rendPkgId render

    docHeader = [
		ulist ! [theclass "links", identifier "page-menu"] <<
			li << anchor ! [href "/"] << "hackageDB",
		paragraph ! [theclass "caption"] << docTitle]

    docTitle = display (packageName pkgid) ++ case synopsis (rendOther render) of
        "" -> ""
        short  -> ": " ++ short

    docBody =
        h1 <<
           bodyTitle :
            concat [
             renderHeads,
             top,
             pkgBody render sections,
             moduleSection render docURL,
             downloadSection render,
             map pair bottom
           ]
    bodyTitle = "The " ++ display (pkgName pkgid) ++ " package"

    renderHeads = case headLinks of
        [] -> []
        items -> [thediv ! [thestyle "font-size: small"] <<
            (map (\item -> "[" +++ item +++ "] ") items)]

    docFooter = paragraph << [
		toHtml "Produced by ",
		anchor ! [href "/"] << "hackageDB",
		toHtml " and ",
		anchor ! [href cabalHomeURL] << "Cabal",
		toHtml (" " ++ display cabalVersion)]

    pair (title, content) =
        toHtml [ h2 << title, content ]

-- | Body of the package page
pkgBody :: PackageRender -> [(String, Html)] -> [Html]
pkgBody render sections =
    prologue (description $ rendOther render) ++
    propertySection sections

prologue :: String -> [Html]
prologue [] = []
prologue desc = case parseHaddockParagraphs (tokenise desc) of
    Left _ -> [paragraph << p | p <- paragraphs desc]
    Right doc -> [markup htmlMarkup doc]

-- Break text into paragraphs (separated by blank lines)
paragraphs :: String -> [String]
paragraphs = map unlines . paras . lines
  where paras xs = case dropWhile null xs of
                [] -> []
                xs' -> case break null xs' of
                        (para, xs'') -> para : paras xs''

downloadSection :: PackageRender -> [Html]
downloadSection render =
    [ h2 << "Downloads"
    , ulist << map (li <<) downloadItems
    ]
  where downloadItems =
            [if tarExists then [anchor ! [href downloadURL] << (display pkgId ++ ".tar.gz"),
                                toHtml << " (Cabal source package)"]<commit_msg>Add link to browse package contents on package page<commit_after>-- Body of the HTML page for a package
module Distribution.Server.Pages.Package (
    packagePage,
    renderDependencies,
    renderVersion,
    renderFields,
    renderDownloads
  ) where

import Distribution.Server.Features.Packages
import Distribution.Server.Packages.Preferred

import Distribution.Server.Pages.Package.HaddockParse (parseHaddockParagraphs)
import Distribution.Server.Pages.Package.HaddockLex  (tokenise)
import Distribution.Server.Pages.Package.HaddockHtml
import Distribution.Server.Packages.ModuleForest
import Distribution.Server.Users.Types (userStatus, userName, isActive)

import Distribution.Package
import Distribution.PackageDescription as P
import Distribution.Simple.Utils ( cabalVersion )
import Distribution.Version (Version (..), VersionRange (..))
import Distribution.Text        (display)
import Text.XHtml.Strict hiding (p, name, title, content)

import Data.Maybe               (maybeToList)
import Data.List                (intersperse, intercalate)
import System.FilePath.Posix    ((</>), (<.>))
import System.Locale            (defaultTimeLocale)
import Data.Time.Format         (formatTime)

packagePage :: PackageRender -> [Html] -> [Html] -> [(String, Html)] -> [(String, Html)] -> Maybe URL -> [Html]
packagePage render headLinks top sections bottom docURL =
    [ thediv ! [identifier "package-header"] << docHeader
    , thediv ! [identifier "content"] << docBody
    , thediv ! [identifier "footer"] << docFooter
    ]
  where
    pkgid = rendPkgId render

    docHeader = [
		ulist ! [theclass "links", identifier "page-menu"] <<
			li << anchor ! [href "/"] << "hackageDB",
		paragraph ! [theclass "caption"] << docTitle]

    docTitle = display (packageName pkgid) ++ case synopsis (rendOther render) of
        "" -> ""
        short  -> ": " ++ short

    docBody =
        h1 <<
           bodyTitle :
            concat [
             renderHeads,
             top,
             pkgBody render sections,
             moduleSection render docURL,
             downloadSection render,
             map pair bottom
           ]
    bodyTitle = "The " ++ display (pkgName pkgid) ++ " package"

    renderHeads = case headLinks of
        [] -> []
        items -> [thediv ! [thestyle "font-size: small"] <<
            (map (\item -> "[" +++ item +++ "] ") items)]

    docFooter = paragraph << [
		toHtml "Produced by ",
		anchor ! [href "/"] << "hackageDB",
		toHtml " and ",
		anchor ! [href cabalHomeURL] << "Cabal",
		toHtml (" " ++ display cabalVersion)]

    pair (title, content) =
        toHtml [ h2 << title, content ]

-- | Body of the package page
pkgBody :: PackageRender -> [(String, Html)] -> [Html]
pkgBody render sections =
    prologue (description $ rendOther render) ++
    propertySection sections

prologue :: String -> [Html]
prologue [] = []
prologue desc = case parseHaddockParagraphs (tokenise desc) of
    Left _ -> [paragraph << p | p <- paragraphs desc]
    Right doc -> [markup htmlMarkup doc]

-- Break text into paragraphs (separated by blank lines)
paragraphs :: String -> [String]
paragraphs = map unlines . paras . lines
  where paras xs = case dropWhile null xs of
                [] -> []
                xs' -> case break null xs' of
                        (para, xs'') -> para : paras xs''

downloadSection :: PackageRender -> [Html]
downloadSection render =
    [ h2 << "Downloads"
    , ulist << map (li <<) downloadItems
    ]
  where downloadItems =
            [if tarExists then [anchor ! [href downloadURL] << (display pkgId ++ ".tar.gz"),
                                toHtml << " [", anchor ! [href (rendPkgUri render </> "src")] << "browse" , toHtml << "]",
                                toHtml << " (Cabal source package)"]
{'fraction_non_alphanumeric': 0.12417597201668236, 'fraction_numerical': 0.0008072110856989103, 'mean_word_length': 2.671111111111111, 'pattern_counts': {'":': 2, '<': 92, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4651653', 'n_tokens_mistral': 2139, 'n_tokens_neox': 2044, 'n_words': 605}