added regex for parsing conditions and toggles from hrefs
This commit is contained in:
parent
5f995fe06d
commit
e9c7d4c391
|
@ -64,6 +64,19 @@
|
||||||
return story;
|
return story;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ParseHref(string href, out IList<string> conditions, out IList<string> toggles)
|
||||||
|
{
|
||||||
|
var match = RegexLib.Href.Match(href);
|
||||||
|
if (match.Success)
|
||||||
|
{
|
||||||
|
var cstr = match.Groups["conditions"].Value;
|
||||||
|
var tstr = match.Groups["toggles"].Value;
|
||||||
|
}
|
||||||
|
else throw new FormatException(string.Format("Invalid href: {0}", href));
|
||||||
|
conditions = null;
|
||||||
|
toggles = null;
|
||||||
|
}
|
||||||
|
|
||||||
private Scene BlockToScene(Block block)
|
private Scene BlockToScene(Block block)
|
||||||
{
|
{
|
||||||
var scene = new Scene
|
var scene = new Scene
|
||||||
|
@ -75,11 +88,12 @@
|
||||||
if (sceneName.Success)
|
if (sceneName.Success)
|
||||||
{
|
{
|
||||||
scene.Name = sceneName.Groups["text"].Value;
|
scene.Name = sceneName.Groups["text"].Value;
|
||||||
|
IList<string> conditions, toggles;
|
||||||
|
ParseHref(sceneName.Groups["href"].Value, out conditions, out toggles);
|
||||||
|
scene.Conditions = conditions;
|
||||||
|
scene.Toggles = toggles;
|
||||||
}
|
}
|
||||||
else
|
else scene.Name = block.Name;
|
||||||
{
|
|
||||||
scene.Name = block.Name;
|
|
||||||
}
|
|
||||||
|
|
||||||
return scene;
|
return scene;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,12 @@
|
||||||
|
|
||||||
internal static class RegexLib
|
internal static class RegexLib
|
||||||
{
|
{
|
||||||
public static Regex Anchors = new Regex(string.Format(@"(?<anchor>\[(?<text>{0})\]\([ ]*(?<href>{1})[ ]*\))",
|
public static Regex Anchors =
|
||||||
GetNestedBracketsPattern(), GetNestedParensPattern()),
|
new Regex(
|
||||||
RegexOptions.Singleline | RegexOptions.Compiled);
|
string.Format(@"(?<anchor>\[(?<text>{0})\]\([ ]*(?<href>{1})[ ]*\))", GetNestedBracketsPattern(),
|
||||||
|
GetNestedParensPattern()), RegexOptions.Singleline | RegexOptions.Compiled);
|
||||||
|
|
||||||
|
public static Regex Href = new Regex(@"^(\?(?<conditions>[^#]+))?(#(?<toggles>.+))?$", RegexOptions.Compiled);
|
||||||
|
|
||||||
private const int _nestDepth = 6;
|
private const int _nestDepth = 6;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue