Skip to content
This repository was archived by the owner on Jun 25, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/Pretzel.Logic/Extensibility/Extensions/WebSequenceDiagrams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ namespace Pretzel.Logic.Extensibility.Extensions
public class WebSequenceDiagrams : IContentTransform
{
static readonly Regex SequenceDiagramRegex = new Regex(@"(?s:<pre><code>@@sequence(?<style>.*?)\r?\n(?<sequenceContent>.*?)</code></pre>)");
const string Style_Template = " wsd_style=\"{0}\"";
const string Div_Template = "<div class=\"wsd\"{1}><pre>{0}</pre></div>";
const string JS_Script = "\r\n<script type=\"text/javascript\" src=\"http://www.websequencediagrams.com/service.js\"></script>";

public string Transform(string content)
{
Expand All @@ -14,16 +17,19 @@ public string Transform(string content)
contentIncludesASequenceDiagram = true;
var sequenceContent = match.Groups["sequenceContent"].Value;
var styleGroup = match.Groups["style"];
string style;
if (styleGroup.Success && string.IsNullOrWhiteSpace(styleGroup.Value))
style = string.Format(" wsd_style=\"{0}\"", styleGroup.Value);
else
style = string.Empty;
return string.Format("<div class=\"wsd\"{1}><pre>{0}</pre></div>", sequenceContent, style);
string style = "default";
if (styleGroup.Success && !string.IsNullOrWhiteSpace(styleGroup.Value))
{
style = styleGroup.Value.Trim();
}

return string.Format(Div_Template, sequenceContent, string.Format(Style_Template, style));
});

if (contentIncludesASequenceDiagram)
content += "\r\n<script type=\"text/javascript\" src=\"http://www.websequencediagrams.com/service.js\"></script>";
{
content += JS_Script;
}

return content;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void Single_block_is_converted_to_diagram()
<p>world</p>";

const string expected = @"<p>hello</p>
<div class=""wsd"" wsd_style=""""><pre>a->b: foo
<div class=""wsd"" wsd_style=""default""><pre>a->b: foo
b->a: bar
</pre></div>
<p>world</p>
Expand All @@ -45,14 +45,35 @@ public void Multiple_blocks_are_converted_to_multiple_diagrams()
<p>woo</p>";

const string expected = @"<p>hello</p>
<div class=""wsd"" wsd_style=""""><pre>a->b: foo
<div class=""wsd"" wsd_style=""default""><pre>a->b: foo
b->a: bar
</pre></div>
<p>world</p>
<div class=""wsd"" wsd_style=""""><pre>c->d: baz
<div class=""wsd"" wsd_style=""default""><pre>c->d: baz
d->c: qak
</pre></div>
<p>woo</p>
<script type=""text/javascript"" src=""http://www.websequencediagrams.com/service.js""></script>";

var markdown = transform.Transform(input);
Assert.Equal(expected.RemoveWhiteSpace(), markdown.RemoveWhiteSpace());
}

[Fact]
public void Single_block_is_converted_to_diagram_style_mscgen()
{
const string input = @"<p>hello</p>
<pre><code>@@sequence mscgen
a->b: foo
b->a: bar
</code></pre>
<p>world</p>";

const string expected = @"<p>hello</p>
<div class=""wsd"" wsd_style=""mscgen""><pre>a->b: foo
b->a: bar
</pre></div>
<p>world</p>
<script type=""text/javascript"" src=""http://www.websequencediagrams.com/service.js""></script>";

var markdown = transform.Transform(input);
Expand Down