From a8d8bda3ea03b2f4d1cc99c66e8d2defaffc2758 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Sat, 11 Dec 2021 18:54:09 +0530 Subject: Fix HTML string handling in dot output. * dump.scm (replace-substrings): New function. (graph->dot): Fix HTML string handling. --- dump.scm | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'dump.scm') diff --git a/dump.scm b/dump.scm index cf8439b..43f3ea6 100755 --- a/dump.scm +++ b/dump.scm @@ -94,6 +94,15 @@ str substrings)) +(define (replace-substrings str replacement-alist) + "Replace substrings in STR according to REPLACEMENT-ALIST, an +association list mapping substrings to their replacements." + (fold (match-lambda* + (((substring . replacement) str) + (string-replace-substring str substring replacement))) + str + replacement-alist)) + (define (string->identifier prefix str) "Convert STR to a turtle identifier after replacing illegal characters with an underscore and prefixing with gn:PREFIX." @@ -546,15 +555,18 @@ case-insensitive." (else (format #f "~a GiB" (round-quotient bytes (expt 1024 3)))))) -;; This wrapper function is necessary to work around a bug in (ccwl -;; graphviz) whereby backslashes in node labels are escaped and -;; printed as \\. +;; This wrapper function is necessary to work around bugs in (ccwl +;; graphviz) whereby backslashes in node labels are escaped as \\, and +;; HTML strings are escaped incorrectly. (define (graph->dot graph) (put-string (current-output-port) - (string-replace-substring + (replace-substrings (call-with-output-string (cut (@@ (ccwl graphviz) graph->dot) graph <>)) - "\\\\" "\\"))) + '(("\\\\" . "\\") + ("\"<<" . "<<") + (">>\"" . ">>") + ("\\\"" . "\""))))) (define (trigrams str) "Return all trigrams in STR." -- cgit v1.2.3