Skip to content

Commit ab89e0c

Browse files
committed
escape strings to satisfy Dot syntax rules
GraphViz's "dot" language has several options for encoding IDs, as described here: https://www.graphviz.org/doc/info/lang.html Alga makes use of the quoted-string syntax. This permits any character within double quotes, except the double-quote character itself, which must be prefixed by a backslash character. (the backslash itself does not need to be escaped). Implement the escaping of " for defaultStyleViaShow.
1 parent f84dc4b commit ab89e0c

File tree

1 file changed

+3
-1
lines changed
  • src/Algebra/Graph/Export

1 file changed

+3
-1
lines changed

src/Algebra/Graph/Export/Dot.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ defaultStyle v = Style mempty mempty [] [] [] v (\_ -> []) (\_ _ -> [])
7272
-- defaultStyleViaShow = 'defaultStyle' ('fromString' . 'show')
7373
-- @
7474
defaultStyleViaShow :: (Show a, IsString s, Monoid s) => Style a s
75-
defaultStyleViaShow = defaultStyle (fromString . show)
75+
defaultStyleViaShow = defaultStyle (fromString . escape . show) where
76+
escape [] = []
77+
escape (x:xs) = if x == '"' then '\\':'"':(escape xs) else x:(escape xs)
7678

7779
-- | Export a graph with a given style.
7880
--

0 commit comments

Comments
 (0)