(bugfix): escape strings for graph export (#207)

strings with quotes used to break the graph export. This change escapes the strings.
This commit is contained in:
Jethro Kuan 2020-03-01 01:08:54 +08:00 committed by GitHub
parent 150ae65564
commit 4da30a7134
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -43,6 +43,7 @@
(require 'cl-lib) (require 'cl-lib)
(require 'org-roam-db) (require 'org-roam-db)
(require 'org-roam-utils) (require 'org-roam-utils)
(require 'xml)
;;; Customizations ;;; Customizations
(defgroup org-roam nil (defgroup org-roam nil
@ -697,22 +698,22 @@ into a digraph."
(insert "digraph {\n") (insert "digraph {\n")
(let ((rows (org-roam-sql [:select [file titles] :from titles]))) (let ((rows (org-roam-sql [:select [file titles] :from titles])))
(dolist (row rows) (dolist (row rows)
(let* ((file (car row)) (let* ((file (xml-escape-string (car row)))
(title (or (caadr row) (title (or (caadr row)
(org-roam--path-to-slug file))) (org-roam--path-to-slug file)))
(shortened-title (s-truncate org-roam-graph-max-title-length title))) (shortened-title (s-truncate org-roam-graph-max-title-length title)))
(insert (insert
(format " \"%s\" [label=\"%s\", shape=%s, URL=\"org-protocol://roam-file?file=%s\", tooltip=\"%s\"];\n" (format " \"%s\" [label=\"%s\", shape=%s, URL=\"org-protocol://roam-file?file=%s\", tooltip=\"%s\"];\n"
file file
shortened-title (xml-escape-string shortened-title)
org-roam-graph-node-shape org-roam-graph-node-shape
file file
title))))) (xml-escape-string title))))))
(let ((link-rows (org-roam-sql [:select :distinct [file-to file-from] :from file-links]))) (let ((link-rows (org-roam-sql [:select :distinct [file-to file-from] :from file-links])))
(dolist (row link-rows) (dolist (row link-rows)
(insert (format " \"%s\" -> \"%s\";\n" (insert (format " \"%s\" -> \"%s\";\n"
(car row) (xml-escape-string (car row))
(cadr row))))) (xml-escape-string (cadr row))))))
(insert "}") (insert "}")
(buffer-string))) (buffer-string)))