jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.68k stars 3.39k forks source link

Have multiline attributes and math attributes in the same file. #8630

Open amine-aboufirass opened 1 year ago

amine-aboufirass commented 1 year ago

It seems that commonmark_x does recognize attributes for both inline and display math. If I have the following in my markdown file:

$$x = 1+2$${ .cs #math:equation caption=test}

$x = 1+2${ .cs #math:equation caption=test}

~~~{
  .cs 
  #lst:my-listing 
  caption=test
  }
def f(x):
    return x
~~~

And I run pandoc --from commonmark_x --to native test.md I will get the following:

[ Para
    [ Span
        ( "math:equation" , [ "cs" ] , [ ( "caption" , "test" ) ] )
        [ Math DisplayMath "x = 1+2" ]
    ]
, Para
    [ Span
        ( "math:equation" , [ "cs" ] , [ ( "caption" , "test" ) ] )
        [ Math InlineMath "x = 1+2" ]
    ]
, CodeBlock
    ( "" , [ "{" ] , [] )
    "  .cs \n  #lst:my-listing \n  caption=test\n  }\ndef f(x):\n    return x"
]

Notice that the multiline attributes for the CodeBlock element are not picked up. If I instead try pandoc --from markdown --to native test.md:

[ Para
    [ Math DisplayMath "x = 1+2"
    , Str "{"
    , Space
    , Str ".cs"
    , Space
    , Str "#math:equation"
    , Space
    , Str "caption=test}"
    ]
, Para
    [ Math InlineMath "x = 1+2"
    , Str "{"
    , Space
    , Str ".cs"
    , Space
    , Str "#math:equation"
    , Space
    , Str "caption=test}"
    ]
, CodeBlock
    ( "lst:my-listing" , [ "cs" ] , [ ( "caption" , "test" ) ] )
    "def f(x):\n    return x"
]

The attributes in the CodeBlock element are picked up, but the attributes for display and inline math are not.

Unfortunately, for my use case I would like to be able to assign multiline attributes to code block elements and assign attributes to display and inline math elements.

Is there a way to achieve both in the same markdown file? Thanks for your consideration.

tarleb commented 1 year ago

This could be considered a duplicate of #7921, unless the different handling of code block attributes by the commonmark and markdown parsers is to be considered an issue.