2022-02-17 09:08:01 +00:00
|
|
|
namespace Textile.States;
|
|
|
|
|
|
|
|
[FormatterState(SimpleBlockFormatterState.PatternBegin + @"pad[0-9]+" + SimpleBlockFormatterState.PatternEnd)]
|
|
|
|
public class PaddingFormatterState : SimpleBlockFormatterState
|
2019-08-19 12:35:39 +00:00
|
|
|
{
|
2022-02-17 09:08:01 +00:00
|
|
|
public PaddingFormatterState(TextileFormatter formatter)
|
|
|
|
: base(formatter)
|
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 int HeaderLevel { get; private set; } = 0;
|
2019-08-19 12:35:39 +00:00
|
|
|
|
|
|
|
|
2022-02-17 09:08:01 +00:00
|
|
|
public override void Enter()
|
|
|
|
{
|
|
|
|
for (var i = 0; i < HeaderLevel; i++)
|
2019-08-19 12:35:39 +00:00
|
|
|
{
|
2022-02-17 09:08:01 +00:00
|
|
|
Formatter.Output.Write($"<br {FormattedStylesAndAlignment("br")}/>");
|
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 override void Exit()
|
|
|
|
{
|
|
|
|
}
|
2019-08-19 12:35:39 +00:00
|
|
|
|
2022-02-17 09:08:01 +00:00
|
|
|
protected override void OnContextAcquired()
|
|
|
|
{
|
|
|
|
var m = Regex.Match(Tag, @"^pad(?<lvl>[0-9]+)");
|
|
|
|
HeaderLevel = int.Parse(m.Groups["lvl"].Value);
|
|
|
|
}
|
2019-08-19 12:35:39 +00:00
|
|
|
|
2022-02-17 09:08:01 +00:00
|
|
|
public override void FormatLine(string input)
|
|
|
|
{
|
|
|
|
Formatter.Output.Write(input);
|
|
|
|
}
|
2019-08-19 12:35:39 +00:00
|
|
|
|
2022-02-17 09:08:01 +00:00
|
|
|
public override bool ShouldExit(string intput)
|
|
|
|
{
|
|
|
|
return true;
|
2019-08-19 12:35:39 +00:00
|
|
|
}
|
|
|
|
|
2022-02-17 09:08:01 +00:00
|
|
|
public override bool ShouldNestState(FormatterState other)
|
2019-08-19 12:35:39 +00:00
|
|
|
{
|
2022-02-17 09:08:01 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-08-19 12:35:39 +00:00
|
|
|
|
2022-02-17 09:08:01 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Formatting state for headers and titles.
|
|
|
|
/// </summary>
|
|
|
|
[FormatterState(SimpleBlockFormatterState.PatternBegin + @"h[0-9]+" + SimpleBlockFormatterState.PatternEnd)]
|
|
|
|
public class HeaderFormatterState : SimpleBlockFormatterState
|
|
|
|
{
|
|
|
|
public int HeaderLevel { get; private set; } = 0;
|
2019-08-19 12:35:39 +00:00
|
|
|
|
2022-02-17 09:08:01 +00:00
|
|
|
public HeaderFormatterState(TextileFormatter f)
|
|
|
|
: base(f)
|
|
|
|
{
|
|
|
|
}
|
2019-08-19 12:35:39 +00:00
|
|
|
|
2022-02-17 09:08:01 +00:00
|
|
|
public override void Enter()
|
|
|
|
{
|
|
|
|
Formatter.Output.Write("<h" + HeaderLevel + FormattedStylesAndAlignment("h" + HeaderLevel) + ">");
|
|
|
|
}
|
2019-08-19 12:35:39 +00:00
|
|
|
|
2022-02-17 09:08:01 +00:00
|
|
|
public override void Exit()
|
|
|
|
{
|
|
|
|
Formatter.Output.WriteLine("</h" + HeaderLevel + ">");
|
|
|
|
}
|
2019-08-19 12:35:39 +00:00
|
|
|
|
2022-02-17 09:08:01 +00:00
|
|
|
protected override void OnContextAcquired()
|
|
|
|
{
|
|
|
|
var m = Regex.Match(Tag, @"^h(?<lvl>[0-9]+)");
|
|
|
|
HeaderLevel = int.Parse(m.Groups["lvl"].Value);
|
|
|
|
}
|
2019-08-19 12:35:39 +00:00
|
|
|
|
2022-02-17 09:08:01 +00:00
|
|
|
public override void FormatLine(string input)
|
|
|
|
{
|
|
|
|
Formatter.Output.Write(input);
|
|
|
|
}
|
2019-08-19 12:35:39 +00:00
|
|
|
|
2022-02-17 09:08:01 +00:00
|
|
|
public override bool ShouldExit(string intput)
|
|
|
|
{
|
|
|
|
return true;
|
2019-08-19 12:35:39 +00:00
|
|
|
}
|
2022-02-17 09:08:01 +00:00
|
|
|
|
|
|
|
public override bool ShouldNestState(FormatterState other)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|