src/Pure/Thy/presentation.scala
changeset 75927 040a59abe196
parent 75926 b8ee1ef948c2
child 75928 fa8d9e5ef913
equal deleted inserted replaced
75926:b8ee1ef948c2 75927:040a59abe196
   136         if Path.is_wellformed(file) => Some((file, kind, name))
   136         if Path.is_wellformed(file) => Some((file, kind, name))
   137         case _ => None
   137         case _ => None
   138       }
   138       }
   139   }
   139   }
   140 
   140 
   141   object Entity_Context {
   141   object Node_Context {
   142     val empty: Entity_Context = new Entity_Context
   142     val empty: Node_Context = new Node_Context
   143 
   143 
   144     def make(
   144     def make(
   145       html_context: HTML_Context,
   145       html_context: HTML_Context,
   146       session_name: String,
   146       session_name: String,
   147       theory_name: String,
   147       theory_name: String,
   148       file_name: String
   148       file_name: String
   149     ): Entity_Context =
   149     ): Node_Context =
   150       new Entity_Context {
   150       new Node_Context {
   151         private val session_dir = html_context.session_dir(session_name)
   151         private val session_dir = html_context.session_dir(session_name)
   152         private val file_dir = Path.explode(file_name).dir
   152         private val file_dir = Path.explode(file_name).dir
   153 
   153 
   154         private val seen_ranges: mutable.Set[Symbol.Range] = mutable.Set.empty
   154         private val seen_ranges: mutable.Set[Symbol.Range] = mutable.Set.empty
   155 
   155 
   208           }
   208           }
   209         }
   209         }
   210       }
   210       }
   211   }
   211   }
   212 
   212 
   213   class Entity_Context {
   213   class Node_Context {
   214     def make_def(range: Symbol.Range, body: XML.Body): Option[XML.Elem] = None
   214     def make_def(range: Symbol.Range, body: XML.Body): Option[XML.Elem] = None
   215     def make_ref(props: Properties.T, body: XML.Body): Option[XML.Elem] = None
   215     def make_ref(props: Properties.T, body: XML.Body): Option[XML.Elem] = None
   216   }
   216   }
   217 
   217 
   218 
   218 
   221   private val div_elements =
   221   private val div_elements =
   222     Set(HTML.div.name, HTML.pre.name, HTML.par.name, HTML.list.name, HTML.`enum`.name,
   222     Set(HTML.div.name, HTML.pre.name, HTML.par.name, HTML.list.name, HTML.`enum`.name,
   223       HTML.descr.name)
   223       HTML.descr.name)
   224 
   224 
   225   def make_html(
   225   def make_html(
   226     entity_context: Entity_Context,
   226     node_context: Node_Context,
   227     elements: Elements,
   227     elements: Elements,
   228     xml: XML.Body
   228     xml: XML.Body
   229   ): XML.Body = {
   229   ): XML.Body = {
   230     def html_div(html: XML.Body): Boolean =
   230     def html_div(html: XML.Body): Boolean =
   231       html exists {
   231       html exists {
   249       xml_tree match {
   249       xml_tree match {
   250         case XML.Wrapped_Elem(markup, _, body) => html_body_single(XML.Elem(markup, body), end_offset)
   250         case XML.Wrapped_Elem(markup, _, body) => html_body_single(XML.Elem(markup, body), end_offset)
   251         case XML.Elem(Markup(Markup.ENTITY, props @ Markup.Kind(kind)), body) =>
   251         case XML.Elem(Markup(Markup.ENTITY, props @ Markup.Kind(kind)), body) =>
   252           val (body1, offset) = html_body(body, end_offset)
   252           val (body1, offset) = html_body(body, end_offset)
   253           if (elements.entity(kind)) {
   253           if (elements.entity(kind)) {
   254             entity_context.make_ref(props, body1) match {
   254             node_context.make_ref(props, body1) match {
   255               case Some(link) => (List(link), offset)
   255               case Some(link) => (List(link), offset)
   256               case None => (body1, offset)
   256               case None => (body1, offset)
   257             }
   257             }
   258           }
   258           }
   259           else (body1, offset)
   259           else (body1, offset)
   287             case None => (html_class(name, html), offset)
   287             case None => (html_class(name, html), offset)
   288           }
   288           }
   289         case XML.Text(text) =>
   289         case XML.Text(text) =>
   290           val offset = end_offset - Symbol.length(text)
   290           val offset = end_offset - Symbol.length(text)
   291           val body = HTML.text(Symbol.decode(text))
   291           val body = HTML.text(Symbol.decode(text))
   292           entity_context.make_def(Text.Range(offset, end_offset), body) match {
   292           node_context.make_def(Text.Range(offset, end_offset), body) match {
   293             case Some(body1) => (List(body1), offset)
   293             case Some(body1) => (List(body1), offset)
   294             case None => (body, offset)
   294             case None => (body, offset)
   295           }
   295           }
   296       }
   296       }
   297 
   297 
   319       Resources.html_document(snapshot) getOrElse {
   319       Resources.html_document(snapshot) getOrElse {
   320         val title =
   320         val title =
   321           if (name.is_theory) "Theory " + quote(name.theory_base_name)
   321           if (name.is_theory) "Theory " + quote(name.theory_base_name)
   322           else "File " + Symbol.cartouche_decoded(name.path.file_name)
   322           else "File " + Symbol.cartouche_decoded(name.path.file_name)
   323         val xml = snapshot.xml_markup(elements = html_context.elements.html)
   323         val xml = snapshot.xml_markup(elements = html_context.elements.html)
   324         val body = make_html(Entity_Context.empty, html_context.elements, xml)
   324         val body = make_html(Node_Context.empty, html_context.elements, xml)
   325         html_context.html_document(title, body, fonts_css)
   325         html_context.html_document(title, body, fonts_css)
   326       }
   326       }
   327     }
   327     }
   328   }
   328   }
   329 
   329 
   502 
   502 
   503       val thy_elements = theory.elements(html_context.elements)
   503       val thy_elements = theory.elements(html_context.elements)
   504 
   504 
   505       val thy_html =
   505       val thy_html =
   506         html_context.source(
   506         html_context.source(
   507           make_html(Entity_Context.make(html_context, session_name, theory_name, theory.thy_file),
   507           make_html(Node_Context.make(html_context, session_name, theory_name, theory.thy_file),
   508             thy_elements, snapshot.xml_markup(elements = thy_elements.html)))
   508             thy_elements, snapshot.xml_markup(elements = thy_elements.html)))
   509 
   509 
   510       val blobs_html =
   510       val blobs_html =
   511         for {
   511         for {
   512           (blob, xml) <- snapshot.xml_markup_blobs(elements = thy_elements.html)
   512           (blob, xml) <- snapshot.xml_markup_blobs(elements = thy_elements.html)
   513           if xml.nonEmpty
   513           if xml.nonEmpty
   514         }
   514         }
   515         yield {
   515         yield {
   516           progress.expose_interrupt()
   516           progress.expose_interrupt()
   517           if (verbose) progress.echo("Presenting file " + quote(blob.name.node))
   517           if (verbose) progress.echo("Presenting file " + quote(blob.name.node))
   518           (blob, html_context.source(make_html(Entity_Context.empty, thy_elements, xml)))
   518           (blob, html_context.source(make_html(Node_Context.empty, thy_elements, xml)))
   519         }
   519         }
   520 
   520 
   521       val files =
   521       val files =
   522         for {
   522         for {
   523           (blob, file_html) <- blobs_html
   523           (blob, file_html) <- blobs_html