All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ends.pamflet-knockoff_2.13.0.12.0.source-code.headers.scala Maven / Gradle / Ivy

The newest version!
package pamflet

import knockoff._

trait IdentifiedHeaders extends Discounter with XHTMLWriter { self: TextWriter =>
  def headerText( spans : collection.Seq[Span] ) : String = {
    val stringWriter = new java.io.StringWriter
    spans.map( self.spanToText(_)(stringWriter) )
    stringWriter.toString
  }
  override def headerToXHTML = (level, spans) => {
    val name = BlockNames.encode(BlockNames.textOf(spans))
    val spanned = spans.map(spanToXHTML)
    val anchored = spanned ++
       
    level match {
      case 1 => 

{ anchored }

case 2 =>

{ anchored }

case 3 =>

{ anchored }

case 4 =>

{ anchored }

case 5 =>
{ anchored }
case 6 =>
{ spanned }
case _ =>
{ spanned }
} } } object BlockNames { /** Do not generate ids for higher levels than this */ val maxLevel = 5 def encode(str: String) = java.net.URLEncoder.encode(str.trim(), "utf-8") def fragment(str: String) = "#" + encode(str) def textOf(spans: collection.Seq[Span]) = spans.flatMap { case t: Text => Seq(t.content) case h: HTMLSpan => Seq(h.html) case _ => Seq() }.mkString("") def name(blocks: collection.Seq[Block]) = blocks.view.collect { case h: Header => textOf(h.spans) }.headOption.getOrElse { "Untitled" } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy