@@ -0,0 +1,614 @@
1+module Text.Pandoc.Readers.DocBook ( readDocBook ) where
2+import Text.Pandoc.Parsing (ParserState(..))
3+import Text.Pandoc.Definition
4+import Text.Pandoc.Builder
6+import Data.Maybe (fromMaybe)
8+import Data.Char (isSpace)
9+import Control.Monad.State
10+import Control.Applicative ((<$>))
14+List of all DocBook tags, with [x] indicating implemented:
16+[ ] abbrev - An abbreviation, especially one followed by a period
17+[x] abstract - A summary
18+[ ] accel - A graphical user interface (GUI) keyboard shortcut
19+[ ] ackno - Acknowledgements in an Article
20+[ ] acronym - An often pronounceable word made from the initial
21+[ ] action - A response to a user event
22+[ ] address - A real-world address, generally a postal address
23+[ ] affiliation - The institutional affiliation of an individual
24+[ ] alt - Text representation for a graphical element
25+[ ] anchor - A spot in the document
26+[ ] answer - An answer to a question posed in a QandASet
27+[ ] appendix - An appendix in a Book or Article
28+[ ] appendixinfo - Meta-information for an Appendix
29+[ ] application - The name of a software program
30+[ ] area - A region defined for a Callout in a graphic or code example
31+[ ] areaset - A set of related areas in a graphic or code example
32+[ ] areaspec - A collection of regions in a graphic or code example
33+[ ] arg - An argument in a CmdSynopsis
34+[ ] article - An article
35+[x] articleinfo - Meta-information for an Article
36+[ ] artpagenums - The page numbers of an article as published
37+[ ] attribution - The source of a block quote or epigraph
38+[ ] audiodata - Pointer to external audio data
39+[ ] audioobject - A wrapper for audio data and its associated meta-information
40+[x] author - The name of an individual author
41+[ ] authorblurb - A short description or note about an author
42+[ ] authorgroup - Wrapper for author information when a document has
43+ multiple authors or collabarators
44+[ ] authorinitials - The initials or other short identifier for an author
45+[ ] beginpage - The location of a page break in a print version of the document
46+[ ] bibliocoverage - The spatial or temporal coverage of a document
47+[ ] bibliodiv - A section of a Bibliography
48+[ ] biblioentry - An entry in a Bibliography
49+[ ] bibliography - A bibliography
50+[ ] bibliographyinfo - Meta-information for a Bibliography
51+[ ] biblioid - An identifier for a document
52+[ ] bibliolist - A wrapper for a set of bibliography entries
53+[ ] bibliomisc - Untyped bibliographic information
54+[ ] bibliomixed - An entry in a Bibliography
55+[ ] bibliomset - A cooked container for related bibliographic information
56+[ ] biblioref - A cross reference to a bibliographic entry
57+[ ] bibliorelation - The relationship of a document to another
58+[ ] biblioset - A raw container for related bibliographic information
59+[ ] bibliosource - The source of a document
60+[ ] blockinfo - Meta-information for a block element
61+[x] blockquote - A quotation set off from the main text
63+[ ] bookinfo - Meta-information for a Book
64+[ ] bridgehead - A free-floating heading
65+[ ] callout - A “called out” description of a marked Area
66+[ ] calloutlist - A list of Callouts
67+[ ] caption - A caption
68+[ ] caution - A note of caution
69+[ ] chapter - A chapter, as of a book
70+[ ] chapterinfo - Meta-information for a Chapter
71+[ ] citation - An inline bibliographic reference to another published work
72+[ ] citebiblioid - A citation of a bibliographic identifier
73+[ ] citerefentry - A citation to a reference page
74+[ ] citetitle - The title of a cited work
75+[ ] city - The name of a city in an address
76+[ ] classname - The name of a class, in the object-oriented programming sense
77+[ ] classsynopsis - The syntax summary for a class definition
78+[ ] classsynopsisinfo - Information supplementing the contents of
80+[ ] cmdsynopsis - A syntax summary for a software command
81+[ ] co - The location of a callout embedded in text
82+[x] code - An inline code fragment
83+[ ] col - Specifications for a column in an HTML table
84+[ ] colgroup - A group of columns in an HTML table
85+[ ] collab - Identifies a collaborator
86+[ ] collabname - The name of a collaborator
87+[ ] colophon - Text at the back of a book describing facts about its production
88+[ ] colspec - Specifications for a column in a table
89+[ ] command - The name of an executable program or other software command
90+[ ] computeroutput - Data, generally text, displayed or presented by a computer
91+[ ] confdates - The dates of a conference for which a document was written
92+[ ] confgroup - A wrapper for document meta-information about a conference
93+[ ] confnum - An identifier, frequently numerical, associated with a conference for which a document was written
94+[ ] confsponsor - The sponsor of a conference for which a document was written
95+[ ] conftitle - The title of a conference for which a document was written
96+[x] constant - A programming or system constant
97+[ ] constraint - A constraint in an EBNF production
98+[ ] constraintdef - The definition of a constraint in an EBNF production
99+[ ] constructorsynopsis - A syntax summary for a constructor
100+[ ] contractnum - The contract number of a document
101+[ ] contractsponsor - The sponsor of a contract
102+[ ] contrib - A summary of the contributions made to a document by a
104+[ ] copyright - Copyright information about a document
105+[ ] coref - A cross reference to a co
106+[ ] corpauthor - A corporate author, as opposed to an individual
107+[ ] corpcredit - A corporation or organization credited in a document
108+[ ] corpname - The name of a corporation
109+[ ] country - The name of a country
110+[ ] database - The name of a database, or part of a database
111+[x] date - The date of publication or revision of a document
112+[ ] dedication - A wrapper for the dedication section of a book
113+[ ] destructorsynopsis - A syntax summary for a destructor
114+[ ] edition - The name or number of an edition of a document
115+[ ] editor - The name of the editor of a document
116+[ ] email - An email address
117+[x] emphasis - Emphasized text
118+[ ] entry - A cell in a table
119+[ ] entrytbl - A subtable appearing in place of an Entry in a table
120+[ ] envar - A software environment variable
121+[ ] epigraph - A short inscription at the beginning of a document or component
122+[ ] equation - A displayed mathematical equation
123+[ ] errorcode - An error code
124+[ ] errorname - An error name
125+[ ] errortext - An error message.
126+[ ] errortype - The classification of an error message
127+[ ] example - A formal example, with a title
128+[ ] exceptionname - The name of an exception
129+[ ] fax - A fax number
130+[ ] fieldsynopsis - The name of a field in a class definition
131+[ ] figure - A formal figure, generally an illustration, with a title
132+[ ] filename - The name of a file
133+[ ] firstname - The first name of a person
134+[ ] firstterm - The first occurrence of a term
135+[ ] footnote - A footnote
136+[ ] footnoteref - A cross reference to a footnote (a footnote mark)
137+[ ] foreignphrase - A word or phrase in a language other than the primary
138+ language of the document
139+[ ] formalpara - A paragraph with a title
140+[ ] funcdef - A function (subroutine) name and its return type
141+[ ] funcparams - Parameters for a function referenced through a function
142+ pointer in a synopsis
143+[ ] funcprototype - The prototype of a function
144+[ ] funcsynopsis - The syntax summary for a function definition
145+[ ] funcsynopsisinfo - Information supplementing the FuncDefs of a FuncSynopsis
146+[x] function - The name of a function or subroutine, as in a
147+ programming language
148+[ ] glossary - A glossary
149+[ ] glossaryinfo - Meta-information for a Glossary
150+[ ] glossdef - A definition in a GlossEntry
151+[ ] glossdiv - A division in a Glossary
152+[ ] glossentry - An entry in a Glossary or GlossList
153+[ ] glosslist - A wrapper for a set of GlossEntrys
154+[ ] glosssee - A cross-reference from one GlossEntry to another
155+[ ] glossseealso - A cross-reference from one GlossEntry to another
156+[ ] glossterm - A glossary term
157+[ ] graphic - A displayed graphical object (not an inline)
158+[ ] graphicco - A graphic that contains callout areas
159+[ ] group - A group of elements in a CmdSynopsis
160+[ ] guibutton - The text on a button in a GUI
161+[ ] guiicon - Graphic and/or text appearing as a icon in a GUI
162+[ ] guilabel - The text of a label in a GUI
163+[ ] guimenu - The name of a menu in a GUI
164+[ ] guimenuitem - The name of a terminal menu item in a GUI
165+[ ] guisubmenu - The name of a submenu in a GUI
166+[ ] hardware - A physical part of a computer system
167+[ ] highlights - A summary of the main points of the discussed component
168+[ ] holder - The name of the individual or organization that holds a copyright
169+[ ] honorific - The title of a person
170+[ ] html:form - An HTML form
171+[ ] imagedata - Pointer to external image data
172+[ ] imageobject - A wrapper for image data and its associated meta-information
173+[ ] imageobjectco - A wrapper for an image object with callouts
174+[ ] important - An admonition set off from the text
176+[ ] indexdiv - A division in an index
177+[ ] indexentry - An entry in an index
178+[ ] indexinfo - Meta-information for an Index
179+[ ] indexterm - A wrapper for terms to be indexed
180+[ ] info - A wrapper for information about a component or other block. (DocBook v5)
181+[ ] informalequation - A displayed mathematical equation without a title
182+[ ] informalexample - A displayed example without a title
183+[ ] informalfigure - A untitled figure
184+[ ] informaltable - A table without a title
185+[ ] initializer - The initializer for a FieldSynopsis
186+[ ] inlineequation - A mathematical equation or expression occurring inline
187+[ ] inlinegraphic - An object containing or pointing to graphical data
188+ that will be rendered inline
189+[ ] inlinemediaobject - An inline media object (video, audio, image, and so on)
190+[ ] interface - An element of a GUI
191+[ ] interfacename - The name of an interface
192+[ ] invpartnumber - An inventory part number
193+[ ] isbn - The International Standard Book Number of a document
194+[ ] issn - The International Standard Serial Number of a periodical
195+[ ] issuenum - The number of an issue of a journal
196+[x] itemizedlist - A list in which each entry is marked with a bullet or
198+[ ] itermset - A set of index terms in the meta-information of a document
199+[ ] jobtitle - The title of an individual in an organization
200+[ ] keycap - The text printed on a key on a keyboard
201+[ ] keycode - The internal, frequently numeric, identifier for a key
203+[ ] keycombo - A combination of input actions
204+[ ] keysym - The symbolic name of a key on a keyboard
205+[ ] keyword - One of a set of keywords describing the content of a document
206+[ ] keywordset - A set of keywords describing the content of a document
207+[ ] label - A label on a Question or Answer
208+[ ] legalnotice - A statement of legal obligations or requirements
209+[ ] lhs - The left-hand side of an EBNF production
210+[ ] lineage - The portion of a person's name indicating a relationship to
212+[ ] lineannotation - A comment on a line in a verbatim listing
213+[x] link - A hypertext link
214+[ ] listitem - A wrapper for the elements of a list item
215+[x] literal - Inline text that is some literal value
216+[ ] literallayout - A block of text in which line breaks and white space are
217+ to be reproduced faithfully
218+[ ] lot - A list of the titles of formal objects (as tables or figures) in
220+[ ] lotentry - An entry in a list of titles
221+[ ] manvolnum - A reference volume number
222+[ ] markup - A string of formatting markup in text that is to be
223+ represented literally
224+[ ] mathphrase - A mathematical phrase, an expression that can be represented
225+ with ordinary text and a small amount of markup
226+[ ] medialabel - A name that identifies the physical medium on which some
228+[ ] mediaobject - A displayed media object (video, audio, image, etc.)
229+[ ] mediaobjectco - A media object that contains callouts
230+[ ] member - An element of a simple list
231+[ ] menuchoice - A selection or series of selections from a menu
232+[ ] methodname - The name of a method
233+[ ] methodparam - Parameters to a method
234+[ ] methodsynopsis - A syntax summary for a method
235+[ ] mml:math - A MathML equation
236+[ ] modespec - Application-specific information necessary for the
237+ completion of an OLink
238+[ ] modifier - Modifiers in a synopsis
239+[ ] mousebutton - The conventional name of a mouse button
240+[ ] msg - A message in a message set
241+[ ] msgaud - The audience to which a message in a message set is relevant
242+[ ] msgentry - A wrapper for an entry in a message set
243+[ ] msgexplan - Explanatory material relating to a message in a message set
244+[ ] msginfo - Information about a message in a message set
245+[ ] msglevel - The level of importance or severity of a message in a message set
246+[ ] msgmain - The primary component of a message in a message set
247+[ ] msgorig - The origin of a message in a message set
248+[ ] msgrel - A related component of a message in a message set
249+[ ] msgset - A detailed set of messages, usually error messages
250+[ ] msgsub - A subcomponent of a message in a message set
251+[ ] msgtext - The actual text of a message component in a message set
252+[ ] nonterminal - A non-terminal in an EBNF production
253+[ ] note - A message set off from the text
254+[ ] objectinfo - Meta-information for an object
255+[ ] olink - A link that addresses its target indirectly, through an entity
256+[ ] ooclass - A class in an object-oriented programming language
257+[ ] ooexception - An exception in an object-oriented programming language
258+[ ] oointerface - An interface in an object-oriented programming language
259+[ ] option - An option for a software command
260+[ ] optional - Optional information
261+[x] orderedlist - A list in which each entry is marked with a sequentially
263+[ ] orgdiv - A division of an organization
264+[ ] orgname - The name of an organization other than a corporation
265+[ ] otheraddr - Uncategorized information in address
266+[ ] othercredit - A person or entity, other than an author or editor,
267+ credited in a document
268+[ ] othername - A component of a persons name that is not a first name,
270+[ ] package - A package
271+[ ] pagenums - The numbers of the pages in a book, for use in a bibliographic
273+[x] para - A paragraph
274+[ ] paramdef - Information about a function parameter in a programming language
275+[ ] parameter - A value or a symbolic reference to a value
276+[ ] part - A division in a book
277+[ ] partinfo - Meta-information for a Part
278+[ ] partintro - An introduction to the contents of a part
279+[ ] personblurb - A short description or note about a person
280+[ ] personname - The personal name of an individual
281+[ ] phone - A telephone number
282+[ ] phrase - A span of text
283+[ ] pob - A post office box in an address
284+[ ] postcode - A postal code in an address
285+[ ] preface - Introductory matter preceding the first chapter of a book
286+[ ] prefaceinfo - Meta-information for a Preface
287+[ ] primary - The primary word or phrase under which an index term should be
289+[ ] primaryie - A primary term in an index entry, not in the text
290+[ ] printhistory - The printing history of a document
291+[ ] procedure - A list of operations to be performed in a well-defined sequence
292+[ ] production - A production in a set of EBNF productions
293+[ ] productionrecap - A cross-reference to an EBNF production
294+[ ] productionset - A set of EBNF productions
295+[ ] productname - The formal name of a product
296+[ ] productnumber - A number assigned to a product
297+[ ] programlisting - A literal listing of all or part of a program
298+[ ] programlistingco - A program listing with associated areas used in callouts
299+[ ] prompt - A character or string indicating the start of an input field in
301+[ ] property - A unit of data associated with some part of a computer system
302+[ ] pubdate - The date of publication of a document
303+[ ] publisher - The publisher of a document
304+[ ] publishername - The name of the publisher of a document
305+[ ] pubsnumber - A number assigned to a publication other than an ISBN or ISSN
306+ or inventory part number
307+[ ] qandadiv - A titled division in a QandASet
308+[ ] qandaentry - A question/answer set within a QandASet
309+[ ] qandaset - A question-and-answer set
310+[ ] question - A question in a QandASet
311+[ ] quote - An inline quotation
312+[ ] refclass - The scope or other indication of applicability of a
314+[ ] refdescriptor - A description of the topic of a reference page
315+[ ] refentry - A reference page (originally a UNIX man-style reference page)
316+[ ] refentryinfo - Meta-information for a Refentry
317+[ ] refentrytitle - The title of a reference page
318+[ ] reference - A collection of reference entries
319+[ ] referenceinfo - Meta-information for a Reference
320+[ ] refmeta - Meta-information for a reference entry
321+[ ] refmiscinfo - Meta-information for a reference entry other than the title
323+[ ] refname - The name of (one of) the subject(s) of a reference page
324+[ ] refnamediv - The name, purpose, and classification of a reference page
325+[ ] refpurpose - A short (one sentence) synopsis of the topic of a reference
327+[ ] refsect1 - A major subsection of a reference entry
328+[ ] refsect1info - Meta-information for a RefSect1
329+[ ] refsect2 - A subsection of a RefSect1
330+[ ] refsect2info - Meta-information for a RefSect2
331+[ ] refsect3 - A subsection of a RefSect2
332+[ ] refsect3info - Meta-information for a RefSect3
333+[ ] refsection - A recursive section in a refentry
334+[ ] refsectioninfo - Meta-information for a refsection
335+[ ] refsynopsisdiv - A syntactic synopsis of the subject of the reference page
336+[ ] refsynopsisdivinfo - Meta-information for a RefSynopsisDiv
337+[ ] releaseinfo - Information about a particular release of a document
338+[ ] remark - A remark (or comment) intended for presentation in a draft
340+[ ] replaceable - Content that may or must be replaced by the user
341+[ ] returnvalue - The value returned by a function
342+[ ] revdescription - A extended description of a revision to a document
343+[ ] revhistory - A history of the revisions to a document
344+[ ] revision - An entry describing a single revision in the history of the
345+ revisions to a document
346+[ ] revnumber - A document revision number
347+[ ] revremark - A description of a revision to a document
348+[ ] rhs - The right-hand side of an EBNF production
349+[ ] row - A row in a table
350+[ ] sbr - An explicit line break in a command synopsis
351+[ ] screen - Text that a user sees or might see on a computer screen
352+[ ] screenco - A screen with associated areas used in callouts
353+[ ] screeninfo - Information about how a screen shot was produced
354+[ ] screenshot - A representation of what the user sees or might see on a
356+[ ] secondary - A secondary word or phrase in an index term
357+[ ] secondaryie - A secondary term in an index entry, rather than in the text
358+[x] sect1 - A top-level section of document
359+[ ] sect1info - Meta-information for a Sect1
360+[x] sect2 - A subsection within a Sect1
361+[ ] sect2info - Meta-information for a Sect2
362+[x] sect3 - A subsection within a Sect2
363+[ ] sect3info - Meta-information for a Sect3
364+[x] sect4 - A subsection within a Sect3
365+[ ] sect4info - Meta-information for a Sect4
366+[x] sect5 - A subsection within a Sect4
367+[ ] sect5info - Meta-information for a Sect5
368+[x] section - A recursive section
369+[ ] sectioninfo - Meta-information for a recursive section
370+[ ] see - Part of an index term directing the reader instead to another entry
372+[ ] seealso - Part of an index term directing the reader also to another entry
374+[ ] seealsoie - A See also entry in an index, rather than in the text
375+[ ] seeie - A See entry in an index, rather than in the text
376+[ ] seg - An element of a list item in a segmented list
377+[ ] seglistitem - A list item in a segmented list
378+[ ] segmentedlist - A segmented list, a list of sets of elements
379+[ ] segtitle - The title of an element of a list item in a segmented list
380+[ ] seriesvolnums - Numbers of the volumes in a series of books
381+[ ] set - A collection of books
382+[ ] setindex - An index to a set of books
383+[ ] setindexinfo - Meta-information for a SetIndex
384+[ ] setinfo - Meta-information for a Set
385+[ ] sgmltag - A component of SGML markup
386+[ ] shortaffil - A brief description of an affiliation
387+[ ] shortcut - A key combination for an action that is also accessible through
389+[ ] sidebar - A portion of a document that is isolated from the main
391+[ ] sidebarinfo - Meta-information for a Sidebar
392+[ ] simpara - A paragraph that contains only text and inline markup, no block
394+[ ] simplelist - An undecorated list of single words or short phrases
395+[ ] simplemsgentry - A wrapper for a simpler entry in a message set
396+[ ] simplesect - A section of a document with no subdivisions
397+[ ] spanspec - Formatting information for a spanned column in a table
398+[ ] state - A state or province in an address
399+[ ] step - A unit of action in a procedure
400+[ ] stepalternatives - Alternative steps in a procedure
401+[ ] street - A street address in an address
402+[ ] structfield - A field in a structure (in the programming language sense)
403+[ ] structname - The name of a structure (in the programming language sense)
404+[ ] subject - One of a group of terms describing the subject matter of a
406+[ ] subjectset - A set of terms describing the subject matter of a document
407+[ ] subjectterm - A term in a group of terms describing the subject matter of
409+[x] subscript - A subscript (as in H2O, the molecular formula for water)
410+[ ] substeps - A wrapper for steps that occur within steps in a procedure
411+[ ] subtitle - The subtitle of a document
412+[x] superscript - A superscript (as in x2, the mathematical notation for x
413+ multiplied by itself)
414+[ ] surname - A family name; in western cultures the last name
415+[ ] svg:svg - An SVG graphic
416+[x] symbol - A name that is replaced by a value before processing
417+[ ] synopfragment - A portion of a CmdSynopsis broken out from the main body
419+[ ] synopfragmentref - A reference to a fragment of a command synopsis
420+[ ] synopsis - A general-purpose element for representing the syntax of
421+ commands or functions
422+[ ] systemitem - A system-related item or term
423+[ ] table - A formal table in a document
424+[ ] task - A task to be completed
425+[ ] taskprerequisites - The prerequisites for a task
426+[ ] taskrelated - Information related to a task
427+[ ] tasksummary - A summary of a task
428+[ ] tbody - A wrapper for the rows of a table or informal table
429+[ ] td - A table entry in an HTML table
430+[ ] term - The word or phrase being defined or described in a variable list
431+[ ] termdef - An inline term definition
432+[ ] tertiary - A tertiary word or phrase in an index term
433+[ ] tertiaryie - A tertiary term in an index entry, rather than in the text
434+[ ] textdata - Pointer to external text data
435+[ ] textobject - A wrapper for a text description of an object and its
436+ associated meta-information
437+[ ] tfoot - A table footer consisting of one or more rows
438+[ ] tgroup - A wrapper for the main content of a table, or part of a table
439+[ ] th - A table header entry in an HTML table
440+[ ] thead - A table header consisting of one or more rows
441+[ ] tip - A suggestion to the user, set off from the text
442+[x] title - The text of the title of a section of a document or of a formal
444+[ ] titleabbrev - The abbreviation of a Title
445+[ ] toc - A table of contents
446+[ ] tocback - An entry in a table of contents for a back matter component
447+[ ] tocchap - An entry in a table of contents for a component in the body of
449+[ ] tocentry - A component title in a table of contents
450+[ ] tocfront - An entry in a table of contents for a front matter component
451+[ ] toclevel1 - A top-level entry within a table of contents entry for a
452+ chapter-like component
453+[ ] toclevel2 - A second-level entry within a table of contents entry for a
454+ chapter-like component
455+[ ] toclevel3 - A third-level entry within a table of contents entry for a
456+ chapter-like component
457+[ ] toclevel4 - A fourth-level entry within a table of contents entry for a
458+ chapter-like component
459+[ ] toclevel5 - A fifth-level entry within a table of contents entry for a
460+ chapter-like component
461+[ ] tocpart - An entry in a table of contents for a part of a book
462+[ ] token - A unit of information
463+[ ] tr - A row in an HTML table
464+[ ] trademark - A trademark
465+[ ] type - The classification of a value
466+[x] ulink - A link that addresses its target by means of a URL
467+ (Uniform Resource Locator)
468+[ ] uri - A Uniform Resource Identifier
469+[ ] userinput - Data entered by the user
470+[x] varargs - An empty element in a function synopsis indicating a variable
472+[ ] variablelist - A list in which each entry is composed of a set of one or
473+ more terms and an associated description
474+[ ] varlistentry - A wrapper for a set of terms and the associated description
476+[x] varname - The name of a variable
477+[ ] videodata - Pointer to external video data
478+[ ] videoobject - A wrapper for video data and its associated meta-information
479+[ ] void - An empty element in a function synopsis indicating that the
480+ function in question takes no arguments
481+[ ] volumenum - The volume number of a document in a set (as of books in a set
482+ or articles in a journal)
483+[ ] warning - An admonition set off from the text
484+[ ] wordasword - A word meant specifically as a word and not representing
486+[ ] xref - A cross reference to another part of the document
487+[ ] year - The year of publication of a document
491+type DB = State DBState
493+data DBState = DBState{ dbSectionLevel :: Int
494+ , dbQuoteType :: QuoteType
495+ , dbDocTitle :: Inlines
496+ , dbDocAuthors :: [Inlines]
497+ , dbDocDate :: Inlines
500+readDocBook :: ParserState -> String -> Pandoc
501+readDocBook st inp = setTitle (dbDocTitle st')
502+ $ setAuthors (dbDocAuthors st')
503+ $ setDate (dbDocDate st')
505+ where (bs, st') = runState (mapM parseBlock $ parseXML inp)
506+ DBState{ dbSectionLevel = 0
507+ , dbQuoteType = DoubleQuote
508+ , dbDocTitle = mempty
510+ , dbDocDate = mempty
513+parseBlock :: Content -> DB Blocks
514+parseBlock (Text (CData CDataRaw _ _)) = return mempty -- DOCTYPE
515+parseBlock (Text (CData _ s _)) = if all isSpace s
517+ else return $ plain $ text s
518+parseBlock (Elem e) =
519+ case qName (elName e) of
520+ "para" -> para <$> getInlines e
521+ "blockquote" -> blockQuote <$> getBlocks e
527+ "section" -> gets dbSectionLevel >>= sect . (+1)
528+ "abstract" -> blockQuote <$> getBlocks e
529+ "itemizedlist" -> bulletList <$> listitems
530+ "orderedlist" -> orderedList <$> listitems -- TODO list attributes
531+ "info" -> getTitle >> getAuthors >> getDate >> return mempty
532+ "articleinfo" -> getTitle >> getAuthors >> getDate >> return mempty
533+ "programlisting" -> return $ codeBlock $ strContent e -- TODO attrs
534+ "?xml" -> return mempty
536+ where getBlocks e' = mconcat <$> (mapM parseBlock $ elContent e')
537+ getInlines e' = (trimInlines . mconcat) <$>
538+ (mapM parseInline $ elContent e')
539+ isTitle e' = qName (elName e') == "title"
540+ skipWhite (Text (CData _ s _):xs) | all isSpace s = skipWhite xs
543+ listitems = mapM getBlocks $ findChildren (unqual "listitem") e
544+ getTitle = case findChild (unqual "title") e of
547+ modify $ \st -> st{dbDocTitle = tit}
548+ Nothing -> return ()
550+ auths <- mapM getInlines
551+ $ findChildren (unqual "author") e
552+ modify $ \st -> st{dbDocAuthors = auths}
553+ getDate = case findChild (unqual "date") e of
556+ modify $ \st -> st{dbDocDate = dat}
557+ Nothing -> return ()
558+ sect n = case skipWhite (elContent e) of
561+ h <- header n <$> (getInlines t)
562+ modify $ \st -> st{ dbSectionLevel = n }
563+ b <- mconcat <$> (mapM parseBlock body)
564+ modify $ \st -> st{ dbSectionLevel = n - 1 }
567+ let h = header n mempty
568+ modify $ \st -> st{ dbSectionLevel = n }
569+ b <- mconcat <$> (mapM parseBlock body)
570+ modify $ \st -> st{ dbSectionLevel = n - 1 }
572+parseBlock (CRef _) = return mempty
574+parseInline :: Content -> DB Inlines
575+parseInline (Text (CData _ s _)) = return $ text s
576+parseInline (Elem e) =
577+ case qName (elName e) of
578+ "subscript" -> subscript <$> innerInlines
579+ "superscript" -> superscript <$> innerInlines
581+ qt <- gets dbQuoteType
582+ let qt' = if qt == SingleQuote then DoubleQuote else SingleQuote
583+ modify $ \st -> st{ dbQuoteType = qt' }
584+ contents <- innerInlines
585+ modify $ \st -> st{ dbQuoteType = qt }
586+ return $ if qt == SingleQuote
587+ then singleQuoted contents
588+ else doubleQuoted contents
589+ "code" -> return $ code $ strContent e -- TODO attrs
590+ "literal" -> return $ code $ strContent e -- TODO attrs
591+ "varname" -> return $ codeWith ("",["varname"],[]) $ strContent e
592+ "function" -> return $ codeWith ("",["function"],[]) $ strContent e
593+ "type" -> return $ codeWith ("",["type"],[]) $ strContent e
594+ "symbol" -> return $ codeWith ("",["symbol"],[]) $ strContent e
595+ "constant" -> return $ codeWith ("",["constant"],[]) $ strContent e
596+ "userinput" -> return $ codeWith ("",["userinput"],[]) $ strContent e
597+ "varargs" -> return $ str "(…)"
599+ (fromMaybe "" (lookupAttrBy (\attr -> qName attr == "url")
600+ (elAttribs e))) "" <$> innerInlines
601+ "link" -> case findAttr (QName "href" Nothing $ Just "xlink") e of
602+ Just href -> link href "" <$> innerInlines
603+ _ -> link ("#"++(fromMaybe "" (lookupAttrBy
604+ (\attr -> qName attr == "linkend")
605+ (elAttribs e)))) "" <$> innerInlines
606+ "emphasis" -> case lookupAttrBy (\attr -> qName attr == "role")
608+ Just "strong" -> strong <$> innerInlines
609+ _ -> emph <$> innerInlines
610+ "footnote" -> (note . mconcat) <$> (mapM parseBlock $ elContent e)
612+ where innerInlines = (trimInlines . mconcat) <$>
613+ (mapM parseInline $ elContent e)
614+parseInline (CRef _) = return mempty