jgm/djoths

djot reader bug when Div attributes span over more than one line / hard_line_breaks extension for djot writer

Closed this issue · 4 comments

Please consider this simple document (in Pandoc native format):

Pandoc
  Meta { unMeta = fromList [] }
  [ Div
      ( ""
      , [ "class1" , "class2" , "a-class-with-a-very-long-name" ]
      , [ ( "attribute1" , "value1" )
        , ( "an-attribute-with-a-very-long-name"
          , "an attribute with a very long name may also have a very long value"
          )
        ]
      )
      [ Para [ Str "Some" , Space , Str "text." ] ]
  ]

save it in "example.native" and then run:

pandoc -f native -t djot -o example.djot example.native

this is the content of example.djot:

{.class1 .class2 .a-class-with-a-very-long-name attribute1="value1"
an-attribute-with-a-very-long-name="an attribute with a very long name may also have a very long value"}
:::
Some text.

:::

The attributes of the Div span over two lines, so when you run:

pandoc -f djot -t html example.djot

this is what you get:

<p>{.class1 .class2 .a-class-with-a-very-long-name
attribute1=“value1”</p>
<p>an-attribute-with-a-very-long-name=“an attribute with a very long
name may also have a very long value” ::: Some text.</p>
<div>

</div>

which is clearly wrong.

When you edit example.djot, deleting the line break so that you have all the Div attributes on the same line, as below:

{.class1 .class2 .a-class-with-a-very-long-name attribute1="value1" an-attribute-with-a-very-long-name="an attribute with a very long name may also have a very long value"}
:::
Some text.

:::

You get the right output when you convert to html with pandoc -f djot -t html example.djot:

<div class="class1 class2 a-class-with-a-very-long-name"
data-wrapper="1" data-attribute1="value1"
data-an-attribute-with-a-very-long-name="an attribute with a very long name may also have a very long value">
<p>Some text.</p>
</div>

The bug shows up when the attributes are separated by one or more line break(s) in the djot file.

The djot reader should recognize those attributes spread over more lines.

Another solution could be a hard_line_breaks extension for djot, as there is already for markdown.
I opened a feature request for this.

jgm commented

It's not a bug -- djot.js also behaves this way. It's more of an omission from the documentation here:
https://htmlpreview.github.io/?https://github.com/jgm/djot/blob/master/doc/syntax.html#block-attributes
If you continue a block attribute over multiple lines, subsequent lines must be indented relative to the first line.
This should be in the documentation but it isn't.

jgm commented

Oh, wait, you're right, it's a bug in the writer, which doesn't add this indentation.

jgm commented

Moving to djoths where the action happens.

I'm happy to have contributed. Thank you for your quick reply.