Skip to content

Commit

Permalink
sTeX: added rawfragment backend api
Browse files Browse the repository at this point in the history
  • Loading branch information
Jazzpirate committed Oct 15, 2023
1 parent bb567e2 commit 297b0e1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ trait SHTMLDocumentServer { this : STeXServer =>
case Some("documentTop") =>
ServerResponse(doDocument.toString.trim, "text/html")
case Some("fragment") =>
ServerResponse(doFragment.toString.trim.replace("&","&"), "text/html")
ServerResponse(doFragment(false).toString.trim.replace("&","&"), "text/html")
case Some("rawfragment") =>
ServerResponse(doFragment(true).toString.trim.replace("&", "&"), "text/html")
case Some("declaration") =>
doDeclaration
case Some("loraw") =>
Expand Down Expand Up @@ -485,8 +487,8 @@ trait SHTMLDocumentServer { this : STeXServer =>
}
}

def doFragment(implicit dp:DocParams) = {
val htm = getFragment
def doFragment(raw:Boolean)(implicit dp:DocParams) = {
val htm = getFragment(raw)
val (doc, body) = this.emptydoc
body.plain.attributes((HTMLParser.ns_html, "style")) = "background-color:white"
stripMargins(doc)
Expand Down Expand Up @@ -521,7 +523,7 @@ trait SHTMLDocumentServer { this : STeXServer =>
}
}

def getFragment(implicit dp:DocParams) = {
def getFragment(raw:Boolean)(implicit dp:DocParams) = {
val path = dp.path match {
case Some(mp: MPath) =>
controller.simplifier(mp)
Expand All @@ -535,7 +537,13 @@ trait SHTMLDocumentServer { this : STeXServer =>
case Some(elem) =>
elem match {
case c: Constant =>
present(getFragmentDefault(c))(dp.bindings)
if (raw) {
val r = getFragmentDefault(c)
val state = new ParsingState(this.controller, Nil)
HTMLParser(r)(state)
} else {
present(getFragmentDefault(c))(dp.bindings)
}
case _ =>
throw ErrorResponse("No symbol with path " + path + " found")
}
Expand Down
2 changes: 1 addition & 1 deletion src/mmt-stex/src/info/kwarc/mmt/stex/STeXServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class STeXServer extends ServerExtension("sTeX") with OMDocSHTMLRules with SHTML

override def apply(request: ServerRequest): ServerResponse = try {
request.path.lastOption match {
case Some("document" | "pdf" | "fullhtml" | "documentTop" | "fulldocument" | "fragment" | "symbol" | "declaration" |
case Some("document" | "pdf" | "fullhtml" | "documentTop" | "fulldocument" | "fragment" | "rawfragment" | "symbol" | "declaration" |
"variable" | "css" | "sections" | "definienda" | "lo" | "loraw") =>
documentRequest(request)
case Some("omdoc" | "omdocfrag" | "omdocuri") =>
Expand Down

0 comments on commit 297b0e1

Please sign in to comment.