DocSpace-client/common/ASC.Textile/States/TableFormatterState.cs

67 lines
1.8 KiB
C#
Raw Normal View History

2022-02-17 09:08:01 +00:00
namespace Textile.States;
[FormatterState(@"^\s*(?<tag>table)" +
Globals.SpanPattern +
Globals.AlignPattern +
Globals.BlockModifiersPattern +
@"\.\s*$")]
public class TableFormatterState : FormatterState
2019-08-19 12:35:39 +00:00
{
2022-02-17 09:08:01 +00:00
private string _attsInfo;
private string _alignInfo;
2019-08-19 12:35:39 +00:00
2022-02-17 09:08:01 +00:00
public TableFormatterState(TextileFormatter f)
: base(f)
{
}
2019-08-19 12:35:39 +00:00
2022-02-17 09:08:01 +00:00
public override string Consume(string input, Match m)
{
_alignInfo = m.Groups["align"].Value;
_attsInfo = m.Groups["atts"].Value;
2019-08-19 12:35:39 +00:00
2022-02-17 09:08:01 +00:00
//TODO: check the state (it could already be a table!)
this.Formatter.ChangeState(this);
2019-08-19 12:35:39 +00:00
2022-02-17 09:08:01 +00:00
return string.Empty;
}
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("<table" + FormattedStylesAndAlignment() + ">");
}
2019-08-19 12:35:39 +00:00
2022-02-17 09:08:01 +00:00
public override void Exit()
{
Formatter.Output.WriteLine("</table>");
}
2019-08-19 12:35:39 +00:00
2022-02-17 09:08:01 +00:00
public override void FormatLine(string input)
{
if (input.Length > 0)
2022-03-17 15:01:39 +00:00
{
2022-02-17 09:08:01 +00:00
throw new Exception("The TableFormatter state is not supposed to format any lines!");
2022-03-17 15:01: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 override bool ShouldExit(string input)
{
var m = Regex.Match(input,
@"^\s*" + Globals.AlignPattern + Globals.BlockModifiersPattern +
@"(\.\s?)?(?<tag>\|)" +
@"(?<content>.*)(?=\|)"
);
return !m.Success;
}
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);
2020-08-27 14:01:37 +00:00
}
2019-08-19 12:35:39 +00:00
}