Skip to content

Commit

Permalink
Merge pull request #19 from jafingerhut/andy-fixes1
Browse files Browse the repository at this point in the history
One potential fix for issue where unquoted labels like "node" and "edge"
  • Loading branch information
daveray committed Dec 17, 2020
2 parents 7addbb9 + b1e5e70 commit 2075708
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions deps.edn
@@ -0,0 +1 @@
{}
16 changes: 8 additions & 8 deletions src/dorothy/core.cljc
Expand Up @@ -476,15 +476,15 @@
(defn ^:private safe-id? [s] (re-find safe-id-pattern s))
(defn ^:private html? [s] (re-find html-pattern s))
(defn ^:private escape-quotes [s] (cs/replace s "\"" "\\\""))
(defn ^:private escape-id [id]
(defn ^:private escape-id [id attr-name?]
(cond
(string? id) (cond
(safe-id? id) id
(and attr-name? (safe-id? id)) id
(html? id) (str \< id \>)
:else (str \" (escape-quotes id) \"))
(number? id) (str id)
(keyword? id) (escape-id (name id))
(gen-id? id) (escape-id ((:id-generator *options*) (id)))
(keyword? id) (escape-id (name id) attr-name?)
(gen-id? id) (escape-id ((:id-generator *options*) (id)) attr-name?)
:else (error "Invalid id: %s - %s" (type id) id)))

(defmulti dot* :type)
Expand All @@ -494,15 +494,15 @@

(defmethod dot* ::node-id [{:keys [id port compass-pt]}]
(str
(escape-id id)
(if port (str ":" (escape-id port)))
(escape-id id true)
(if port (str ":" (escape-id port true)))
(if compass-pt (str ":" (name compass-pt)))))

(defn dot*-attrs [attrs]
(cs/join
\,
(for [[k v] attrs]
(str (escape-id k) \= (escape-id v)))))
(str (escape-id k true) \= (escape-id v false)))))

(defn ^:private dot*-trailing-attrs [attrs]
(if-not (empty? attrs)
Expand Down Expand Up @@ -535,7 +535,7 @@
{:id-generator (id-generator)})]
(str (if strict? "strict ")
(name (:type this)) " "
(if id (str (escape-id id) " "))
(if id (str (escape-id id false) " "))
"{\n" (dot*-statements statements) "} ")))

(defn dot
Expand Down

0 comments on commit 2075708

Please sign in to comment.