summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2016-06-08 19:10:23 +0000
committerhallgren <hallgren@chalmers.se>2016-06-08 19:10:23 +0000
commita59821eb803886e9b29b9aac43ee9eeacdc02b93 (patch)
tree1fb08eab6268b255bb2f3f181df827f8464318e9 /src
parentc9ea17d2931c63ca06fe6d5e0a0af74c332b6569 (diff)
PGF web service: switch to the new SVG rendering of word dependency trees
Also added the function outputText in CGIUtils.
Diffstat (limited to 'src')
-rw-r--r--src/server/CGIUtils.hs10
-rw-r--r--src/server/PGFService.hs11
2 files changed, 13 insertions, 8 deletions
diff --git a/src/server/CGIUtils.hs b/src/server/CGIUtils.hs
index ba41dc180..2e652b4e6 100644
--- a/src/server/CGIUtils.hs
+++ b/src/server/CGIUtils.hs
@@ -4,7 +4,7 @@ module CGIUtils (throwCGIError, handleCGIErrors,
stderrToFile,logError,
outputJSONP,outputEncodedJSONP,
outputPNG,outputBinary,outputBinary',
- outputHTML,outputPlain) where
+ outputHTML,outputPlain,outputText) where
import Control.Exception(Exception(..),SomeException(..),throw)
import Data.Dynamic(Typeable,cast)
@@ -73,7 +73,7 @@ outputEncodedJSONP json =
Nothing -> ("json",json)
Just c -> ("javascript",c ++ "(" ++ json ++ ")")
ct = "application/"++ty++"; charset=utf-8"
- outputStrict ct $ UTF8.encodeString str
+ outputText ct str
outputPNG :: BS.ByteString -> CGI CGIResult
outputPNG = outputBinary' "image/png"
@@ -88,10 +88,12 @@ outputBinary' ct x = do
outputFPS x
outputHTML :: String -> CGI CGIResult
-outputHTML = outputStrict "text/html; charset=utf-8" . UTF8.encodeString
+outputHTML = outputText "text/html; charset=utf-8"
outputPlain :: String -> CGI CGIResult
-outputPlain = outputStrict "text/plain; charset=utf-8" . UTF8.encodeString
+outputPlain = outputText "text/plain; charset=utf-8"
+
+outputText ct = outputStrict ct . UTF8.encodeString
outputStrict :: String -> String -> CGI CGIResult
outputStrict ct x | x == x = do setHeader "Content-Type" ct
diff --git a/src/server/PGFService.hs b/src/server/PGFService.hs
index 5e673ca75..44f0b7e14 100644
--- a/src/server/PGFService.hs
+++ b/src/server/PGFService.hs
@@ -7,8 +7,9 @@ import PGF (PGF)
import qualified PGF
import PGF.Lexing
import Cache
-import CGIUtils(outputJSONP,outputPlain,outputHTML,logError,outputBinary,
- outputBinary',handleCGIErrors,throwCGIError,stderrToFile)
+import CGIUtils(outputJSONP,outputPlain,outputHTML,outputText,
+ outputBinary,outputBinary',
+ logError,handleCGIErrors,throwCGIError,stderrToFile)
import CGI(CGI,readInput,getInput,getVarWithDefault,
CGIResult,requestAcceptLanguage,handleErrors,setHeader,
Accept(..),Language(..),negotiate,liftIO)
@@ -777,9 +778,11 @@ parseTree pgf lang opts tree = PGF.graphvizParseTree pgf lang opts tree
doDepTree path pgf fmt lang tree =
do lbls <- either (const Nothing) Just # liftIO (tryIOError readDepLabels)
let vis = PGF.graphvizDependencyTree fmt False lbls Nothing pgf lang tree
- if fmt `elem` ["png","gif","svg","gv"]
+ if fmt `elem` ["png","gif","gv"]
then outputGraphviz vis
- else outputPlain vis
+ else if fmt=="svg"
+ then outputText "image/svg+xml" vis
+ else outputPlain vis
where
labelsPath = dropExtension path <.> "labels"
readDepLabels = PGF.getDepLabels . lines # readFile labelsPath