diff --git a/plugins/markdown/core/src/org/intellij/plugins/markdown/ui/preview/html/links/InlineLinkGeneratingProvider.kt b/plugins/markdown/core/src/org/intellij/plugins/markdown/ui/preview/html/links/InlineLinkGeneratingProvider.kt index 97fb565f72d9..b34fed988c9c 100644 --- a/plugins/markdown/core/src/org/intellij/plugins/markdown/ui/preview/html/links/InlineLinkGeneratingProvider.kt +++ b/plugins/markdown/core/src/org/intellij/plugins/markdown/ui/preview/html/links/InlineLinkGeneratingProvider.kt @@ -9,13 +9,10 @@ import org.intellij.markdown.parser.LinkMap internal class InlineLinkGeneratingProvider : LinkGeneratingProvider() { override fun getRenderInfo(text: String, node: ASTNode): RenderInfo? { - val label = node.findChildOfType(MarkdownElementTypes.LINK_TEXT) - ?: return null + val label = node.findChildOfType(MarkdownElementTypes.LINK_TEXT) ?: return null return RenderInfo( label, - node.findChildOfType(MarkdownElementTypes.LINK_DESTINATION)?.getTextInNode(text)?.let { - LinkMap.normalizeDestination(it, true) - } ?: "", + node.findChildOfType(MarkdownElementTypes.LINK_DESTINATION)?.getTextInNode(text) ?: "", node.findChildOfType(MarkdownElementTypes.LINK_TITLE)?.getTextInNode(text)?.let { LinkMap.normalizeTitle(it) } diff --git a/plugins/markdown/core/src/org/intellij/plugins/markdown/ui/preview/html/links/IntelliJImageGeneratingProvider.kt b/plugins/markdown/core/src/org/intellij/plugins/markdown/ui/preview/html/links/IntelliJImageGeneratingProvider.kt index 6fad25021801..7521d0333839 100644 --- a/plugins/markdown/core/src/org/intellij/plugins/markdown/ui/preview/html/links/IntelliJImageGeneratingProvider.kt +++ b/plugins/markdown/core/src/org/intellij/plugins/markdown/ui/preview/html/links/IntelliJImageGeneratingProvider.kt @@ -1,8 +1,6 @@ // Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.intellij.plugins.markdown.ui.preview.html.links -import com.intellij.openapi.util.SystemInfo -import com.intellij.openapi.util.text.StringUtil import org.intellij.markdown.MarkdownElementTypes import org.intellij.markdown.ast.ASTNode import org.intellij.markdown.ast.findChildOfType @@ -38,11 +36,10 @@ internal class IntelliJImageGeneratingProvider(linkMap: LinkMap) : LinkGeneratin } override fun renderLink(visitor: HtmlGenerator.HtmlGeneratingVisitor, text: String, node: ASTNode, info: RenderInfo) { - val url = if (SystemInfo.isWindows) StringUtil.replace(info.destination.toString(), "%5C", "/") else info.destination.toString() visitor.consumeTagOpen( node, "img", - "src=\"$url\"", + "src=\"${info.destination}\"", "alt=\"${getPlainTextFrom(info.label, text)}\"", info.title?.let { "title=\"$it\"" }, "$generatedAttributeName=\"true\"", diff --git a/plugins/markdown/core/src/org/intellij/plugins/markdown/ui/preview/html/links/LinkGeneratingProvider.kt b/plugins/markdown/core/src/org/intellij/plugins/markdown/ui/preview/html/links/LinkGeneratingProvider.kt index 8197bde9aa8b..647c963aacb9 100644 --- a/plugins/markdown/core/src/org/intellij/plugins/markdown/ui/preview/html/links/LinkGeneratingProvider.kt +++ b/plugins/markdown/core/src/org/intellij/plugins/markdown/ui/preview/html/links/LinkGeneratingProvider.kt @@ -5,6 +5,7 @@ import org.intellij.markdown.ast.ASTNode import org.intellij.markdown.html.GeneratingProvider import org.intellij.markdown.html.HtmlGenerator import org.intellij.markdown.html.TransparentInlineHolderProvider +import org.intellij.markdown.parser.LinkMap internal abstract class LinkGeneratingProvider: GeneratingProvider { override fun processNode(visitor: HtmlGenerator.HtmlGeneratingVisitor, text: String, node: ASTNode) { @@ -13,7 +14,8 @@ internal abstract class LinkGeneratingProvider: GeneratingProvider { } open fun renderLink(visitor: HtmlGenerator.HtmlGeneratingVisitor, text: String, node: ASTNode, info: RenderInfo) { - visitor.consumeTagOpen(node, "a", "href=\"${info.destination}\"", info.title?.let { "title=\"$it\"" }) + val destination = info.destination.let { LinkMap.normalizeDestination(it, true) } + visitor.consumeTagOpen(node, "a", "href=\"$destination\"", info.title?.let { "title=\"$it\"" }) labelProvider.processNode(visitor, text, info.label) visitor.consumeTagClose("a") } diff --git a/plugins/markdown/core/src/org/intellij/plugins/markdown/ui/preview/html/links/ReferenceLinksGeneratingProvider.kt b/plugins/markdown/core/src/org/intellij/plugins/markdown/ui/preview/html/links/ReferenceLinksGeneratingProvider.kt index 4608cc001818..1e274b74c39d 100644 --- a/plugins/markdown/core/src/org/intellij/plugins/markdown/ui/preview/html/links/ReferenceLinksGeneratingProvider.kt +++ b/plugins/markdown/core/src/org/intellij/plugins/markdown/ui/preview/html/links/ReferenceLinksGeneratingProvider.kt @@ -3,6 +3,7 @@ package org.intellij.plugins.markdown.ui.preview.html.links import org.intellij.markdown.MarkdownElementTypes import org.intellij.markdown.ast.ASTNode +import org.intellij.markdown.ast.findChildOfType import org.intellij.markdown.ast.getTextInNode import org.intellij.markdown.html.entities.EntityConverter import org.intellij.markdown.parser.LinkMap @@ -12,9 +13,10 @@ internal class ReferenceLinksGeneratingProvider(private val linkMap: LinkMap): L val label = node.children.firstOrNull { it.type == MarkdownElementTypes.LINK_LABEL } ?: return null val linkInfo = linkMap.getLinkInfo(label.getTextInNode(text)) ?: return null val linkTextNode = node.children.firstOrNull { it.type == MarkdownElementTypes.LINK_TEXT } + val destination = linkInfo.node.findChildOfType(MarkdownElementTypes.LINK_DESTINATION)?.getTextInNode(text) ?: "" return RenderInfo( linkTextNode ?: label, - EntityConverter.replaceEntities(linkInfo.destination, true, true), + destination, linkInfo.title?.let { EntityConverter.replaceEntities(it, true, true) } ) } diff --git a/plugins/markdown/core/src/org/intellij/plugins/markdown/ui/preview/jcef/impl/IncrementalDOMBuilder.kt b/plugins/markdown/core/src/org/intellij/plugins/markdown/ui/preview/jcef/impl/IncrementalDOMBuilder.kt index fd616beb2060..5933bd254387 100644 --- a/plugins/markdown/core/src/org/intellij/plugins/markdown/ui/preview/jcef/impl/IncrementalDOMBuilder.kt +++ b/plugins/markdown/core/src/org/intellij/plugins/markdown/ui/preview/jcef/impl/IncrementalDOMBuilder.kt @@ -5,6 +5,7 @@ import com.intellij.openapi.diagnostic.thisLogger import com.intellij.openapi.progress.ProgressManager import com.intellij.openapi.util.SystemInfo import com.intellij.openapi.util.io.FileUtil +import com.intellij.openapi.util.text.StringUtil import com.intellij.openapi.vfs.VfsUtilCore import com.intellij.openapi.vfs.VirtualFile import org.intellij.plugins.markdown.ui.preview.PreviewStaticServer @@ -114,12 +115,15 @@ class IncrementalDOMBuilder( private fun actuallyProcessImageNode(node: Node, baseFile: VirtualFile, projectRoot: VirtualFile) { var path = node.attr("src") + if (SystemInfo.isWindows) { + path = StringUtil.replace(path, "\\", "/") + } if (!path.startsWith('/')) { val resolved = baseFile.findFileByRelativePath(path) ?: return path = VfsUtilCore.getRelativePath(resolved, projectRoot) ?: path } if (SystemInfo.isWindows && path.startsWith("/")) { - path = path.trimStart('/', '\\') + path = path.trimStart('/') } val fixedPath = FileUtil.toSystemIndependentName(path) if (fileSchemeResourceProcessor != null) {