Skip to content

Commit

Permalink
Format the NewLineCommand (ForNeVeR#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed Jan 6, 2020
1 parent 3940d1c commit 4f3b440
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/WpfMath/Parsers/StandardCommands.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using WpfMath.Atoms;
using WpfMath.Parsers.Matrices;

namespace WpfMath.Parsers
{
internal static class StandardCommands
Expand Down Expand Up @@ -51,44 +52,40 @@ public CommandProcessingResult ProcessCommand(CommandContext context)

private class NewLineCommand : ICommandParser
{

public CommandProcessingResult ProcessCommand(CommandContext context)
{
var source = context.CommandSource;
var position = context.ArgumentsStartPosition;


var prevFormulaAtom = context.Formula.RootAtom;

var upRow = new List<Atom>();
upRow.Add(prevFormulaAtom);
var rows = new List<List<Atom>> {upRow};
var topRow = new List<Atom>();
topRow.Add(prevFormulaAtom);
var rows = new List<List<Atom>> {topRow};

var inside = context.Parser.Parse(
var newContent = context.Parser.Parse(
TexFormulaParser.ReadElement(source, ref position),
context.Formula.TextStyle,
context.Environment);
var downRow = new List<Atom>();
downRow.Add(inside.RootAtom);
rows.Add(downRow);

var bottomRow = new List<Atom>();
bottomRow.Add(newContent.RootAtom);
rows.Add(bottomRow);

var start = context.CommandNameStartPosition;
var atomSource = source.Segment(start, position - start);
var atom = new MatrixAtom(atomSource, rows, MatrixCellAlignment.Center);
return new CommandProcessingResult(atom, position, AtomAppendMode.Replace);
}

}

public static IReadOnlyDictionary<string, ICommandParser> Dictionary = new Dictionary<string, ICommandParser>
{
[@"\"] = new NewLineCommand(),
["binom"] = new BinomCommand(),
["cases"] = new MatrixCommandParser("lbrace", null, MatrixCellAlignment.Left),
["matrix"] = new MatrixCommandParser(null, null, MatrixCellAlignment.Center),
["pmatrix"] = new MatrixCommandParser("lbrack", "rbrack", MatrixCellAlignment.Center),
["underline"] = new UnderlineCommand(),
["binom"] = new BinomCommand(),
[@"\"] = new NewLineCommand()
["underline"] = new UnderlineCommand()
};
}
}

0 comments on commit 4f3b440

Please sign in to comment.