This is an automated email from the ASF dual-hosted git repository. cziegeler pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git
The following commit(s) were added to refs/heads/master by this push: new 5f83bcc3 Fix link handling 5f83bcc3 is described below commit 5f83bcc31cfff4f65fa2386f5364fed6481d46c6 Author: Carsten Ziegeler <cziege...@apache.org> AuthorDate: Tue Dec 12 16:57:26 2023 +0100 Fix link handling --- .../java/org/apache/sling/mdresource/impl/ResourceUtils.java | 12 ++++++++---- .../sling/mdresource/impl/md/links/CustomLinkResolver.java | 8 ++++---- .../mdresource/impl/md/links/CustomLinkResolverFactory.java | 1 - 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/mdresourcedecorator/src/main/java/org/apache/sling/mdresource/impl/ResourceUtils.java b/mdresourcedecorator/src/main/java/org/apache/sling/mdresource/impl/ResourceUtils.java index ce08853f..8ae3b488 100644 --- a/mdresourcedecorator/src/main/java/org/apache/sling/mdresource/impl/ResourceUtils.java +++ b/mdresourcedecorator/src/main/java/org/apache/sling/mdresource/impl/ResourceUtils.java @@ -30,7 +30,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; - import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; import org.apache.sling.api.resource.ValueMap; @@ -41,8 +40,6 @@ import org.apache.sling.mdresource.impl.md.MarkdownProcessor; import org.apache.sling.mdresource.impl.md.ProcessingInstructions; import org.apache.sling.mdresource.impl.md.ProcessingResult; import org.apache.sling.mdresource.impl.md.links.CustomLinkResolverFactory; -import org.slf4j.LoggerFactory; - import com.vladsch.flexmark.html.HtmlRenderer; import com.vladsch.flexmark.util.ast.Node; @@ -121,8 +118,15 @@ public class ResourceUtils { } if ( config.elementsProperty != null ) { final List<Map.Entry<String, String>> elements = new ArrayList<>(); + final List<Node> nodes = new ArrayList<>(); for(final Node node : result.document.getChildren()) { - elements.add(new AbstractMap.SimpleEntry<>(node.getNodeName(), htmlRenderer.render(node))); + nodes.add(node); + node.unlink(); + } + for(final Node node : nodes) { + result.document.appendChild(node); + elements.add(new AbstractMap.SimpleEntry<>(node.getNodeName(), htmlRenderer.render(result.document))); + node.unlink(); } props.put(config.elementsProperty, elements); } diff --git a/mdresourcedecorator/src/main/java/org/apache/sling/mdresource/impl/md/links/CustomLinkResolver.java b/mdresourcedecorator/src/main/java/org/apache/sling/mdresource/impl/md/links/CustomLinkResolver.java index 1d6b6898..2b6c5631 100644 --- a/mdresourcedecorator/src/main/java/org/apache/sling/mdresource/impl/md/links/CustomLinkResolver.java +++ b/mdresourcedecorator/src/main/java/org/apache/sling/mdresource/impl/md/links/CustomLinkResolver.java @@ -19,7 +19,6 @@ package org.apache.sling.mdresource.impl.md.links; import org.apache.sling.api.resource.Resource; -import org.apache.sling.api.resource.ResourceUtil; import org.jetbrains.annotations.NotNull; import com.vladsch.flexmark.html.LinkResolver; @@ -43,9 +42,10 @@ public class CustomLinkResolver implements LinkResolver { if ( link.getLinkType().equals(LinkType.IMAGE) || link.getLinkType().equals(LinkType.LINK) ) { String url = link.getUrl(); if ( url.indexOf(":/") == - 1 && !url.startsWith("/") ) { - // relative - final String path = this.baseResource.getPath().concat("/").concat(url); - link = link.withUrl(this.baseResource.getResourceResolver().map(ResourceUtil.normalize(path))); + // check if link to + if ( url.endsWith(".md") ) { + link = link.withUrl(url.concat(".html")); + } } } diff --git a/mdresourcedecorator/src/main/java/org/apache/sling/mdresource/impl/md/links/CustomLinkResolverFactory.java b/mdresourcedecorator/src/main/java/org/apache/sling/mdresource/impl/md/links/CustomLinkResolverFactory.java index 341b312c..1815689b 100644 --- a/mdresourcedecorator/src/main/java/org/apache/sling/mdresource/impl/md/links/CustomLinkResolverFactory.java +++ b/mdresourcedecorator/src/main/java/org/apache/sling/mdresource/impl/md/links/CustomLinkResolverFactory.java @@ -48,7 +48,6 @@ public class CustomLinkResolverFactory implements LinkResolverFactory { @Override public boolean affectsGlobalScope() { - // TODO true or false? return false; }