Search in sources :

Example 11 with NumberingDefinitionsPart

use of org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart in project flexmark-java by vsch.

the class CoreNodeDocxRenderer method renderListItem.

private void renderListItem(final ListItem node, final DocxRendererContext docx) {
    final int nesting = node.countDirectAncestorsOfType(ListItem.class, BulletList.class, OrderedList.class);
    final DocxRendererOptions options = docx.getDocxRendererOptions();
    final String listTextStyle = listOptions.isTightListItem(node) ? options.TIGHT_PARAGRAPH_STYLE : options.LOOSE_PARAGRAPH_STYLE;
    final boolean inBlockQuote = node.getAncestorOfType(BlockQuote.class) != null;
    final boolean wantNumbered = node instanceof OrderedListItem;
    // + (inBlockQuote ? 2 : 0);
    long numId = (wantNumbered ? 3 : 2);
    int newNum = 1;
    final int listLevel = nesting - 1;
    final NumberingDefinitionsPart ndp = docx.getDocxDocument().getNumberingDefinitionsPart();
    if (node.getParent() instanceof OrderedList) {
        if (node == node.getParent().getFirstChild()) {
            newNum = listOptions.isOrderedListManualStart() ? ((OrderedList) node.getParent()).getStartNumber() : 1;
            numId = ndp.restart(numId, listLevel, newNum);
            ensureNumberedListLength(listLevel);
            numberedLists[listLevel] = numId;
        } else {
            numId = numberedLists[listLevel];
        }
    } else if (node.getParent() instanceof BulletList) {
        if (node == node.getParent().getFirstChild()) {
            newNum = 1;
            numId = ndp.restart(numId, listLevel, newNum);
            ensureBulletListLength(listLevel);
            bulletLists[listLevel] = numId;
        } else {
            numId = bulletLists[listLevel];
        }
    }
    final long idNum = numId;
    docx.setBlockFormatProvider(new ListItemBlockFormatProvider<Node>(docx, listTextStyle, idNum, listLevel, ListItem.class, ListBlock.class));
    docx.renderChildren(node);
}
Also used : NumberingDefinitionsPart(org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart) AttributesNode(com.vladsch.flexmark.ext.attributes.AttributesNode)

Aggregations

NumberingDefinitionsPart (org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart)11 XHTMLImporterImpl (org.docx4j.convert.in.xhtml.XHTMLImporterImpl)4 WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)4 File (java.io.File)3 OutputStream (java.io.OutputStream)2 BigInteger (java.math.BigInteger)2 AbstractHtmlExporter (org.docx4j.convert.out.html.AbstractHtmlExporter)2 HtmlSettings (org.docx4j.convert.out.html.AbstractHtmlExporter.HtmlSettings)2 HtmlExporterNG2 (org.docx4j.convert.out.html.HtmlExporterNG2)2 AttributesNode (com.vladsch.flexmark.ext.attributes.AttributesNode)1 URL (java.net.URL)1 Docx4JException (org.docx4j.openpackaging.exceptions.Docx4JException)1 PPrBase (org.docx4j.wml.PPrBase)1 RFonts (org.docx4j.wml.RFonts)1