On 12/26/22 21:46, Thibaut Cuvelier wrote:
On Tue, 27 Dec 2022 at 03:20, Richard Kimberly Heck <rikih...@gmail.com> wrote:

    On 12/26/22 20:13, Thibaut Cuvelier wrote:
    > Dear list,
    >
    > To solve https://www.lyx.org/trac/ticket/12585, I wrote the
    attached
    > patch. Basically, LyX now considers the order of font tags when
    > closing them, otherwise you get strange results like in the ticket.
    > The bug is quite serious, actually, even though I don't believe
    many
    > users will hit it.

    I struggled with that when writing the original XHTML code. It's
    hard to
    get right. I know it sometimes would fail. Is this same code also
    used
    with XHTML now? Or would it need to be adapted for that case?


I've tested this case and it looks like the XHTML code did the right thing there. It's a part I rewrote for DocBook, introducing a few bugs.Here is the output from XHTML for the same file:

<div class='standard' id='magicparlabel-1'>norm <em>emph <b>emph-bold</b></em><b> bold</b> norm</div>

I don't understand why it is producing the right output while DocBook did not. Maybe the pending tags or the special code for font tags from XMLStream kick in. If that's the case, it's a bit strange that XMLStream deals with this kind of issue (it feels like XMLStream is doing work at multiple levels of abstraction).

I wish I'd commented this code a bit more. I thought I did that pretty well.

Anyway, after digging into it, the magic happens in XMLStream::operator<<(EndTag), though the font part specifically is handled in Paragraph::simpleLyXHTMLOnePar.


    > +    DocBookFontOperation endTransaction() {
    > +        return {.fontsToClose = fontsToClose_, .fontsToOpen =
    > fontsToOpen_};
    > +    }
    > +
    What is ".fontsToClose"? What's the dot doing? Is the "=" right? This
    code just confuses me.


It looks like the name of this C99 feature is "designated initializers": when building a struct instance, you can give the name of the fields you are filling. This is especially useful here to ensure that you are not mixing the open and close sets (they have the same type).

That's a nice feature, but my limited searching only turns up C++20 for this feature. E.g.:

https://pdimov.github.io/blog/2020/09/07/named-parameters-in-c20/

Riki

-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to