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

62 lines
1.5 KiB
C#
Raw Normal View History

2022-02-17 09:08:01 +00:00
namespace Textile.States;
[FormatterState(SimpleBlockFormatterState.PatternBegin + @"bc" + SimpleBlockFormatterState.PatternEnd)]
public class PreCodeFormatterState : SimpleBlockFormatterState
2019-08-19 12:35:39 +00:00
{
2022-02-17 09:08:01 +00:00
public PreCodeFormatterState(TextileFormatter formatter)
: base(formatter)
{
}
public override void Enter()
{
Formatter.Output.Write("<pre><code>");
}
public override void Exit()
{
Formatter.Output.WriteLine("</code></pre>");
}
public override void FormatLine(string input)
{
Formatter.Output.WriteLine(FixEntities(input));
}
public override bool ShouldExit(string input)
{
if (Regex.IsMatch(input, @"^\s*$"))
2022-03-17 15:01:39 +00:00
{
2022-02-17 09:08:01 +00:00
return true;
2022-03-17 15:01:39 +00:00
}
2022-02-17 09:08:01 +00:00
Formatter.Output.WriteLine("<br />");
return false;
}
public override bool ShouldFormatBlocks(string input)
{
return false;
}
public override bool ShouldNestState(FormatterState other)
{
return false;
}
public override bool ShouldParseForNewFormatterState(string input)
{
return false;
}
private string FixEntities(string text)
{
// de-entify any remaining angle brackets or ampersands
text = text.Replace("&", "&amp;");
text = text.Replace(">", "&gt;");
text = text.Replace("<", "&lt;");
//Regex.Replace(text, @"\b&([#a-z0-9]+;)", "x%x%");
return text;
2019-08-19 12:35:39 +00:00
}
}