mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[Markdown][IDEA-283825] Add code style option for disabling text wrapping inside block quotes
GitOrigin-RevId: 9e878fdd643931c7d4368e07470a8a6bbac0d7b2
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f5c3f6a142
commit
081c50a5d8
@@ -75,6 +75,7 @@ markdown.style.settings.spacing.after.list.marker=After list marker
|
||||
markdown.style.settings.spacing.after.blockquote.marker=After blockquote marker
|
||||
|
||||
markdown.style.settings.text.wrapping=Wrap text if long
|
||||
markdown.style.settings.text.wrapping.inside.blockquotes=Wrap text inside block quotes
|
||||
markdown.style.settings.group.when.reformatting=When reformatting
|
||||
markdown.style.settings.line.breaks.inside.text.blocks=Keep line breaks inside text blocks
|
||||
markdown.style.settings.insert.quote.arrows=Insert block quote arrows
|
||||
|
||||
-2
@@ -6,7 +6,6 @@ import com.intellij.psi.PsiDocumentManager
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings
|
||||
import com.intellij.psi.impl.DebugUtil
|
||||
import com.intellij.psi.impl.source.codeStyle.PostFormatProcessor
|
||||
import com.intellij.psi.util.siblings
|
||||
import org.intellij.plugins.markdown.lang.MarkdownLanguage
|
||||
@@ -56,7 +55,6 @@ internal class BlockquotePostFormatProcessor: PostFormatProcessor {
|
||||
|
||||
private fun processParagraph(paragraph: MarkdownParagraphImpl, level: Int) {
|
||||
val firstChild = paragraph.firstChild ?: return
|
||||
println(DebugUtil.psiToString(paragraph, true, true))
|
||||
val elements = firstChild.siblings(forward = true, withSelf = true).filter(this::shouldProcessTextElement)
|
||||
for (element in elements) {
|
||||
repeat(level) {
|
||||
|
||||
+31
-5
@@ -10,6 +10,9 @@ import org.intellij.plugins.markdown.lang.MarkdownTokenTypeSets
|
||||
import org.intellij.plugins.markdown.lang.MarkdownTokenTypes
|
||||
import org.intellij.plugins.markdown.lang.formatter.blocks.special.MarkdownRangedFormattingBlock
|
||||
import org.intellij.plugins.markdown.lang.formatter.blocks.special.MarkdownWrappingFormattingBlock
|
||||
import org.intellij.plugins.markdown.lang.formatter.settings.MarkdownCustomCodeStyleSettings
|
||||
import org.intellij.plugins.markdown.util.hasType
|
||||
import org.intellij.plugins.markdown.util.parents
|
||||
|
||||
internal object MarkdownBlocks {
|
||||
/**
|
||||
@@ -18,7 +21,11 @@ internal object MarkdownBlocks {
|
||||
* Would ignore real whitespace blocks (blocks which has type whitespace
|
||||
* and text of which is really blank)
|
||||
*/
|
||||
fun create(nodes: Sequence<ASTNode>, settings: CodeStyleSettings, spacing: SpacingBuilder, align: (ASTNode) -> Alignment?
|
||||
fun create(
|
||||
nodes: Sequence<ASTNode>,
|
||||
settings: CodeStyleSettings,
|
||||
spacing: SpacingBuilder,
|
||||
align: (ASTNode) -> Alignment?
|
||||
): Sequence<MarkdownFormattingBlock> {
|
||||
return filterFromWhitespaces(nodes).map { create(it, settings, spacing, align) }
|
||||
}
|
||||
@@ -32,17 +39,36 @@ internal object MarkdownBlocks {
|
||||
in MarkdownTokenTypeSets.LIST_MARKERS, in MarkdownTokenTypeSets.WHITE_SPACES, MarkdownTokenTypes.BLOCK_QUOTE -> {
|
||||
MarkdownRangedFormattingBlock.trimmed(node, settings, spacing, align(node), null)
|
||||
}
|
||||
MarkdownElementTypes.PARAGRAPH, MarkdownElementTypes.EMPH, MarkdownElementTypes.STRONG, MarkdownElementTypes.STRIKETHROUGH -> {
|
||||
MarkdownWrappingFormattingBlock(settings, spacing, node, align(node))
|
||||
in elementsToWrap -> {
|
||||
when {
|
||||
isInsideBlockquote(node) && !shouldWrapInsideBlockquote(settings) -> MarkdownFormattingBlock(node, settings, spacing, align(node))
|
||||
else -> MarkdownWrappingFormattingBlock(settings, spacing, node, align(node))
|
||||
}
|
||||
}
|
||||
else -> MarkdownFormattingBlock(node, settings, spacing, align(node))
|
||||
}
|
||||
}
|
||||
|
||||
private fun isInsideBlockquote(node: ASTNode): Boolean {
|
||||
return node.parents().any { it.hasType(MarkdownTokenTypeSets.BLOCK_QUOTE) }
|
||||
}
|
||||
|
||||
private fun shouldWrapInsideBlockquote(settings: CodeStyleSettings): Boolean {
|
||||
val customSettings = settings.getCustomSettings(MarkdownCustomCodeStyleSettings::class.java)
|
||||
return customSettings.WRAP_TEXT_IF_LONG && customSettings.WRAP_TEXT_INSIDE_BLOCKQUOTES
|
||||
}
|
||||
|
||||
/** Filter out real whitespace blocks from sequence */
|
||||
fun filterFromWhitespaces(sequence: Sequence<ASTNode>) = sequence.filter {
|
||||
it.elementType !in MarkdownTokenTypeSets.WHITE_SPACES
|
||||
//Dirty hack cause for some reason Markdown parser think that `>`, `:` are whitespaces
|
||||
// Dirty hack cause for some reason Markdown parser thinks that `>`, `:` are whitespaces
|
||||
|| (it.elementType in MarkdownTokenTypeSets.WHITE_SPACES && it.text.isNotBlank())
|
||||
}
|
||||
}
|
||||
|
||||
private val elementsToWrap = hashSetOf(
|
||||
MarkdownElementTypes.PARAGRAPH,
|
||||
MarkdownElementTypes.EMPH,
|
||||
MarkdownElementTypes.STRONG,
|
||||
MarkdownElementTypes.STRIKETHROUGH
|
||||
)
|
||||
}
|
||||
|
||||
+8
@@ -30,6 +30,14 @@ internal class MarkdownCodeStyleSettingsProvider : LanguageCodeStyleSettingsProv
|
||||
CodeStyleSettingsCustomizable.OptionAnchor.AFTER,
|
||||
"WRAP_ON_TYPING"
|
||||
)
|
||||
consumer.showCustomOption(
|
||||
MarkdownCustomCodeStyleSettings::class.java,
|
||||
MarkdownCustomCodeStyleSettings::WRAP_TEXT_INSIDE_BLOCKQUOTES.name,
|
||||
MarkdownBundle.message("markdown.style.settings.text.wrapping.inside.blockquotes"),
|
||||
null,
|
||||
CodeStyleSettingsCustomizable.OptionAnchor.AFTER,
|
||||
"WRAP_ON_TYPING"
|
||||
)
|
||||
consumer.showCustomOption(
|
||||
MarkdownCustomCodeStyleSettings::class.java,
|
||||
MarkdownCustomCodeStyleSettings::KEEP_LINE_BREAKS_INSIDE_TEXT_BLOCKS.name,
|
||||
|
||||
+3
@@ -47,6 +47,9 @@ class MarkdownCustomCodeStyleSettings(settings: CodeStyleSettings) : CustomCodeS
|
||||
@JvmField
|
||||
var KEEP_LINE_BREAKS_INSIDE_TEXT_BLOCKS = true
|
||||
|
||||
@JvmField
|
||||
var WRAP_TEXT_INSIDE_BLOCKQUOTES = true
|
||||
|
||||
@JvmField
|
||||
var INSERT_QUOTE_ARROWS_ON_WRAP = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user