Skip to content

Change list rendering to support nicer output when alignment is :both #42

Open
@a-macnamara

Description

I can include a new line break within a list (so that a given list item looks like it spans multiple paragraphs) like so:

Example

docx.ol do
  li do
    text "This is the first list item."
    br
    br
    text "This is the same first list item, but a new 'paragraph.'"
    br
  end
  li do
    text "This is the second list item."
  end
end

With this code, Caracal creates a document.xml that looks something like (for the first list item):

...
        <w:p w:rsidP="00000000" w:rsidRDefault="00000000" w:rsidR="00000000" w:rsidRPr="00000000" w:rsidDel="00000000">
            <w:pPr>
                <w:numPr>
                    <w:ilvl w:val="0"/>
                    <w:numId w:val="1"/>
                </w:numPr>
                <w:ind w:left="1440" w:hanging="719"/>
                <w:contextualSpacing w:val="1"/>
                <w:rPr>
                    <w:u w:val="none"/>
                </w:rPr>
            </w:pPr>
            <w:r w:rsidR="00000000" w:rsidRPr="00000000" w:rsidDel="00000000">
                <w:rPr>
                    <w:rtl w:val="0"/>
                </w:rPr>
                <w:t xml:space="preserve"/>
            </w:r>
            <w:r w:rsidR="00000000" w:rsidRPr="00000000" w:rsidDel="00000000">
                <w:rPr>
                    <w:rtl w:val="0"/>
                </w:rPr>
                <w:t xml:space="preserve">This is the first list item.</w:t>
            </w:r>
            <w:r>
                <w:br/>
            </w:r>
            <w:r>
                <w:br/>
            </w:r>
            <w:r w:rsidR="00000000" w:rsidRPr="00000000" w:rsidDel="00000000">
                <w:rPr>
                    <w:rtl w:val="0"/>
                </w:rPr>
                <w:t xml:space="preserve">This is the same first list item, but a new 'paragraph.'</w:t>
            </w:r>
            <w:r>
                <w:br/>
            </w:r>
        </w:p>
...

But when my Normal text style includes "align: :both", the text is "Justified" in such a way that Word wraps the last line of each "paragraph" that comprises a list item by padding spaces between the words with an ugly amount of space. See screenshot:

bad-justify

Within Word itself, you can get around this by entering a carriage return at the end of the first list item and removing the blank list that gets created. What Word does in the generated XML is something like (Word 2010 for Windows):

...
        <w:p w:rsidR="00666E17" w:rsidRDefault="00666E17">
            <w:pPr>
                <w:numPr>
                    <w:ilvl w:val="0"/>
                    <w:numId w:val="1"/>
                </w:numPr>
                <w:ind w:hanging="719"/>
                <w:contextualSpacing/>
            </w:pPr>
            <w:r>
                <w:t>This is the first list item.</w:t>
            </w:r>
        </w:p>
        <w:p w:rsidR="00666E17" w:rsidRDefault="00666E17" w:rsidP="00666E17">
            <w:pPr>
                <w:ind w:left="1440"/>
                <w:contextualSpacing/>
            </w:pPr>
            <w:r>
                <w:br/>
            </w:r>
            <w:bookmarkStart w:id="0" w:name="_GoBack"/>
            <w:bookmarkEnd w:id="0"/>
            <w:r>
                <w:t>This is the same first list item, but a new 'paragraph.'</w:t>
            </w:r>
        </w:p>
...

Essentially, Word starts a w:p with the list property for the first paragraph of the first list item, then starts a new w:p with no list property for the second paragraph of the first list item.

Does Caracal currently support something like this? If not, I'm willing to try adding it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions