git.iko.soy/typeable/pandoc
on master help sign in
HTML reader now recognizes DocBook block and inline tags.

It was always possible to include raw DocBook tags in a markdown document, but now pandoc will be able to distinguish block from inline tags and behave accordingly. Thus, for example, <sidebar> hello </sidebar> will not be wrapped in `<para>` tags.

commit1b81981c5f681d5c3f48c8d54d6f0a64c9e482ca authorJohn MacFarlane <fiddlosopher@gmail.com> dateTue 25 Oct 2011, 12:44 (15 years ago) parentc8bc039
3 files changed+29−10
README+3−4 src/Text/Pandoc/Readers/HTML.hs+24−5 src/Text/Pandoc/Writers/Docbook.hs+2−1
README+3−4
@@ -1514,7 +1514,7 @@ MediaWiki
15141514Textile
15151515 ~ It will be rendered inside `<span class="math">` tags.
15161516
1517−RTF, Docbook, OpenDocument, ODT
1517+RTF, DocBook, OpenDocument, ODT
15181518 ~ It will be rendered, if possible, using unicode characters,
15191519 and will otherwise appear verbatim.
15201520
@@ -1523,7 +1523,7 @@ HTML, Slidy, DZSlides, S5, EPUB
15231523 command-line options selected:
15241524
15251525 1. The default is to render TeX math as far as possible using unicode
1526− characters, as with RTF, Docbook, and OpenDocument output. Formulas
1526+ characters, as with RTF, DocBook, and OpenDocument output. Formulas
15271527 are put inside a `span` with `class="math"`, so that they may be
15281528 styled differently from the surrounding text if needed.
15291529
@@ -1565,7 +1565,7 @@ HTML, Slidy, DZSlides, S5, EPUB
15651565Raw HTML
15661566--------
15671567
1568−Markdown allows you to insert raw HTML anywhere in a document
1568+Markdown allows you to insert raw HTML (or DocBook) anywhere in a document
15691569(except verbatim contexts, where `<`, `>`, and `&` are interpreted
15701570literally).
15711571
@@ -1610,7 +1610,6 @@ markdown with HTML block elements. For example, one can surround
16101610a block of markdown text with `<div>` tags without preventing it
16111611from being interpreted as markdown.
16121612
1613−
16141613Raw TeX
16151614-------
16161615
src/Text/Pandoc/Readers/HTML.hs+24−5
@@ -503,16 +503,35 @@ blockHtmlTags = ["address", "blockquote", "body", "center", "dir", "div",
503503 "dt", "frameset", "li", "tbody", "td", "tfoot",
504504 "th", "thead", "tr", "script", "style"]
505505
506+-- We want to allow raw docbook in markdown documents, so we
507+-- include docbook block tags here too.
508+blockDocBookTags :: [String]
509+blockDocBookTags = ["calloutlist", "bibliolist", "glosslist", "itemizedlist",
510+ "orderedlist", "segmentedlist", "simplelist",
511+ "variablelist", "caution", "important", "note", "tip",
512+ "warning", "address", "literallayout", "programlisting",
513+ "programlistingco", "screen", "screenco", "screenshot",
514+ "synopsis", "example", "informalexample", "figure",
515+ "informalfigure", "table", "informaltable", "para",
516+ "simpara", "formalpara", "equation", "informalequation",
517+ "figure", "screenshot", "mediaobject", "qandaset",
518+ "procedure", "task", "cmdsynopsis", "funcsynopsis",
519+ "classsynopsis", "blockquote", "epigraph", "msgset",
520+ "sidebar"]
521+
522+blockTags :: [String]
523+blockTags = blockHtmlTags ++ blockDocBookTags
524+
506525isInlineTag :: Tag String -> Bool
507−isInlineTag t = tagOpen (`notElem` blockHtmlTags) (const True) t ||
508− tagClose (`notElem` blockHtmlTags) t ||
526+isInlineTag t = tagOpen (`notElem` blockTags) (const True) t ||
527+ tagClose (`notElem` blockTags) t ||
509528 tagComment (const True) t
510529
511530isBlockTag :: Tag String -> Bool
512531isBlockTag t = tagOpen (`elem` blocktags) (const True) t ||
513532 tagClose (`elem` blocktags) t ||
514533 tagComment (const True) t
515− where blocktags = blockHtmlTags ++ eitherBlockOrInline
534+ where blocktags = blockTags ++ eitherBlockOrInline
516535
517536isTextTag :: Tag String -> Bool
518537isTextTag = tagText (const True)
@@ -547,8 +566,8 @@ t `closes` t2 |
547566 t `elem` ["h1","h2","h3","h4","h5","h6","dl","ol","ul","table","div","p"] &&
548567 t2 `elem` ["h1","h2","h3","h4","h5","h6","p" ] = True -- not "div"
549568t1 `closes` t2 |
550− t1 `elem` blockHtmlTags &&
551− t2 `notElem` (blockHtmlTags ++ eitherBlockOrInline) = True
569+ t1 `elem` blockTags &&
570+ t2 `notElem` (blockTags ++ eitherBlockOrInline) = True
552571_ `closes` _ = False
553572
554573--- parsers for use in markdown, textile readers
src/Text/Pandoc/Writers/Docbook.hs+2−1
@@ -255,7 +255,8 @@ inlineToDocbook _ EnDash = text "–"
255255inlineToDocbook _ (Code _ str) =
256256 inTagsSimple "literal" $ text (escapeStringForXML str)
257257inlineToDocbook opts (Math _ str) = inlinesToDocbook opts $ readTeXMath str
258−inlineToDocbook _ (RawInline _ _) = empty
258+inlineToDocbook _ (RawInline f x) | f == "html" || f == "docbook" = text x
259+ | otherwise = empty
259260inlineToDocbook _ LineBreak = inTagsSimple "literallayout" empty
260261inlineToDocbook _ Space = space
261262inlineToDocbook opts (Link txt (src, _)) =