DocSpace-buildtools/common/ASC.Textile/States/TableRowFormatterState.cs

72 lines
1.9 KiB
C#
Raw Normal View History

2022-02-17 09:08:01 +00:00
namespace Textile.States;
[FormatterState(@"^\s*(" + Globals.AlignPattern + Globals.BlockModifiersPattern + @"\.\s?)?" +
@"\|(?<content>.*)\|\s*$")]
public class TableRowFormatterState : FormatterState
2019-08-19 12:35:39 +00:00
{
2022-02-17 09:08:01 +00:00
private string _attsInfo;
private string _alignInfo;
public TableRowFormatterState(TextileFormatter f)
: base(f)
{
}
public override string Consume(string input, Match m)
2019-08-19 12:35:39 +00:00
{
2022-02-17 09:08:01 +00:00
_alignInfo = m.Groups["align"].Value;
_attsInfo = m.Groups["atts"].Value;
input = "|" + m.Groups["content"].Value + "|";
2019-08-19 12:35:39 +00:00
2022-02-17 09:08:01 +00:00
if (!(this.Formatter.CurrentState is TableFormatterState))
2019-08-19 12:35:39 +00:00
{
2022-02-17 09:08:01 +00:00
var s = new TableFormatterState(this.Formatter);
this.Formatter.ChangeState(s);
2019-08-19 12:35:39 +00:00
}
2022-02-17 09:08:01 +00:00
this.Formatter.ChangeState(this);
2019-08-19 12:35:39 +00:00
2022-02-17 09:08:01 +00:00
return input;
}
2019-08-19 12:35:39 +00:00
2022-02-17 09:08:01 +00:00
public override bool ShouldNestState(FormatterState other)
{
return false;
}
2019-08-19 12:35:39 +00:00
2022-02-17 09:08:01 +00:00
public override void Enter()
{
Formatter.Output.WriteLine("<tr" + FormattedStylesAndAlignment() + ">");
}
2019-08-19 12:35:39 +00:00
2022-02-17 09:08:01 +00:00
public override void Exit()
{
Formatter.Output.WriteLine("</tr>");
}
2019-08-19 12:35:39 +00:00
2022-02-17 09:08:01 +00:00
public override void FormatLine(string input)
{
// can get: Align & Classes
2019-08-19 12:35:39 +00:00
2022-02-17 09:08:01 +00:00
var sb = new StringBuilder();
var cellsInput = input.Split('|');
for (var i = 1; i < cellsInput.Length - 1; i++)
2019-08-19 12:35:39 +00:00
{
2022-02-17 09:08:01 +00:00
var cellInput = cellsInput[i];
var tcp = new TableCellParser(cellInput);
sb.Append(tcp.GetLineFragmentFormatting());
2019-08-19 12:35:39 +00:00
}
2022-02-17 09:08:01 +00:00
Formatter.Output.WriteLine(sb.ToString());
}
2019-08-19 12:35:39 +00:00
2022-02-17 09:08:01 +00:00
public override bool ShouldExit(string input)
{
return true;
}
2019-08-19 12:35:39 +00:00
2022-02-17 09:08:01 +00:00
protected string FormattedStylesAndAlignment()
{
return Blocks.BlockAttributesParser.ParseBlockAttributes(_alignInfo + _attsInfo);
2019-08-19 12:35:39 +00:00
}
2022-02-17 09:08:01 +00:00
}