Class MarkdownDocParserSession

All Implemented Interfaces:
BeanSession, ConverterSession, RecordReadable

Session object for MarkdownDocParser.

Parses Markdown documents (headings + tables) produced by MarkdownDocSerializer into Java objects by mapping heading sections to nested bean properties.

Notes:
  • This class is not thread safe and is typically discarded after one use.
  • Constructor Details

  • Method Details

    • create

      Creates a new builder for this object.
      Parameters:
      ctx - The context creating this session.
      Cannot be null.
      Returns:
      A new builder.
    • doRead

      protected <T> T doRead(ParserPipe pipe, ClassMeta<T> type) throws IOException, ParseException
      Description copied from class: ParserSession
      Workhorse method.

      Subclasses are expected to implement this method or Parser.doRead(ParserSession,ParserPipe,ClassMeta).

      The default implementation of this method simply calls Parser.doRead(ParserSession,ParserPipe,ClassMeta).

      Overrides:
      doRead in class MarkdownParserSession
      Type Parameters:
      T - The class type of the object to create.
      Parameters:
      pipe - Where to get the input from.
      type - The class type of the object to create. If null or Object.class, object type is based on what's being parsed. For example, when parsing JSON text, it may return a String, Number, JsonMap, etc...
      Returns:
      The parsed object.
      Throws:
      IOException - Thrown by underlying stream.
      ParseException - Malformed input encountered.
    • readDocAnything

      protected <T> T readDocAnything(List<String> lines, ClassMeta<T> eType, Object outer, int level) throws IOException, ParseException
      Main document-mode parse dispatch.
      Type Parameters:
      T - The target type.
      Parameters:
      lines - All input lines.
      eType - The expected type.
      outer - The outer object.
      level - The expected heading level for the top-level section.
      Returns:
      The parsed object.
      Throws:
      IOException - Thrown by underlying stream.
      ParseException - If parsing fails.
    • readBeanFromDoc

      protected Object readBeanFromDoc(List<String> lines, ClassMeta<?> sType, Object outer, int level) throws IOException, ParseException
      Parses a bean from Markdown document structure (headings + tables).

      The top-level heading (title) is ignored. Inline key/value tables at the current heading level populate simple properties. Sub-headings at level+1 map to nested bean properties.

      Parameters:
      lines - All document lines.
      sType - The bean type.
      outer - The outer object.
      level - The current heading level.
      Returns:
      The parsed bean.
      Throws:
      ParseException - If parsing fails.
      IOException
    • readMapFromDoc

      protected Object readMapFromDoc(List<String> lines, ClassMeta<?> sType, Object outer, int level) throws IOException, ParseException
      Parses a map from Markdown document structure.
      Parameters:
      lines - All document lines.
      sType - The map type.
      outer - The outer object.
      level - The current heading level.
      Returns:
      The parsed map.
      Throws:
      ParseException - If parsing fails.
      IOException
    • segmentBySections

      protected Map<String,List<String>> segmentBySections(List<String> lines, int sectionLevel)
      Segments document lines into sections by heading level.

      Returns a map where the key is the heading text and the value is the lines in that section. The empty-string key maps to content before the first sub-heading (root content).

      Parameters:
      lines - All document lines.
      sectionLevel - The heading level that defines section boundaries.
      Returns:
      Map of section name → section lines.
    • getHeadingText

      protected String getHeadingText(String line, int level)
      Returns the heading text if the given line is a heading at the specified level, else null.
      Parameters:
      line - The input line.
      level - The heading level to check.
      Returns:
      The heading text or null.
    • isHeadingLine

      protected boolean isHeadingLine(String line, int level)
      Returns whether the given line is a heading at the specified level.
      Parameters:
      line - The input line.
      level - The heading level.
      Returns:
      Whether it is a heading at that level.
    • isBulletLine

      protected boolean isBulletLine(String line)
      Returns whether a line is a bullet list item.
      Parameters:
      line - The input line.
      Returns:
      Whether it is a bullet item.