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