Skip to content

Commit

Permalink
Escape newlines in graphviz output (#7)
Browse files Browse the repository at this point in the history
* Escape newlines when outputting labels

* Close br tag

* Align text to the left when separated by br

* Fix quotes
  • Loading branch information
saulshanabrook authored Nov 9, 2023
1 parent e682702 commit 6f16222
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ const INITIAL_COLOR: usize = 2;
/// Returns an html label for the node with the function name and ports for each argumetn
fn html_label(label: &str, n_args: usize) -> String {
format!(
"<<TABLE BGCOLOR=\"white\" CELLBORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\" style=\"rounded\"><tr><td CELLPADDING=\"4\" WIDTH=\"30\" HEIGHT=\"30\"{}>{}</td></tr>{}</TABLE>>",
"<<TABLE BGCOLOR=\"white\" CELLBORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\" style=\"rounded\"><tr><td BALIGN=\"left\" CELLPADDING=\"4\" WIDTH=\"30\" HEIGHT=\"30\"{}>{}</td></tr>{}</TABLE>>",
(if n_args == 0 {"".to_string()} else {format!(" colspan=\"{}\"", n_args)}),
Escape(label),
(if n_args == 0 {
Expand All @@ -172,6 +172,7 @@ fn quote(s: &str) -> String {
}

// Copied from https://doc.rust-lang.org/stable/nightly-rustc/src/rustdoc/html/escape.rs.html#10
// but added conversion of \n to <br/>

/// Wrapper struct which will emit the HTML-escaped version of the contained
/// string when passed to a format string.
Expand All @@ -191,6 +192,7 @@ impl<'a> fmt::Display for Escape<'a> {
'&' => "&amp;",
'\'' => "&#39;",
'"' => "&quot;",
'\n' => "<br/>",
_ => continue,
};
fmt.write_str(&pile_o_bits[last..i])?;
Expand Down

0 comments on commit 6f16222

Please sign in to comment.