DocSpace-client/common/ASC.Textile/StyleReader.cs

30 lines
1020 B
C#
Raw Normal View History

2019-08-19 12:35:39 +00:00
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)
{
2020-08-27 14:01:37 +00:00
_tagStyler.Add(match.Groups["selector"].Value.Trim('{', '}', ' '), _minimizer.Replace(match.Groups["style"].Value.Trim('{', '}', ' '), ";"));
2019-08-19 12:35:39 +00:00
}
}
}
public string GetStyle(string tag)
{
return _tagStyler[tag];
}
}
}