Skip to content

Commit

Permalink
Unknown section is now rendered in document body
Browse files Browse the repository at this point in the history
  • Loading branch information
hurricup committed Feb 13, 2019
1 parent f07f2ee commit 6dc27be
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 17 deletions.
3 changes: 2 additions & 1 deletion core/grammar/Pod.bnf
Expand Up @@ -31,6 +31,7 @@ limitations under the License.
mixin("head4_section")="com.perl5.lang.pod.parser.psi.mixin.PodSectionH4Mixin"
mixin("pod_paragraph")="com.perl5.lang.pod.parser.psi.mixin.PodSectionParagraphMixin"
mixin("pod_verbatim_paragraph")="com.perl5.lang.pod.parser.psi.mixin.PodSectionVerbatimParagraphMixin"
mixin("unknown_section")="com.perl5.lang.pod.parser.psi.mixin.PodUnknownSectionMixIn"

mixin("over_section")="com.perl5.lang.pod.parser.psi.mixin.PodSectionOverMixin"
mixin("over_section_content")="com.perl5.lang.pod.parser.psi.mixin.PodOverSectionContentMixin"
Expand Down Expand Up @@ -229,7 +230,7 @@ encoding_section ::= POD_ENCODING <<collapseNonSpaceTo 'POD_ENCODING_NAME '>> PO

cut_section ::= POD_CUT [parse_section_title] POD_NEWLINE* {pin=1}

unknown_section ::= POD_UNKNOWN [parse_section_title [any_level_item*]] POD_NEWLINE* {pin=1}
unknown_section ::= POD_UNKNOWN [parse_section_title] POD_NEWLINE* {pin=1}


private pod_term ::=
Expand Down
Expand Up @@ -23,10 +23,14 @@
import com.perl5.lang.pod.parser.psi.util.PodRenderUtil;
import org.jetbrains.annotations.NotNull;

import static com.perl5.lang.pod.parser.psi.util.PodRenderUtil.PARAGRAPH_PREFIX;
import static com.perl5.lang.pod.parser.psi.util.PodRenderUtil.PARAGRAPH_SUFFIX;

/**
* Created by hurricup on 26.03.2016.
*/
public class PodSectionParagraphMixin extends PodSectionMixin implements PodSectionParagraph {

public PodSectionParagraphMixin(@NotNull ASTNode node) {
super(node);
}
Expand All @@ -36,9 +40,9 @@ public void renderElementContentAsHTML(StringBuilder builder, PodRenderingContex
PsiElement firstChild = getFirstChild();

if (firstChild != null) {
builder.append("<p style=\"padding-bottom: 10px;\">");
builder.append(PARAGRAPH_PREFIX);
PodRenderUtil.renderPsiRangeAsHTML(firstChild, null, builder, context);
builder.append("</p>");
builder.append(PARAGRAPH_SUFFIX);
}
}

Expand Down
@@ -0,0 +1,37 @@
/*
* Copyright 2015-2018 Alexandr Evstigneev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.perl5.lang.pod.parser.psi.mixin;

import com.intellij.lang.ASTNode;
import com.perl5.lang.pod.parser.psi.PodRenderingContext;
import org.jetbrains.annotations.NotNull;

import static com.perl5.lang.pod.parser.psi.util.PodRenderUtil.PARAGRAPH_PREFIX;
import static com.perl5.lang.pod.parser.psi.util.PodRenderUtil.PARAGRAPH_SUFFIX;

public abstract class PodUnknownSectionMixIn extends PodTitledSectionMixin {
public PodUnknownSectionMixIn(@NotNull ASTNode node) {
super(node);
}

@Override
public void renderElementTitleAsHTML(StringBuilder builder, PodRenderingContext context) {
builder.append(PARAGRAPH_PREFIX);
super.renderElementTitleAsHTML(builder, context);
builder.append(PARAGRAPH_SUFFIX);
}
}
Expand Up @@ -32,6 +32,9 @@
* Created by hurricup on 26.03.2016.
*/
public class PodRenderUtil implements PodElementTypes {
public static final String PARAGRAPH_PREFIX = "<p style=\"padding-bottom: 10px;\">";
public static final String PARAGRAPH_SUFFIX = "</p>";

public static String renderPsiElementAsHTML(@Nullable PsiElement firstElement) {
return renderPsiRangeAsHTML(firstElement, firstElement);
}
Expand Down
1 change: 1 addition & 0 deletions core/test/documentation/PerlDocumentationTest.java
Expand Up @@ -35,6 +35,7 @@ protected String getTestDataPath() {
return "testData/documentation/perl";
}

public void testUnknownSectionWithContent() {doTest();}

public void testSubDefinitionInline() {doTest();}

Expand Down
2 changes: 2 additions & 0 deletions core/test/parser/PODParserTest.java
Expand Up @@ -31,6 +31,8 @@ protected String getTestDataPath() {
return "testData/parser/pod";
}

public void testUnknownSectionWIthContent() {doTest();}

public void testHierarchy() {
doTest();
}
Expand Down
2 changes: 1 addition & 1 deletion core/testData/breadcrumbs/perl/podInFile.code
Expand Up @@ -36,7 +36,7 @@ text<caret>

Text<caret>

=Item Other titled item<caret>
=item Other titled item<caret>

Text<caret>

Expand Down
7 changes: 3 additions & 4 deletions core/testData/breadcrumbs/perl/podInFile.pl.txt
Expand Up @@ -36,9 +36,9 @@ text<[header1, /perl5language.png, null]: [header2, /perl5language.png, null]: [

Text<[header1, /perl5language.png, null]: [header2, /perl5language.png, null]: [header3, /perl5language.png, null]: [header4, /perl5language.png, null]: [Titled item, /perl5language.png, null]>

=Item Other titled item<[header1, /perl5language.png, null]: [header2, /perl5language.png, null]: [header3, /perl5language.png, null]: [header4, /perl5language.png, null]: [Titled item, /perl5language.png, null]: [Other titled item, /perl5language.png, null]>
=item Other titled item<[header1, /perl5language.png, null]: [header2, /perl5language.png, null]: [header3, /perl5language.png, null]: [header4, /perl5language.png, null]: [Other titled item, /perl5language.png, null]>

Text<[header1, /perl5language.png, null]: [header2, /perl5language.png, null]: [header3, /perl5language.png, null]: [header4, /perl5language.png, null]: [Titled item, /perl5language.png, null]: [Other titled item, /perl5language.png, null]>
Text<[header1, /perl5language.png, null]: [header2, /perl5language.png, null]: [header3, /perl5language.png, null]: [header4, /perl5language.png, null]: [Other titled item, /perl5language.png, null]>

=back<[header1, /perl5language.png, null]: [header2, /perl5language.png, null]: [header3, /perl5language.png, null]: [header4, /perl5language.png, null]>

Expand All @@ -50,5 +50,4 @@ text<[header1, /perl5language.png, null]: [header2, /perl5language.png, null]: [

Text<[header1, /perl5language.png, null]: [header2, /perl5language.png, null]: [header3, /perl5language.png, null]: [header4, /perl5language.png, null]>

=back<[header1, /perl5language.png, null]: [header2, /perl5language.png, null]: [header3, /perl5language.png, null]: [header4, /perl5language.png, null]>

=back<[header1, /perl5language.png, null]: [header2, /perl5language.png, null]: [header3, /perl5language.png, null]: [header4, /perl5language.png, null]>
2 changes: 1 addition & 1 deletion core/testData/breadcrumbs/pod/inFile.code
Expand Up @@ -22,7 +22,7 @@ text<caret>

Text<caret>

=Item Other titled item<caret>
=item Other titled item<caret>

Text<caret>

Expand Down
7 changes: 3 additions & 4 deletions core/testData/breadcrumbs/pod/inFile.pod.txt
Expand Up @@ -22,9 +22,9 @@ text<[header1, /perl5language.png, null]: [header2, /perl5language.png, null]: [

Text<[header1, /perl5language.png, null]: [header2, /perl5language.png, null]: [header3, /perl5language.png, null]: [header4, /perl5language.png, null]: [Titled item, /perl5language.png, null]>

=Item Other titled item<[header1, /perl5language.png, null]: [header2, /perl5language.png, null]: [header3, /perl5language.png, null]: [header4, /perl5language.png, null]: [Titled item, /perl5language.png, null]: [Other titled item, /perl5language.png, null]>
=item Other titled item<[header1, /perl5language.png, null]: [header2, /perl5language.png, null]: [header3, /perl5language.png, null]: [header4, /perl5language.png, null]: [Other titled item, /perl5language.png, null]>

Text<[header1, /perl5language.png, null]: [header2, /perl5language.png, null]: [header3, /perl5language.png, null]: [header4, /perl5language.png, null]: [Titled item, /perl5language.png, null]: [Other titled item, /perl5language.png, null]>
Text<[header1, /perl5language.png, null]: [header2, /perl5language.png, null]: [header3, /perl5language.png, null]: [header4, /perl5language.png, null]: [Other titled item, /perl5language.png, null]>

=back<[header1, /perl5language.png, null]: [header2, /perl5language.png, null]: [header3, /perl5language.png, null]: [header4, /perl5language.png, null]>

Expand All @@ -36,5 +36,4 @@ text<[header1, /perl5language.png, null]: [header2, /perl5language.png, null]: [

Text<[header1, /perl5language.png, null]: [header2, /perl5language.png, null]: [header3, /perl5language.png, null]: [header4, /perl5language.png, null]>

=back<[header1, /perl5language.png, null]: [header2, /perl5language.png, null]: [header3, /perl5language.png, null]: [header4, /perl5language.png, null]>

=back<[header1, /perl5language.png, null]: [header2, /perl5language.png, null]: [header3, /perl5language.png, null]: [header4, /perl5language.png, null]>
17 changes: 17 additions & 0 deletions core/testData/documentation/perl/unknownSectionWithContent.code
@@ -0,0 +1,17 @@
=pod

=head1 somesub

headed text

second text

=unknown unknown title

unknown body

=cut

sub som<caret>esub{

}
@@ -0,0 +1,6 @@


<h1>somesub</h1><p style="padding-bottom: 10px;">headed text</p>
<p style="padding-bottom: 10px;">second text</p>
<p style="padding-bottom: 10px;">unknown title</p>
<p style="padding-bottom: 10px;">unknown body</p>
8 changes: 4 additions & 4 deletions core/testData/parser/pod/hierarchy.txt
Expand Up @@ -807,7 +807,7 @@ POD file
PsiSectionTitleImpl(Perl5 POD: SECTION_TITLE)
<empty list>
PsiElement(Perl5 POD: POD_NEWLINE)('\n')
PsiCutSectionImpl(Perl5 POD: CUT_SECTION)
PsiElement(Perl5 POD: POD_CUT)('=cut')
PsiSectionTitleImpl(Perl5 POD: SECTION_TITLE)
<empty list>
PsiCutSectionImpl(Perl5 POD: CUT_SECTION)
PsiElement(Perl5 POD: POD_CUT)('=cut')
PsiSectionTitleImpl(Perl5 POD: SECTION_TITLE)
<empty list>
13 changes: 13 additions & 0 deletions core/testData/parser/pod/unknownSectionWIthContent.code
@@ -0,0 +1,13 @@
=pod

=head1 somesub

headed text

second text

=unknown unknown title

unknown body

=cut
32 changes: 32 additions & 0 deletions core/testData/parser/pod/unknownSectionWIthContent.txt
@@ -0,0 +1,32 @@
POD file
PsiPodSectionImpl(Perl5 POD: POD_SECTION)
PsiElement(Perl5 POD: POD_POD)('=pod')
PsiElement(Perl5 POD: POD_NEWLINE)('\n')
PsiHead1SectionImpl(Perl5 POD: HEAD_1_SECTION)
PsiElement(Perl5 POD: POD_HEAD1)('=head1')
PsiSectionTitleImpl(Perl5 POD: SECTION_TITLE)
PodIdentifierImpl(Perl5 POD: POD_IDENTIFIER)('somesub')
PsiElement(Perl5 POD: POD_NEWLINE)('\n')
PsiHead1SectionContentImpl(Perl5 POD: HEAD_1_SECTION_CONTENT)
PsiPodParagraphImpl(Perl5 POD: POD_PARAGRAPH)
PodIdentifierImpl(Perl5 POD: POD_IDENTIFIER)('headed')
PodIdentifierImpl(Perl5 POD: POD_IDENTIFIER)('text')
PsiElement(Perl5 POD: POD_NEWLINE)('\n')
PsiPodParagraphImpl(Perl5 POD: POD_PARAGRAPH)
PodIdentifierImpl(Perl5 POD: POD_IDENTIFIER)('second')
PodIdentifierImpl(Perl5 POD: POD_IDENTIFIER)('text')
PsiElement(Perl5 POD: POD_NEWLINE)('\n')
PsiUnknownSectionImpl(Perl5 POD: UNKNOWN_SECTION)
PsiElement(Perl5 POD: POD_UNKNOWN)('=unknown')
PsiSectionTitleImpl(Perl5 POD: SECTION_TITLE)
PodIdentifierImpl(Perl5 POD: POD_IDENTIFIER)('unknown')
PodIdentifierImpl(Perl5 POD: POD_IDENTIFIER)('title')
PsiElement(Perl5 POD: POD_NEWLINE)('\n')
PsiPodParagraphImpl(Perl5 POD: POD_PARAGRAPH)
PodIdentifierImpl(Perl5 POD: POD_IDENTIFIER)('unknown')
PodIdentifierImpl(Perl5 POD: POD_IDENTIFIER)('body')
PsiElement(Perl5 POD: POD_NEWLINE)('\n')
PsiCutSectionImpl(Perl5 POD: CUT_SECTION)
PsiElement(Perl5 POD: POD_CUT)('=cut')
PsiSectionTitleImpl(Perl5 POD: SECTION_TITLE)
<empty list>

0 comments on commit 6dc27be

Please sign in to comment.