htmlContents = new HashMap<>();
+
+ for (Node nodeIterator = schemaDoc.selectFirst("h2"); nodeIterator != null; nodeIterator = nodeIterator.nextSibling()) {
+ Element element = null;
+ if (nodeIterator instanceof Element) {
+ element = (Element)nodeIterator;
+
+ if (element.tag().equals(Tag.valueOf("h2"))) {
+ prevH2 = element;
+ }
+ }
+ if (prevH2 == null) continue;
+
+ String contentKey = prevH2.text();
+
+ if (!htmlContents.containsKey(contentKey)) {
+ htmlContents.put(contentKey,
+ new HTMLContentEntry(new StringBuilder().append(prevH2.outerHtml()), prevH2.id())
+ );
+ continue;
+ }
+ StringBuilder currentBuilder = htmlContents.get(contentKey).htmlContent();
+
+ currentBuilder.append("\n");
+
+ if (element == null) {
+ if (!nodeIterator.toString().isBlank())
+ currentBuilder.append(nodeIterator.toString());
+ continue;
+ }
+
+ if (element.tag().equals(Tag.valueOf("table"))) {
+ Element tbody = element.selectFirst("tbody");
+ // replace all in tbody with |
+ tbody.select("th").tagName("td");
+ }
+
+ currentBuilder.append(element.outerHtml());
+ }
+
+ Map result = new HashMap<>();
+
+ FlexmarkHtmlConverter converter = this.getHtmlParser();
+
+ for (var entry : htmlContents.entrySet()) {
+ StringBuilder htmlContent = entry.getValue().htmlContent();
+ String h2id = entry.getValue().h2ID();
+
+ URI readMoreLink = URI.create(ContentFetcher.URL_PREFIX).resolve(fileUrl).resolve("#" + h2id);
+ htmlContent.append("Read more");
+
+ String md = converter.convert(htmlContent.toString());
+
+ // Edge case occuring at "bolding" html, don't know why.
+ md = md.replaceAll("````\n", "");
+
+ result.put(entry.getKey(), md);
+ }
+ return result;
+ }
+}
diff --git a/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/lsp/command/CommandRegistry.java b/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/lsp/command/CommandRegistry.java
deleted file mode 100644
index c346febe8e43..000000000000
--- a/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/lsp/command/CommandRegistry.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package ai.vespa.schemals.lsp.command;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Optional;
-
-import org.eclipse.lsp4j.Command;
-import org.eclipse.lsp4j.ExecuteCommandParams;
-
-import ai.vespa.schemals.lsp.command.commandtypes.DocumentOpen;
-import ai.vespa.schemals.lsp.command.commandtypes.DocumentParse;
-import ai.vespa.schemals.lsp.command.commandtypes.CommandList;
-import ai.vespa.schemals.lsp.command.commandtypes.SchemaCommand;
-
-/**
- * SchemaCommand
- */
-public class CommandRegistry {
- public interface GenericCommandType {
- public String title();
- public SchemaCommand construct();
- }
- public enum CommandType implements GenericCommandType {
- DOCUMENT_OPEN {
- public String title() { return "Open document"; }
- public SchemaCommand construct() { return new DocumentOpen(); }
- },
- DOCUMENT_PARSE {
- public String title() { return "Parse document"; }
- public SchemaCommand construct() { return new DocumentParse(); }
- },
- COMMAND_LIST {
- public String title() { return "Command list"; }
- public SchemaCommand construct() { return new CommandList(); }
- }
- }
-
- public static List getSupportedCommandList() {
- return Arrays.stream(CommandType.values()).map(commandType -> commandType.name()).toList();
- }
-
- public static Optional getCommand(ExecuteCommandParams params) {
- try {
- CommandType commandType = CommandType.valueOf(params.getCommand());
- SchemaCommand command = commandType.construct();
-
- if (command.getArity() != -1 && command.getArity() != params.getArguments().size()) return Optional.empty();
- if (!command.setArguments(params.getArguments())) return Optional.empty();
- return Optional.of(command);
- } catch(Exception e) {
- return Optional.empty();
- }
- }
-
- public static Command createLSPCommand(CommandType commandType, List |