laika.parse.rst

ReStructuredText

class ReStructuredText extends ParserFactory

A parser for text written in reStructuredText markup. Instances of this class may be passed directly to the Parse or Transform APIs:

val document = Parse as ReStructuredText fromFile "hello.rst"

Transform from ReStructuredText to HTML fromFile "hello.rst" toFile "hello.html"

reStructuredText has several types of extension points that are fully supported by Laika. In contrast to the original Python implementation, the API has been redesigned to be a more idiomatic, concise and type-safe Scala DSL.

The following extension types are available:

In addition to the standard reStructuredText directives, the API also supports a custom directive type unique to Laika. They represent a library-wide extension mechanism and allow you to implement tags which can be used in any of the supported markup formats or in templates. If you need this level of flexibility, it is recommended to use the Laika directives, if you want to stay compatible with the reStructuredText reference parser, you should pick the standard directives.

Laika directives can be registered with the withLaikaSpanDirective and withLaikaBlockDirective calls respectively. reStructuredText directives can be registered with withSpanDirective and withBlockDirective respectively. The DSLs for creating directives are similar, but still different, due to differences in the feature set of the two variants. The Laika directives try to avoid some of the unnecessary complexities of reStructuredText directives.

Self Type
ReStructuredText
Linear Supertypes
ParserFactory, AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. ReStructuredText
  2. ParserFactory
  3. AnyRef
  4. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  9. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  10. val fileSuffixes: Set[String]

    The file suffixes recognized by this parser.

    The file suffixes recognized by this parser. When transforming entire directories only files with names ending in one of the specified suffixes will be consired.

    It is recommended not to support txt or similarly common suffixes as this might interfere with other installed formats.

    Definition Classes
    ReStructuredTextParserFactory
  11. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  12. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  13. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  14. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  15. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  16. val newParser: (Input) ⇒ Document

    The actual parser function, fully parsing the specified input and returning a document tree.

    The actual parser function, fully parsing the specified input and returning a document tree.

    Definition Classes
    ReStructuredTextParserFactory
  17. final def notify(): Unit

    Definition Classes
    AnyRef
  18. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  19. def strict: ReStructuredText

    Turns strict mode on for the returned parser, switching off any features not part of the reStructuredText specification.

    Turns strict mode on for the returned parser, switching off any features not part of the reStructuredText specification. This includes the Laika variant of directives as well as configuration sections at the start of the document.

  20. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  21. def toString(): String

    Definition Classes
    AnyRef → Any
  22. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  23. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  24. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  25. def withBlockDirectives(directives: Directive[Block]*): ReStructuredText

    Adds the specified directives and returns a new instance of the parser.

    Adds the specified directives and returns a new instance of the parser. These block directives may then be used anywhere in documents parsed by this instance.

    Example:

    case class Note (title: String, content: Seq[Block]) extends Block with BlockContainer[Note]
    
    val rst = ReStructuredText withBlockDirectives (
      BlockDirective("note") {
        (argument() ~ blockContent)(Note)
      }
    )
    
    Transform from rst to HTML fromFile "hello.rst" toFile "hello.html"

    For more details on implementing directives see laika.parse.rst.Directives.

  26. def withDefaultTextRole(role: String): ReStructuredText

    Specifies the name of the default text role to apply when interpreted text is used in markup without an explicit role name.

  27. def withLaikaBlockDirectives(directives: directive.Directives.Blocks.Directive*): ReStructuredText

    Adds the specified Laika directives and returns a new instance of the parser.

    Adds the specified Laika directives and returns a new instance of the parser.

    Example:

    case class Note (title: String, content: Seq[Block], options: Options = NoOpt)
                                                         extends Block with BlockContainer[Note]
    
    val rst = ReStructuredText withLaikaBlockDirectives (
      Blocks.create("note") {
        (attribute(Default) ~ body(Default))(Note(_,_))
      }
    )
    Transform from rst to HTML fromFile "hello.rst" toFile "hello.html"

    For more details on implementing Laika directives see laika.directives.Directives.

  28. def withLaikaSpanDirectives(directives: directive.Directives.Spans.Directive*): ReStructuredText

    Adds the specified Laika directives and returns a new instance of the parser.

    Adds the specified Laika directives and returns a new instance of the parser.

    Example:

    val rst = ReStructuredText withLaikaSpanDirectives (
      Spans.create("ticket") {
        (attribute(Default) ~ attribute("param").optional) { (ticketNo, param) =>
          val base = "http://tickets.service.com/"+ticketNo
          val url = base + (param map (p => "¶m="+p) getOrElse "")
          ExternalLink(Seq(Text("Ticket "+ticketNo)), url, options = Styles("ticket"))
        }
      }
    )
    
    Transform from rst to HTML fromFile "hello.rst" toFile "hello.html"

    For more details on implementing Laika directives see laika.directives.Directives.

  29. def withRawContent: ReStructuredText

    Adds the raw directive and text roles to the parser.

    Adds the raw directive and text roles to the parser. These are disabled by default as they present a potential security risk.

  30. def withSpanDirectives(directives: Directive[Span]*): ReStructuredText

    Adds the specified directives and returns a new instance of the parser.

    Adds the specified directives and returns a new instance of the parser. These span directives can then be referred to by substitution references.

    Example:

    val rst = ReStructuredText withSpanDirectives (
      SpanDirective("replace") {
        spanContent map SpanSequence
      }
    )
    
    Transform from rst to HTML fromFile "hello.rst" toFile "hello.html"

    For more details on implementing directives see laika.parse.rst.Directives.

  31. def withTextRoles(roles: TextRole*): ReStructuredText

    Adds the specified text roles and returns a new instance of the parser.

    Adds the specified text roles and returns a new instance of the parser. These text roles may then be used in interpreted text spans.

    Example:

    val rst = ReStructuredText withTextRoles (
      TextRole("link", "http://www.our-server.com/tickets/")(field("base-url")) {
        (base, text) => Link(List(Text(text)), base + text)
      }
    )
    
    Transform from rst to HTML fromFile "hello.rst" toFile "hello.html"

    For more details on implementing directives see laika.parse.rst.TextRoles.

Inherited from ParserFactory

Inherited from AnyRef

Inherited from Any

Ungrouped