Skip to content

Commit

Permalink
🚧 prepare jaws deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudroques committed Dec 15, 2024
1 parent 35c48bf commit 1d6d965
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 18 deletions.
3 changes: 1 addition & 2 deletions src/net/sourceforge/plantuml/BlockUml.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ public BlockUml(List<StringLocated> strings, Defines defines, Map<String, String
final TimLoader timLoader = new TimLoader(definitions.getImportedFiles(), defines, charset, definitions,
this.rawSource.get(0));
this.included.addAll(timLoader.load(this.rawSource));
final Jaws jaws = new Jaws(timLoader.getResultList());
this.data = jaws.getResultList();
this.data = Jaws.expandsJawsForPreprocessor(timLoader.getResultList());
this.debug = timLoader.getDebug();
this.preprocessorError = timLoader.isPreprocessorError();
}
Expand Down
25 changes: 11 additions & 14 deletions src/net/sourceforge/plantuml/jaws/Jaws.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,36 @@ public class Jaws {
public static final char BLOCK_E1_NEWLINE = '\uE100';
public static final char BLOCK_E1_NEWLINE_LEFT_ALIGN = '\uE101';
public static final char BLOCK_E1_NEWLINE_RIGHT_ALIGN = '\uE102';

public static final char BLOCK_E1_REAL_BACKSLASH = '\uE110';
public static final char BLOCK_E1_REAL_TABULATION = '\uE111';

public static final char BLOCK_E1_INVISIBLE_QUOTE = '\uE121';
public static final char BLOCK_E1_START_TEXTBLOCK = '\uE122';
public static final char BLOCK_E1_END_TEXTBLOCK = '\uE123';


private final List<StringLocated> output = new ArrayList<StringLocated>();

public Jaws(List<StringLocated> input) {
public static List<StringLocated> expandsJawsForPreprocessor(List<StringLocated> input) {
final List<StringLocated> output = new ArrayList<StringLocated>();
for (int i = 0; i < input.size(); i++) {
List<StringLocated> splitted = input.get(i).expandsJaws();
List<StringLocated> splitted = input.get(i).expandsJawsForPreprocessor();
StringLocated line = splitted.get(0);
if (splitted.size() == 2) {
line = line.append(splitted.get(1).getString());
final int headerLength = line.length() + 3;
line = line.append(BLOCK_E1_INVISIBLE_QUOTE);
final MultilinesBloc bloc = new MultilinesBloc(headerLength, splitted.get(1).getString());
while (true) {
line = line.append(BLOCK_E1_NEWLINE);
i++;
splitted = input.get(i).expandsJaws();
splitted = input.get(i).expandsJawsForPreprocessor();
bloc.add(splitted.get(0).getString());
if (splitted.size() == 2)
break;
line = line.append(splitted.get(0).getString());
}
line = line.append(splitted.get(0).getString());
line = line.append(bloc.getMerged());
line = line.append(BLOCK_E1_INVISIBLE_QUOTE);
line = line.append(splitted.get(1).getString());
}
output.add(line);
}
}

public List<StringLocated> getResultList() {
return Collections.unmodifiableList(output);
}

Expand Down
76 changes: 76 additions & 0 deletions src/net/sourceforge/plantuml/jaws/MultilinesBloc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2024, Arnaud Roques
*
* Project Info: https://plantuml.com
*
* If you like this project or if you find it useful, you can support us at:
*
* https://plantuml.com/patreon (only 1$ per month!)
* https://plantuml.com/paypal
*
* 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
*
*
*/
package net.sourceforge.plantuml.jaws;

import java.util.ArrayList;
import java.util.List;

public class MultilinesBloc {

private final int initialHeaderLength;
private final List<String> lines = new ArrayList<>();

public MultilinesBloc(int headerLength, String first) {
this.initialHeaderLength = headerLength;
this.lines.add(first);
}

public void add(String part) {
lines.add(part);
}

public String getMerged() {
int minHeader = countSpaceAtStart(lines.get(1));
for (int i = 2; i < lines.size(); i++)
minHeader = Math.min(minHeader, countSpaceAtStart(lines.get(i)));

final StringBuilder sb = new StringBuilder(lines.get(0));
for (int i = 1; i < lines.size(); i++) {
sb.append(Jaws.BLOCK_E1_NEWLINE);
sb.append(lines.get(i).substring(minHeader));
}

return sb.toString();
}

private int countSpaceAtStart(String part) {
int result = 0;
while (result < part.length() && part.charAt(result) == ' ')
result++;
return result;
}

}
4 changes: 3 additions & 1 deletion src/net/sourceforge/plantuml/regex/MyPattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import java.util.Map;
import java.util.regex.Pattern;

import net.sourceforge.plantuml.jaws.Jaws;

class MaxSizeHashMap<K, V> extends LinkedHashMap<K, V> {
private final int maxSize;

Expand Down Expand Up @@ -92,7 +94,7 @@ private static String transform(String p) {
p = p.replace("%pLN", "\\p{L}\\p{N}"); // Unicode Letter, digit
p = p.replace("%s", "\\s\u00A0"); // space
p = p.replace("%q", "'\u2018\u2019"); // quote
p = p.replace("%g", "\"\u201c\u201d"); // double quote
p = p.replace("%g", "\"\u201c\u201d" + Jaws.BLOCK_E1_INVISIBLE_QUOTE); // double quote
return p;
}

Expand Down
2 changes: 1 addition & 1 deletion src/net/sourceforge/plantuml/text/StringLocated.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ final public class StringLocated {
// return result;
//}

public List<StringLocated> expandsJaws() {
public List<StringLocated> expandsJawsForPreprocessor() {
if (JawsFlags.PARSE_NEW_MULTILINE_TRIPLE_EXCLAMATION_MARKS) {
final int x = s.indexOf("!!!");
if (x == -1)
Expand Down

0 comments on commit 1d6d965

Please sign in to comment.