@Override public boolean isParagraphWrappingDisabled(Paragraph node, ListOptions listOptions, DataHolder options) { assert node.getParent() == this; return listOptions.isInTightListItem(node); }
private void render(final Paragraph node, final NodeFormatterContext context, final MarkdownWriter markdown) { if (node.getParent() instanceof ParagraphContainer) { final boolean startWrappingDisabled = ((ParagraphContainer) node.getParent()).isParagraphStartWrappingDisabled(node); final boolean endWrappingDisabled = ((ParagraphContainer) node.getParent()).isParagraphEndWrappingDisabled(node); if (startWrappingDisabled || endWrappingDisabled) { if (!startWrappingDisabled) markdown.blankLine(); if (!(node.getParent() instanceof ParagraphItemContainer)) { if (!node.isTrailingBlankLine() && (node.getNext() == null || node.getNext() instanceof ListBlock)) { renderTextBlockParagraphLines(node, context, markdown); } else { boolean isItemParagraph = ((ParagraphItemContainer) node.getParent()).isItemParagraph(node); if (isItemParagraph) { ListSpacing itemSpacing = context.getDocument().get(LIST_ITEM_SPACING); renderTextBlockParagraphLines(node, context, markdown); } else if (itemSpacing == ListSpacing.LOOSE) { if (node.getParent().getNextAnyNot(BlankLine.class) == null) { renderTextBlockParagraphLines(node, context, markdown); } else { if (!((ParagraphItemContainer) node.getParent()).isParagraphWrappingDisabled(node, listOptions, context.getOptions())) { renderLooseItemParagraph(node, context, markdown); } else {
BasedSequence blockChars = block.getChars(); BasedSequence contentChars = blockChars.subSequence(pos + blockChars.countChars(BasedSequence.WHITESPACE_CHARS, pos, blockChars.length())); block.unlink(); blockRemoved(block); return; } else { int iMax = block.getLineCount(); int i; for (i = 0; i < iMax; i++) { if (block.getLineChars(i).getEndOffset() > contentChars.getStartOffset()) break; block.unlink(); blockRemoved(block); return; } else if (block.getLineChars(i).getEndOffset() == contentChars.getStartOffset()) { block.setContent(block, i, iMax); } else { lines.addAll(block.getContentLines().subList(i, iMax)); int start = contentChars.getStartOffset() - lines.get(0).getStartOffset(); if (start > 0 && start < lines.get(0).length()) { System.arraycopy(block.getLineIndents(), i, indents, 0, indents.length); block.setContentLines(lines); block.setLineIndents(indents); block.setChars(contentChars);
void render(final Paragraph node, final NodeRendererContext context, final HtmlWriter html) { if (node.getFirstChildAnyNot(NonRenderingInline.class) != null) { if (!(node.getParent() instanceof ParagraphItemContainer) || !((ParagraphItemContainer) node.getParent()).isParagraphWrappingDisabled(node, listOptions, context.getOptions())) { renderLooseParagraph(node, context, html); } else { renderTextBlockParagraphLines(node, context, html, false); //context.getHtmlOptions().wrapTightItemParagraphInSpan); } } }
Node afterParagraph = previous.getNext(); Node paragraphPreviousNonBlank = paragraph.getPreviousAnyNot(BlankLine.class); Node paragraphPrevious = paragraph.getPrevious(); final Node paragraphParent = paragraph.getParent(); paragraph.unlink(); state.blockRemovedWithChildren(paragraph); if (options.doubleBlankLineBreaksList) { final BasedSequence interSpace = paragraphPreviousNonBlank == null ? BasedSequence.NULL : BasedSequenceImpl.of(paragraphPreviousNonBlank.getChars().baseSubSequence(paragraphPreviousNonBlank.getChars().getEndOffset(), paragraph.getChars().getStartOffset()).normalizeEOL()); hadPreviousList = paragraphPreviousNonBlank instanceof DefinitionList && interSpace.countChars('\n') < 2; } else { definitionList.setTight(true); final List<BasedSequence> lines = paragraph.getContentLines(); DefinitionTerm definitionTerm = null; content.add(line, paragraph.getLineIndent(lineIndex++)); parser.getBlock().setContent(content); parser.getBlock().setCharsFromContent();
int separatorLineNumber = -1; BasedSequence separatorLine = null; int blockIndent = block.getLineIndent(0); BasedSequence captionLine = null; BitSet separators = separatorCharacters; for (BasedSequence rowLine : block.getContentLines()) { int rowNumber = tableLines.size(); if (separatorLineNumber == -1 && rowNumber > options.maxHeaderRows) return 0; // too many header rows BasedSequence fullRowLine = block.getLineIndent(rowNumber) <= blockIndent ? rowLine.trimEOL() : rowLine.baseSubSequence(rowLine.getStartOffset() - (block.getLineIndent(rowNumber) - blockIndent), rowLine.getEndOffset() - rowLine.eolLength()); if (separatorLineNumber == -1) { if (rowNumber >= options.minHeaderRows separatorLine = rowLine; } else if (fullRowLine.charAt(0) == ' ' || fullRowLine.charAt(0) == '\t') { block.setHasTableSeparator(true); int rowNumber = tableRows.size(); BasedSequence fullRowLine = block.getLineIndent(rowNumber) <= blockIndent ? rowLine.trimEOL() : rowLine.baseSubSequence(rowLine.getStartOffset() - (block.getLineIndent(rowNumber) - blockIndent), rowLine.getEndOffset() - rowLine.eolLength()); boolean isSeparator = rowNumber == separatorLineNumber; TableRow tableRow = new TableRow(fullRowLine); block.insertBefore(tableBlock); state.blockAdded(tableBlock); return tableBlock.getChars().length();
@Override public int preProcessBlock(Paragraph block, ParserState state) { BasedSequence trySequence = block.getChars(); Matcher matcher = ABBREVIATION_BLOCK.matcher(trySequence); int lastFound = 0; while (matcher.find()) { // abbreviation definition if (matcher.start() != lastFound) break; lastFound = matcher.end(); int openingStart = matcher.start(1); int openingEnd = matcher.end(1); int textEnd = lastFound; BasedSequence openingMarker = trySequence.subSequence(openingStart, openingStart + 2); BasedSequence text = trySequence.subSequence(openingStart + 2, openingEnd - 2).trim(); BasedSequence closingMarker = trySequence.subSequence(openingEnd - 2, openingEnd); AbbreviationBlock abbreviationBlock = new AbbreviationBlock(); abbreviationBlock.setOpeningMarker(openingMarker); abbreviationBlock.setText(text); abbreviationBlock.setClosingMarker(closingMarker); abbreviationBlock.setAbbreviation(trySequence.subSequence(openingEnd, textEnd).trim()); abbreviationBlock.setCharsFromContent(); block.insertBefore(abbreviationBlock); state.blockAdded(abbreviationBlock); abbreviationMap.put(abbreviationMap.normalizeKey(abbreviationBlock.getText()), abbreviationBlock); } return lastFound; }
@Override public boolean isParagraphEndWrappingDisabled(final Paragraph node) { return node == getLastChild() || node.getNext() instanceof GitLabBlockQuote; }
@Override public int preProcessBlock(Paragraph block, ParserState state) { BasedSequence contentChars = block.getChars(); // try parsing the beginning as link reference definitions: int leadingSpaces = contentChars.countLeading(BasedSequence.WHITESPACE_NO_EOL_CHARS); int length = contentChars.length(); while (leadingSpaces <= 3 && length > 3 + leadingSpaces && contentChars.charAt(leadingSpaces) == '[') { if (leadingSpaces > 0) { contentChars = contentChars.subSequence(leadingSpaces, length); length -= leadingSpaces; } int pos = parseReference(block, contentChars); if (pos == 0) break; contentChars = contentChars.subSequence(pos, length); length = contentChars.length(); leadingSpaces = contentChars.countLeading(BasedSequence.WHITESPACE_NO_EOL_CHARS); } return contentChars.getStartOffset() - block.getChars().getStartOffset(); }
public void setContent(Paragraph other, int startLine, int endLine) { super.setContent(other.getContentLines(startLine, endLine)); if (endLine > startLine) { int[] lineIndents = new int[endLine - startLine]; System.arraycopy(other.lineIndents, startLine, lineIndents, 0, endLine - startLine); this.lineIndents = lineIndents; } else { this.lineIndents = EMPTY_INDENTS; } }
try { HWPFDocument document = [...]; // comes from somewhere Range range = document.getRange(); // Background shading of a paragraph ParagraphProperties pprops = new ParagraphProperties(); ShadingDescriptor shd = new ShadingDescriptor(); shd.setCvFore(Colorref.valueOfIco(0x07)); // yellow; ICO shd.setIpat(0x0001); // solid background; IPAT pprops.setShading(shd); Paragraph p1 = range.insertBefore(pprops, StyleSheet.NIL_STYLE); p1.insertBefore("shaded paragraph"); // Highlighting of individual characters Paragraph p2 = range.insertBefore(new ParagraphProperties(), StyleSheet.NIL_STYLE); CharacterRun cr = p2.insertBefore("highlighted text\r"); cr.setHighlighted((byte) 0x06); // red; ICO document.write([...]); // document goes to somewhere } catch (IOException e) { e.printStackTrace(); }
@Override public void parseInlines(InlineParser inlineParser) { inlineParser.parse(getBlock().getContentChars(), getBlock()); }
Node afterParagraph = previous.getNext(); Node paragraphPreviousNonBlank = paragraph.getPreviousAnyNot(BlankLine.class); Node paragraphPrevious = paragraph.getPrevious(); final Node paragraphParent = paragraph.getParent(); paragraph.unlink(); state.blockRemovedWithChildren(paragraph); if (options.doubleBlankLineBreaksList) { final BasedSequence interSpace = paragraphPreviousNonBlank == null ? BasedSequence.NULL : BasedSequenceImpl.of(paragraphPreviousNonBlank.getChars().baseSubSequence(paragraphPreviousNonBlank.getChars().getEndOffset(), paragraph.getChars().getStartOffset()).normalizeEOL()); hadPreviousList = paragraphPreviousNonBlank instanceof DefinitionList && interSpace.countChars('\n') < 2; } else { definitionList.setTight(true); final List<BasedSequence> lines = paragraph.getContentLines(); DefinitionTerm definitionTerm = null; content.add(line, paragraph.getLineIndent(lineIndex++)); parser.getBlock().setContent(content); parser.getBlock().setCharsFromContent();
private void render(final Paragraph node, final DocxRendererContext docx) { if (node.getParent() instanceof EnumeratedReferenceBlock) { // we need to unwrap the paragraphs //final String text = new TextCollectingVisitor().collectAndGetText(node); //if (!text.isEmpty()) { docx.renderChildren(node); //} } else if (!(node.getParent() instanceof ParagraphItemContainer) || !((ParagraphItemContainer) node.getParent()).isItemParagraph(node)) { if (node.getParent() instanceof BlockQuote || node.getParent() instanceof AsideBlock) { // the parent handles our formatting docx.createP(); docx.renderChildren(node); } else { if (node.getFirstChildAnyNot(NonRenderingInline.class) != null) { docx.setBlockFormatProvider(new BlockFormatProviderBase<>(docx, docx.getDocxRendererOptions().LOOSE_PARAGRAPH_STYLE)); docx.createP(); docx.renderChildren(node); } } } else { // the parent handles our formatting if (node.getParent() instanceof FootnoteBlock) { // there is already an open paragraph, re-use it docx.renderChildren(node); } else { docx.createP(); docx.renderChildren(node); } } }
int separatorLineNumber = -1; BasedSequence separatorLine = null; int blockIndent = block.getLineIndent(0); BasedSequence captionLine = null; BitSet separators = separatorCharacters; for (BasedSequence rowLine : block.getContentLines()) { int rowNumber = tableLines.size(); if (separatorLineNumber == -1 && rowNumber > options.maxHeaderRows) return 0; // too many header rows BasedSequence fullRowLine = block.getLineIndent(rowNumber) <= blockIndent ? rowLine.trimEOL() : rowLine.baseSubSequence(rowLine.getStartOffset() - (block.getLineIndent(rowNumber) - blockIndent), rowLine.getEndOffset() - rowLine.eolLength()); if (separatorLineNumber == -1) { if (rowNumber >= options.minHeaderRows separatorLine = rowLine; } else if (fullRowLine.charAt(0) == ' ' || fullRowLine.charAt(0) == '\t') { block.setHasTableSeparator(true); int rowNumber = tableRows.size(); BasedSequence fullRowLine = block.getLineIndent(rowNumber) <= blockIndent ? rowLine.trimEOL() : rowLine.baseSubSequence(rowLine.getStartOffset() - (block.getLineIndent(rowNumber) - blockIndent), rowLine.getEndOffset() - rowLine.eolLength()); boolean isSeparator = rowNumber == separatorLineNumber; TableRow tableRow = new TableRow(fullRowLine); block.insertBefore(tableBlock); state.blockAdded(tableBlock); return tableBlock.getChars().length();
@Override public int preProcessBlock(Paragraph block, ParserState state) { BasedSequence trySequence = block.getChars(); Matcher matcher = ABBREVIATION_BLOCK.matcher(trySequence); int lastFound = 0; while (matcher.find()) { // abbreviation definition if (matcher.start() != lastFound) break; lastFound = matcher.end(); int openingStart = matcher.start(1); int openingEnd = matcher.end(1); int textEnd = lastFound; BasedSequence openingMarker = trySequence.subSequence(openingStart, openingStart + 2); BasedSequence text = trySequence.subSequence(openingStart + 2, openingEnd - 2).trim(); BasedSequence closingMarker = trySequence.subSequence(openingEnd - 2, openingEnd); AbbreviationBlock abbreviationBlock = new AbbreviationBlock(); abbreviationBlock.setOpeningMarker(openingMarker); abbreviationBlock.setText(text); abbreviationBlock.setClosingMarker(closingMarker); abbreviationBlock.setAbbreviation(trySequence.subSequence(openingEnd, textEnd).trim()); abbreviationBlock.setCharsFromContent(); block.insertBefore(abbreviationBlock); state.blockAdded(abbreviationBlock); abbreviationMap.put(abbreviationMap.normalizeKey(abbreviationBlock.getText()), abbreviationBlock); } return lastFound; }
private void renderLooseParagraph(final Paragraph node, final NodeRendererContext context, final HtmlWriter html) { renderTextBlockParagraphLines(node, context, html); if (inBlockQuote > 0 && node.getNext() == null) { html.line(); } else { html.blankLine(); } }
private void renderLooseParagraph(final Paragraph node, final NodeRendererContext context, final HtmlWriter html) { if (context.getHtmlOptions().noPTagsUseBr) { renderTextBlockParagraphLines(node, context, html, false); html.tagVoid("br").tagVoid("br").line(); } else { html.srcPosWithEOL(node.getChars()).withAttr().tagLine("p", new Runnable() { @Override public void run() { renderTextBlockParagraphLines(node, context, html, false); } }); } }
public void setContent(Paragraph other, int startLine, int endLine) { super.setContent(other.getContentLines(startLine, endLine)); if (endLine > startLine) { int[] lineIndents = new int[endLine - startLine]; System.arraycopy(other.lineIndents, startLine, lineIndents, 0, endLine - startLine); this.lineIndents = lineIndents; } else { this.lineIndents = EMPTY_INDENTS; } }
@Override public void parseInlines(InlineParser inlineParser) { inlineParser.parse(getBlock().getContentChars(), getBlock()); }