Skip to content

Conversation

@simsurace
Copy link
Member

No description provided.

@simsurace simsurace requested a review from Krastanov October 30, 2025 16:32
Comment on lines +17 to +58
# escaping unescaped quotation marks
# i.e. replacing `"`` with `\"` while leaving `\"` as is
escape_quotes(s::AbstractString) = replace(s, r"([^\\])\"" => s"\1\\\\\"")

# According to the DOT language specification https://graphviz.org/doc/info/lang.html
# we can quote everyhthing that's not an XML/HTML literal
function quote_prop(p::AbstractString)
if occursin(r"<+.*>+$", p)
# The label is an HTML string, no additional quotes here.
return p
else
return "\"" * escape_quotes(p) * "\""
end
end
# if the property value is _not_ a string it cannot be XML/HTML literal, so just put it in quotes
quote_prop(p::Any) = "\"" * escape_quotes(string(p)) * "\""
# NOTE: down there I only quote property _values_. DOT allows quoting property _names_ too
# I don't do that as long as names are Symbols and can't have spaces and commas and stuff.
# That will break if someone uses a DOT keyword as a property name, as they must be quoted.

function MetaGraphs.savedot(io::IO, g::AbstractMetaGraph)
if is_directed(g)
write(io, "digraph G {\n")
dash = "->"
else
write(io, "graph G {\n")
dash = "--"
end

for p in props(g)
write(io, "$(p[1])=$(quote_prop(p[2]));\n")
end

for v in vertices(g)
write(io, "$v")
if length(props(g, v)) > 0
write(io, " [ ")

for p in props(g, v)
write(io, "$(p[1])=$(quote_prop(p[2])), ")
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these functions in any way connected to the JLD2 backend?
I think these should stay in the main package.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, they don't look like they are

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants