mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[Markdown][IDEA-349637] Fix image link generating for paths with unicode symbols
GitOrigin-RevId: aa417a91ce2e5afd51e1facf8107dd91fd96c495
This commit is contained in:
committed by
intellij-monorepo-bot
parent
9f3822e4e3
commit
509f56d461
+2
-5
@@ -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)
|
||||
}
|
||||
|
||||
+1
-4
@@ -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\"",
|
||||
|
||||
+3
-1
@@ -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")
|
||||
}
|
||||
|
||||
+3
-1
@@ -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) }
|
||||
)
|
||||
}
|
||||
|
||||
+5
-1
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user