1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-06 10:20:54 +00:00
plantuml/src/net/sourceforge/plantuml/creole/command/CommandCreoleLatex.java

81 lines
2.4 KiB
Java
Raw Normal View History

2016-12-14 21:01:03 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2022-03-07 19:33:46 +00:00
* (C) Copyright 2009-2023, Arnaud Roques
2016-12-14 21:01:03 +00:00
*
* Project Info: http://plantuml.com
*
2017-03-15 19:13:31 +00:00
* If you like this project or if you find it useful, you can support us at:
*
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
*
2016-12-14 21:01:03 +00:00
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*
* Original Author: Arnaud Roques
*
*
*/
2020-03-18 10:50:02 +00:00
package net.sourceforge.plantuml.creole.command;
2016-12-14 21:01:03 +00:00
import net.sourceforge.plantuml.command.regex.Matcher2;
import net.sourceforge.plantuml.command.regex.MyPattern;
import net.sourceforge.plantuml.command.regex.Pattern2;
2020-05-17 21:15:50 +00:00
import net.sourceforge.plantuml.creole.legacy.StripeSimple;
2016-12-14 21:01:03 +00:00
import net.sourceforge.plantuml.graphic.Splitter;
import net.sourceforge.plantuml.math.ScientificEquationSafe;
public class CommandCreoleLatex implements Command {
// ::remove file when WASM
2016-12-14 21:01:03 +00:00
2021-11-30 18:33:37 +00:00
@Override
public String startingChars() {
return "<";
}
2021-05-23 15:35:13 +00:00
private static final Pattern2 pattern = MyPattern.cmpile("^(" + Splitter.latexPattern + ")");
2016-12-14 21:01:03 +00:00
2021-05-23 15:35:13 +00:00
private CommandCreoleLatex() {
2016-12-14 21:01:03 +00:00
}
2020-06-07 10:03:18 +00:00
public static Command create() {
2021-05-23 15:35:13 +00:00
return new CommandCreoleLatex();
2016-12-14 21:01:03 +00:00
}
public int matchingSize(String line) {
final Matcher2 m = pattern.matcher(line);
2022-09-23 16:53:33 +00:00
if (m.find() == false)
2016-12-14 21:01:03 +00:00
return 0;
2022-09-23 16:53:33 +00:00
2016-12-14 21:01:03 +00:00
return m.group(1).length();
}
public String executeAndGetRemaining(String line, StripeSimple stripe) {
final Matcher2 m = pattern.matcher(line);
2022-09-23 16:53:33 +00:00
if (m.find() == false)
2016-12-14 21:01:03 +00:00
throw new IllegalStateException();
2022-09-23 16:53:33 +00:00
2016-12-14 21:01:03 +00:00
final String latex = m.group(2);
2020-06-07 10:03:18 +00:00
stripe.addMath(ScientificEquationSafe.fromLatex(latex));
2016-12-14 21:01:03 +00:00
return line.substring(m.group(1).length());
}
}