Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QDOC: fix some corner cases in doc rendered #5669

Merged
merged 1 commit into from Jul 2, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/main/kotlin/org/rust/lang/doc/RsDocPipeline.kt
Expand Up @@ -141,7 +141,7 @@ private class RsCodeFenceProvider(private val context: PsiElement) : GeneratingP
var skipNextEOL = false
var lastChildWasContent = false

loop@for (child in childrenToConsider) {
loop@ for (child in childrenToConsider) {
if (isContentStarted && child.type in listOf(MarkdownTokenTypes.CODE_FENCE_CONTENT, MarkdownTokenTypes.EOL)) {
if (skipNextEOL && child.type == MarkdownTokenTypes.EOL) {
skipNextEOL = false
Expand All @@ -152,12 +152,14 @@ private class RsCodeFenceProvider(private val context: PsiElement) : GeneratingP
// * `# ` prefix is used to mark lines that should be skipped in rendered documentation.
// * `##` prefix is converted to `#`
// See https://github.com/rust-lang/rust/blob/5182cc1ca65d05f16ee5e1529707ac6f63233ca9/src/librustdoc/html/markdown.rs#L114 for more details
val trimmedLine = rawLine.trimStart()
val codeLine = when {
rawLine.startsWith("# ") -> {
// `#` or `# `
trimmedLine.startsWith("#") && trimmedLine.getOrNull(1)?.equals(' ') != false -> {
skipNextEOL = true
continue@loop
}
rawLine.startsWith("##") -> rawLine.removePrefix("#")
trimmedLine.startsWith("##") -> trimmedLine.removePrefix("#")
else -> rawLine
}

Expand Down
Expand Up @@ -109,8 +109,13 @@ class RsCodeHighlightingInQuickDocumentationTest : RsDocumentationProviderTest()
/// ```
/// #[attr1]
/// ##[attr2]
/// ##[attr3]
/// #
/// #
/// let foo = Foo;
/// # let foo2 = Foo;
/// # let foo3 = Foo;
/// let foo4 = Foo;
/// ```
struct Foo;
//^
Expand All @@ -119,7 +124,9 @@ class RsCodeHighlightingInQuickDocumentationTest : RsDocumentationProviderTest()
struct <b>Foo</b></pre></div>
<div class='content'><p>Some doc.</p><h2>Example</h2><pre>#[attr1]
#[attr2]
#[attr3]
<span style="...">let </span>foo = Foo;
<span style="...">let </span>foo4 = Foo;
</pre>
</div>
""")
Expand Down