Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
## [Unreleased]
- Decode character references above U+FFFF, such as `😀` or `𝔄`, to the right character instead of a truncated one, and replace `�`, surrogates and out of range numeric references with U+FFFD as required by CommonMark
- Parse an ATX heading followed by `---` or `===` as a heading, not as setext content (IJPL-94630)
- Add `lazyContinuation` parameter to GFM flavor

## [0.7.18]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ import org.intellij.markdown.parser.sequentialparsers.impl.*
* otherwise. When enabled, the leading `<` of the disallowed raw HTML tags (`title`, `textarea`, `style`, `xmp`,
* `iframe`, `noembed`, `noframes`, `script`, `plaintext`) is replaced with `&lt;`.
* See [Disallowed Raw HTML (extension)](https://github.github.com/gfm/#disallowed-raw-html-extension-)
*
* @param lazyContinuation `true` if an unmarked line may continue a paragraph inside a block quote.
*/
open class GFMFlavourDescriptor(
useSafeLinks: Boolean = true,
absolutizeAnchorLinks: Boolean = false,
private val makeHttpsAutoLinks: Boolean = false,
private val useTagFilter: Boolean = false
private val useTagFilter: Boolean = false,
private val lazyContinuation: Boolean = true,
) : CommonMarkFlavourDescriptor(useSafeLinks, absolutizeAnchorLinks) {
/**
* For ABI compatibility.
Expand All @@ -49,7 +52,15 @@ open class GFMFlavourDescriptor(
makeHttpsAutoLinks: Boolean = false
) : this(useSafeLinks, absolutizeAnchorLinks, makeHttpsAutoLinks, useTagFilter = false)

override val markerProcessorFactory: MarkerProcessorFactory = GFMMarkerProcessor.Factory
constructor(
useSafeLinks: Boolean = true,
absolutizeAnchorLinks: Boolean = false,
makeHttpsAutoLinks: Boolean = false,
useTagFilter: Boolean = false,
) : this(useSafeLinks, absolutizeAnchorLinks, makeHttpsAutoLinks, useTagFilter, lazyContinuation = true)

override val markerProcessorFactory: MarkerProcessorFactory =
GFMMarkerProcessor.Factory.withLazyContinuation(lazyContinuation)

override fun createInlinesLexer(): MarkdownLexer {
return MarkdownLexer(_GFMLexer())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,24 @@ import org.intellij.markdown.parser.constraints.CommonMarkdownConstraints
import org.intellij.markdown.parser.constraints.MarkdownConstraints
import org.intellij.markdown.parser.constraints.getCharsEaten
import org.intellij.markdown.parser.markerblocks.MarkerBlockProvider
import org.intellij.markdown.parser.markerblocks.providers.BlockQuoteProvider
import org.intellij.markdown.parser.sequentialparsers.SequentialParser
import kotlin.math.min

class GFMMarkerProcessor(productionHolder: ProductionHolder, constraintsBase: CommonMarkdownConstraints)
class GFMMarkerProcessor(
productionHolder: ProductionHolder,
constraintsBase: CommonMarkdownConstraints,
private val lazyContinuation: Boolean,
)
: CommonMarkMarkerProcessor(productionHolder, constraintsBase) {

constructor(productionHolder: ProductionHolder, constraintsBase: CommonMarkdownConstraints) :
this(productionHolder, constraintsBase, lazyContinuation = true)

private val markerBlockProviders = listOf(GitHubAlertMarkerProvider())
.plus(super.getMarkerBlockProviders())
.plus(super.getMarkerBlockProviders().map {
if (it is BlockQuoteProvider) BlockQuoteProvider(lazyContinuation) else it
})
.plus(listOf(GitHubTableMarkerProvider()))

override fun getMarkerBlockProviders(): List<MarkerBlockProvider<StateInfo>> {
Expand Down Expand Up @@ -66,5 +76,15 @@ class GFMMarkerProcessor(productionHolder: ProductionHolder, constraintsBase: Co
override fun createMarkerProcessor(productionHolder: ProductionHolder): MarkerProcessor<*> {
return GFMMarkerProcessor(productionHolder, GFMConstraints.BASE)
}

internal fun withLazyContinuation(lazyContinuation: Boolean): MarkerProcessorFactory {
return if (lazyContinuation) this else ConfiguredFactory(lazyContinuation)
}
}

private class ConfiguredFactory(private val lazyContinuation: Boolean) : MarkerProcessorFactory {
override fun createMarkerProcessor(productionHolder: ProductionHolder): MarkerProcessor<*> {
return GFMMarkerProcessor(productionHolder, GFMConstraints.BASE, lazyContinuation)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package org.intellij.markdown

import org.intellij.markdown.flavours.commonmark.CommonMarkFlavourDescriptor
import org.intellij.markdown.flavours.commonmark.CommonMarkMarkerProcessor
import org.intellij.markdown.flavours.gfm.GFMConstraints
import org.intellij.markdown.flavours.gfm.GFMFlavourDescriptor
import org.intellij.markdown.flavours.gfm.alert.GitHubAlertMarkerProvider
import org.intellij.markdown.flavours.gfm.table.GitHubTableMarkerProvider
import org.intellij.markdown.parser.MarkerProcessor
import org.intellij.markdown.parser.MarkerProcessorFactory
import org.intellij.markdown.parser.ProductionHolder
Expand All @@ -23,15 +20,19 @@ private class NonLazyBlockQuoteMarkerProcessor(
first: List<MarkerBlockProvider<StateInfo>> = emptyList(),
last: List<MarkerBlockProvider<StateInfo>> = emptyList()
) : CommonMarkMarkerProcessor(productionHolder, constraintsBase) {
private val markerBlockProviders = first + super.getMarkerBlockProviders().map {
if (it is BlockQuoteProvider) BlockQuoteProvider(lazyContinuation = false) else it
} + last
private val markerBlockProviders = buildList {
addAll(first)
super.getMarkerBlockProviders().mapTo(this) {
if (it is BlockQuoteProvider) BlockQuoteProvider(lazyContinuation = false) else it
}
addAll(last)
}

override fun getMarkerBlockProviders(): List<MarkerBlockProvider<StateInfo>> = markerBlockProviders
}

/**
* The CommonMark flavour that ends a block quote at a line without the `>` marker instead of continuing its paragraph.
* The CommonMark flavor that ends a block quote at a line without the `>` marker instead of continuing its paragraph.
*/
class NonLazyBlockQuoteCommonMarkFlavour : CommonMarkFlavourDescriptor() {
override val markerProcessorFactory: MarkerProcessorFactory = object : MarkerProcessorFactory {
Expand All @@ -41,19 +42,5 @@ class NonLazyBlockQuoteCommonMarkFlavour : CommonMarkFlavourDescriptor() {
}
}

/**
* The GFM flavour that ends a block quote at a line without the `>` marker instead of continuing its paragraph.
* Its marker processor has the providers of [org.intellij.markdown.flavours.gfm.GFMMarkerProcessor].
*/
class NonLazyBlockQuoteGfmFlavour : GFMFlavourDescriptor() {
override val markerProcessorFactory: MarkerProcessorFactory = object : MarkerProcessorFactory {
override fun createMarkerProcessor(productionHolder: ProductionHolder): MarkerProcessor<*> {
return NonLazyBlockQuoteMarkerProcessor(
productionHolder,
GFMConstraints.BASE,
first = listOf(GitHubAlertMarkerProvider()),
last = listOf(GitHubTableMarkerProvider())
)
}
}
}
/** The GFM flavor that ends a block quote at a line without the `>` marker. */
class NonLazyBlockQuoteGfmFlavour : GFMFlavourDescriptor(lazyContinuation = false)
Loading