Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DocBook reader ignores the id attribute of informalequation #8664

Closed
snwnde opened this issue Mar 3, 2023 · 2 comments · Fixed by #10592
Closed

DocBook reader ignores the id attribute of informalequation #8664

snwnde opened this issue Mar 3, 2023 · 2 comments · Fixed by #10592
Labels

Comments

@snwnde
Copy link
Contributor

snwnde commented Mar 3, 2023

Explain the problem.

DocBook reader ignores the id attribute of informalequation. This attribute is useful for crossref, and the equivalent attribute of section is very well preserved. It is thus expected that for informalequation this attribute also passes to AST.

Here is an example DocBook input,

<?xml version="1.0" encoding="UTF-8"?>
<?asciidoc-toc?>
<?asciidoc-numbered?>
<article xmlns="http://docbook.org/ns/docbook" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0" xml:lang="en">
<info>
<title>Example</title>
<date>2023-03-03</date>
</info>
<informalequation xml:id="eq-massenergy">
<alt><![CDATA[E = mc^2]]></alt>
<mathphrase><![CDATA[E = mc^2]]></mathphrase>
</informalequation>
<simpara>Let&#8217;s refer to <link linkend="eq-massenergy">the equation</link>.</simpara>
</article>

and the output AST,

Pandoc
  Meta
    { unMeta =
        fromList
          [ ( "date" , MetaInlines [ Str "2023-03-03" ] )
          , ( "title" , MetaInlines [ Str "Example" ] )
          ]
    }
  [ Para [ Math DisplayMath "E = mc^2" ]
  , Para
      [ Str "Let\8217s"
      , Space
      , Str "refer"
      , Space
      , Str "to"
      , Space
      , Link
          ( "" , [] , [] )
          [ Str "the" , Space , Str "equation" ]
          ( "#eq-massenergy" , "" )
      , Str "."
      ]
  ]

returned by pandoc -s -t native -f docbook example.xml.

Pandoc version?
v3.1 (https://pandoc.org/try/)

@snwnde snwnde added the bug label Mar 3, 2023
@snwnde
Copy link
Contributor Author

snwnde commented Mar 3, 2023

Related to #8666.

@tombolano
Copy link

I am the user that reported #8666, it's an interesting coincidence that I encountered an very similar problem at the same time 😃.

Looking at the DocBook reader code it seems that the id attribute is ignored for some of the block DocBook elements. Other attributes such as role are also ignored as reported in #3657, but the id attribute is essential for cross-references to work so it should not be ignored.

For the case of informalequation, the DocBook reader creates a simple Para element containing the equation. I think that this can be fixed by creating a Div with the correct id value. I tried the following change in the code that seems to fix this:

diff --git a/src/Text/Pandoc/Readers/DocBook.hs b/src/Text/Pandoc/Readers/DocBook.hs
index e11da4253..d5d468f92 100644
--- a/src/Text/Pandoc/Readers/DocBook.hs
+++ b/src/Text/Pandoc/Readers/DocBook.hs
@@ -878,7 +878,8 @@ parseBlock (Elem e) =
         "bibliomisc" -> parseMixed para (elContent e)
         "bibliomixed" -> parseMixed para (elContent e)
         "equation"         -> para <$> equation e displayMath
-        "informalequation" -> para <$> equation e displayMath
+        "informalequation" -> divWith (attrValue "id" e,["informalequation"],[]) .
+                              para <$> equation e displayMath
         "glosssee" -> para . (\ils -> text "See " <> ils <> str ".")
                          <$> getInlines e
         "glossseealso" -> para . (\ils -> text "See also " <> ils <> str ".")

With this change the resulting AST for the DocBook code provided by @snwnde in the first message when executing pandoc -t native -f docbook example.xml (I omit the -s for simplicity) is:

[ Div
    ( "eq-massenergy" , [ "informalequation" ] , [] )
    [ Para [ Math DisplayMath "E = mc^2" ] ]
, Para
    [ Str "Let\8217s"
    , Space
    , Str "refer"
    , Space
    , Str "to"
    , Space
    , Link
        ( "" , [] , [] )
        [ Str "the" , Space , Str "equation" ]
        ( "#eq-massenergy" , "" )
    , Str "."
    ]
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants