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

26 lines
886 B
C#
Raw Normal View History

2022-02-17 09:08:01 +00:00
namespace Textile;
public class StyleReader
2019-08-19 12:35:39 +00:00
{
2022-02-17 09:08:01 +00:00
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();
2019-08-19 12:35:39 +00:00
2022-02-17 09:08:01 +00:00
public StyleReader(string styles)
{
//Read it
var matches = _styleParser.Matches(styles.Replace(System.Environment.NewLine, ""));
foreach (Match match in matches)
2019-08-19 12:35:39 +00:00
{
2022-02-17 09:08:01 +00:00
if (match.Success)
2019-08-19 12:35:39 +00:00
{
2022-02-17 09:08:01 +00:00
_tagStyler.Add(match.Groups["selector"].Value.Trim('{', '}', ' '), _minimizer.Replace(match.Groups["style"].Value.Trim('{', '}', ' '), ";"));
2019-08-19 12:35:39 +00:00
}
}
2022-02-17 09:08:01 +00:00
}
2019-08-19 12:35:39 +00:00
2022-02-17 09:08:01 +00:00
public string GetStyle(string tag)
{
return _tagStyler[tag];
2019-08-19 12:35:39 +00:00
}
}