module Text.Pandoc.Readers.Odt.Namespaces ( Namespace (..)
) where
import Data.List (isPrefixOf)
import qualified Data.Map as M (empty, insert)
import Data.Maybe (fromMaybe, listToMaybe)
import Text.Pandoc.Readers.Odt.Generic.Namespaces
instance NameSpaceID Namespace where
getInitialIRImap = nsIDmap
getNamespaceID "" m = Just(m, NsXML)
getNamespaceID iri m = asPair $ fromMaybe (NsOther iri) (findID iri)
where asPair nsID = Just (M.insert nsID iri m, nsID)
findID :: NameSpaceIRI -> Maybe Namespace
findID iri = listToMaybe [nsID | (iri',nsID) <- nsIDs, iri' `isPrefixOf` iri]
nsIDmap :: NameSpaceIRIs Namespace
nsIDmap = foldr (uncurry $ flip M.insert) M.empty nsIDs
data Namespace =
NsOffice | NsStyle | NsText | NsTable | NsForm
| NsDraw | Ns3D | NsAnim | NsChart | NsConfig
| NsDB | NsMeta | NsNumber | NsScript | NsManifest
| NsPresentation
| NsODF
| NsXSL_FO | NsSVG | NsSmil
| NsMathML | NsXForms | NsXLink | NsXHtml | NsGRDDL
| NsDublinCore
| NsPKG
| NsOpenFormula
| NsXML
| NsOther String
deriving ( Eq, Ord, Show )
nsIDs :: [(String,Namespace)]
nsIDs = [
("urn:oasis:names:tc:opendocument:xmlns:animation" , NsAnim ),
("urn:oasis:names:tc:opendocument:xmlns:chart" , NsChart ),
("urn:oasis:names:tc:opendocument:xmlns:config" , NsConfig ),
("urn:oasis:names:tc:opendocument:xmlns:database" , NsDB ),
("urn:oasis:names:tc:opendocument:xmlns:dr3d" , Ns3D ),
("urn:oasis:names:tc:opendocument:xmlns:drawing" , NsDraw ),
("urn:oasis:names:tc:opendocument:xmlns:form" , NsForm ),
("urn:oasis:names:tc:opendocument:xmlns:manifest" , NsManifest ),
("urn:oasis:names:tc:opendocument:xmlns:meta" , NsMeta ),
("urn:oasis:names:tc:opendocument:xmlns:datastyle" , NsNumber ),
("urn:oasis:names:tc:opendocument:xmlns:of" , NsOpenFormula ),
("urn:oasis:names:tc:opendocument:xmlns:office:1.0" , NsOffice ),
("urn:oasis:names:tc:opendocument:xmlns:presentation" , NsPresentation ),
("urn:oasis:names:tc:opendocument:xmlns:script" , NsScript ),
("urn:oasis:names:tc:opendocument:xmlns:style" , NsStyle ),
("urn:oasis:names:tc:opendocument:xmlns:table" , NsTable ),
("urn:oasis:names:tc:opendocument:xmlns:text" , NsText ),
("urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible", NsXSL_FO ),
("urn:oasis:names:tc:opendocument:xmlns:smil-compatible" , NsSmil ),
("urn:oasis:names:tc:opendocument:xmlns:svg-compatible" , NsSVG ),
("http://docs.oasis-open.org/ns/office/1.2/meta/odf" , NsODF ),
("http://docs.oasis-open.org/ns/office/1.2/meta/pkg" , NsPKG ),
("http://purl.org/dc/elements" , NsDublinCore ),
("http://www.w3.org/2003/g/data-view" , NsGRDDL ),
("http://www.w3.org/1998/Math/MathML" , NsMathML ),
("http://www.w3.org/1999/xhtml" , NsXHtml ),
("http://www.w3.org/2002/xforms" , NsXForms ),
("http://www.w3.org/1999/xlink" , NsXLink )
]