Top Description Fields Constructors Methods
org.jabref.htmltonode.internal

public final Class HtmlToModel

extends Object
Class Inheritance
Imports
java.util.ArrayList, .List, .Locale, org.jabref.htmltonode.model.Block, .CssLength, .Inline, .InlineStyle, org.jsoup.Jsoup, org.jsoup.nodes.Document, .Element, .Node, .TextNode, org.jspecify.annotations.Nullable

Parses HTML into the block/inline model. Uses jsoup, so malformed markup, entities and <base href> behave like in a browser. Unknown tags degrade gracefully: unknown inline tags are transparent, unknown block tags act like <div>.

Field Summary

Modifier and TypeField and Description
private static final double[]
FONT_SIZE_FACTORS

Legacy <font size="1..7"> factors relative to the base size (size 3 = 1.0)

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static void
addDefinitionList(Element element, InlineStyle inherited, WhiteSpaceMode whiteSpace, BlockCollector out)

private static void
addHeading(Element element, int level, InlineStyle inherited, WhiteSpaceMode whiteSpace, BlockCollector out)

private static void
addList(Element element, boolean ordered, InlineStyle inherited, WhiteSpaceMode whiteSpace, BlockCollector out)

private static void
addParagraphLike(Element element, InlineStyle inherited, WhiteSpaceMode whiteSpace, BlockCollector out, boolean spaced)

<p> and <div>-like elements: a single all-inline child list collapses into one Block.Paragraph; mixed content becomes a Block.Container.

private static void
addPre(Element element, InlineStyle inherited, BlockCollector out)

private static void
addTable(Element element, InlineStyle inherited, WhiteSpaceMode whiteSpace, BlockCollector out)

private static void
addTableRow(Element row, InlineStyle inherited, WhiteSpaceMode whiteSpace, List<Block.TableRow> rows)

private static void
private static InlineStyle
private static CssLength
attributeLength(Element element, String attribute)

private static WhiteSpaceMode
private static InlineStyle
deriveStyle(Element element, InlineStyle inherited)

Tag semantics plus the element's style attribute, resolved onto inherited.

private static List<Inline>
flattenToInlines(List<Block> blocks)

For heading/pre content: nested blocks are squashed into one inline sequence (rare, only from malformed markup), separated by line breaks.

public static List<Block>
parse(String html, @Nullable String baseUri)

private static List<Block>
parseBlocks(Element element, InlineStyle style, WhiteSpaceMode whiteSpace)

private static void
replaceOrRemove(List<Inline> inlines, int index, String newText, InlineStyle style)

private static List<Inline>
trimPreEdges(List<Inline> inlines)

Browsers ignore a single newline directly after <pre> and before </pre>.

private static void
private static void
walkElement(Element element, InlineStyle inherited, WhiteSpaceMode whiteSpace, BlockCollector out)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

FONT_SIZE_FACTORSback to summary
private static final double[] FONT_SIZE_FACTORS

Legacy <font size="1..7"> factors relative to the base size (size 3 = 1.0)

Constructor Detail

HtmlToModelback to summary
private HtmlToModel()

Method Detail

addDefinitionListback to summary
private static void addDefinitionList(Element element, InlineStyle inherited, WhiteSpaceMode whiteSpace, BlockCollector out)
addHeadingback to summary
private static void addHeading(Element element, int level, InlineStyle inherited, WhiteSpaceMode whiteSpace, BlockCollector out)
addListback to summary
private static void addList(Element element, boolean ordered, InlineStyle inherited, WhiteSpaceMode whiteSpace, BlockCollector out)
addParagraphLikeback to summary
private static void addParagraphLike(Element element, InlineStyle inherited, WhiteSpaceMode whiteSpace, BlockCollector out, boolean spaced)

<p> and <div>-like elements: a single all-inline child list collapses into one Block.Paragraph; mixed content becomes a Block.Container.

addPreback to summary
private static void addPre(Element element, InlineStyle inherited, BlockCollector out)
addTableback to summary
private static void addTable(Element element, InlineStyle inherited, WhiteSpaceMode whiteSpace, BlockCollector out)
addTableRowback to summary
private static void addTableRow(Element row, InlineStyle inherited, WhiteSpaceMode whiteSpace, List<Block.TableRow> rows)
appendImageback to summary
private static void appendImage(Element element, BlockCollector out)
applyFontElementback to summary
private static InlineStyle applyFontElement(Element element, InlineStyle style)
attributeLengthback to summary
private static CssLength attributeLength(Element element, String attribute)
childWhiteSpaceback to summary
private static WhiteSpaceMode childWhiteSpace(Element element, WhiteSpaceMode current)
deriveStyleback to summary
private static InlineStyle deriveStyle(Element element, InlineStyle inherited)

Tag semantics plus the element's style attribute, resolved onto inherited.

flattenToInlinesback to summary
private static List<Inline> flattenToInlines(List<Block> blocks)

For heading/pre content: nested blocks are squashed into one inline sequence (rare, only from malformed markup), separated by line breaks.

parseback to summary
public static List<Block> parse(String html, @Nullable String baseUri)
parseBlocksback to summary
private static List<Block> parseBlocks(Element element, InlineStyle style, WhiteSpaceMode whiteSpace)
replaceOrRemoveback to summary
private static void replaceOrRemove(List<Inline> inlines, int index, String newText, InlineStyle style)
trimPreEdgesback to summary
private static List<Inline> trimPreEdges(List<Inline> inlines)

Browsers ignore a single newline directly after <pre> and before </pre>.

walkChildrenback to summary
private static void walkChildren(Element element, InlineStyle style, WhiteSpaceMode whiteSpace, BlockCollector out)
walkElementback to summary
private static void walkElement(Element element, InlineStyle inherited, WhiteSpaceMode whiteSpace, BlockCollector out)