src/Pure/Thy/html.scala
changeset 75938 17d51bdabded
parent 75933 c14409948063
child 75939 87f0adcb7e10
equal deleted inserted replaced
75937:02b18f59f903 75938:17d51bdabded
    94   def script_file(path: Path): XML.Elem = script_file(Url.print_file(path.file))
    94   def script_file(path: Path): XML.Elem = script_file(Url.print_file(path.file))
    95 
    95 
    96 
    96 
    97   /* href */
    97   /* href */
    98 
    98 
    99   def relative_href(loc: Path, base: Option[Path] = None, reverse: Boolean = false): String = {
    99   def relative_href(loc: Path, base: Option[Path] = None): String = {
   100     base match {
   100     base match {
   101       case None =>
   101       case None =>
   102         val path = loc.expand
   102         val path = loc.expand
   103         if (path.is_absolute) Exn.error("Relative href expected: " + path)
   103         if (path.is_absolute) Exn.error("Relative href expected: " + path)
   104         else if (path.is_current) "" else path.implode
   104         else if (path.is_current) "" else path.implode
   105       case Some(dir) =>
   105       case Some(dir) =>
   106         val path1 = dir.absolute_file.toPath
   106         val path1 = dir.absolute_file.toPath
   107         val path2 = loc.absolute_file.toPath
   107         val path2 = loc.absolute_file.toPath
   108         try {
   108         try {
   109           val java_path = if (reverse) path2.relativize(path1) else path1.relativize(path2)
   109           val path = File.path(path1.relativize(path2).toFile)
   110           val path = File.path(java_path.toFile)
       
   111           if (path.is_current) "" else path.implode
   110           if (path.is_current) "" else path.implode
   112         }
   111         }
   113         catch {
   112         catch {
   114           case _: IllegalArgumentException =>
   113           case _: IllegalArgumentException =>
   115             Exn.error("Failed to relativize href " + path2 + " with wrt. base " + path1)
   114             Exn.error("Failed to relativize href " + path2 + " with wrt. base " + path1)
   447     css: String = isabelle_css.file_name,
   446     css: String = isabelle_css.file_name,
   448     hidden: Boolean = true,
   447     hidden: Boolean = true,
   449     structural: Boolean = true
   448     structural: Boolean = true
   450   ): Unit = {
   449   ): Unit = {
   451     Isabelle_System.make_directory(dir)
   450     Isabelle_System.make_directory(dir)
   452     val fonts = fonts_css_dir(relative_href(dir, base = base, reverse = true))
   451     val fonts_prefix = relative_href(base getOrElse dir, base = Some(dir))
       
   452     val fonts = fonts_css_dir(fonts_prefix)
   453     File.write(dir + isabelle_css.base, fonts + "\n\n" + File.read(isabelle_css))
   453     File.write(dir + isabelle_css.base, fonts + "\n\n" + File.read(isabelle_css))
   454     File.write(dir + Path.basic(name),
   454     File.write(dir + Path.basic(name),
   455       output_document(head, body, css = css, hidden = hidden, structural = structural))
   455       output_document(head, body, css = css, hidden = hidden, structural = structural))
   456   }
   456   }
   457 }
   457 }