DocSpace-buildtools/common/ASC.Textile/StyleReader.cs
2020-08-27 17:01:37 +03:00

30 lines
1020 B
C#

using System.Text.RegularExpressions;
namespace Textile
{
public class StyleReader
{
private readonly Regex _styleParser = new Regex(@"(?<selector>[^\{]+)(?<style>[^\}]+)");
private readonly Regex _minimizer = new Regex(@";\s+");
private readonly System.Collections.Specialized.StringDictionary _tagStyler = new System.Collections.Specialized.StringDictionary();
public StyleReader(string styles)
{
//Read it
var matches = _styleParser.Matches(styles.Replace(System.Environment.NewLine, ""));
foreach (Match match in matches)
{
if (match.Success)
{
_tagStyler.Add(match.Groups["selector"].Value.Trim('{', '}', ' '), _minimizer.Replace(match.Groups["style"].Value.Trim('{', '}', ' '), ";"));
}
}
}
public string GetStyle(string tag)
{
return _tagStyler[tag];
}
}
}