aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gen/org/jetbrains/markdown/MarkdownElementTypes.java1
-rw-r--r--gen/org/jetbrains/markdown/MarkdownParser.java67
-rw-r--r--src/Formats/HtmlFormatService.kt20
-rw-r--r--src/Formats/MarkdownFormatService.kt6
-rw-r--r--src/Formats/StructuredFormatService.kt9
-rw-r--r--src/Kotlin/ContentBuilder.kt5
-rw-r--r--src/Markdown/markdown.bnf4
-rw-r--r--src/Model/Content.kt4
-rw-r--r--styles/style.css2
9 files changed, 102 insertions, 16 deletions
diff --git a/gen/org/jetbrains/markdown/MarkdownElementTypes.java b/gen/org/jetbrains/markdown/MarkdownElementTypes.java
index e8910c7b..337ff1a5 100644
--- a/gen/org/jetbrains/markdown/MarkdownElementTypes.java
+++ b/gen/org/jetbrains/markdown/MarkdownElementTypes.java
@@ -11,6 +11,7 @@ public interface MarkdownElementTypes {
IElementType BLOCK = new IElementType("BLOCK", null);
IElementType BULLET = new IElementType("BULLET", null);
IElementType BULLET_LIST = new IElementType("BULLET_LIST", null);
+ IElementType CODE = new IElementType("CODE", null);
IElementType EMPH = new IElementType("EMPH", null);
IElementType END_LINE = new IElementType("END_LINE", null);
IElementType ENUMERATOR = new IElementType("ENUMERATOR", null);
diff --git a/gen/org/jetbrains/markdown/MarkdownParser.java b/gen/org/jetbrains/markdown/MarkdownParser.java
index c6068e5b..efad3d6e 100644
--- a/gen/org/jetbrains/markdown/MarkdownParser.java
+++ b/gen/org/jetbrains/markdown/MarkdownParser.java
@@ -37,6 +37,9 @@ public class MarkdownParser implements PsiParser {
else if (t == BULLET_LIST) {
r = BulletList(b, 0);
}
+ else if (t == CODE) {
+ r = Code(b, 0);
+ }
else if (t == EMPH) {
r = Emph(b, 0);
}
@@ -260,6 +263,67 @@ public class MarkdownParser implements PsiParser {
}
/* ********************************************************** */
+ // '`' !Whitespace (!'`' Inline)+ '`'
+ public static boolean Code(PsiBuilder b, int l) {
+ if (!recursion_guard_(b, l, "Code")) return false;
+ boolean r;
+ Marker m = enter_section_(b, l, _NONE_, "<code>");
+ r = consumeToken(b, "`");
+ r = r && Code_1(b, l + 1);
+ r = r && Code_2(b, l + 1);
+ r = r && consumeToken(b, "`");
+ exit_section_(b, l, m, CODE, r, false, null);
+ return r;
+ }
+
+ // !Whitespace
+ private static boolean Code_1(PsiBuilder b, int l) {
+ if (!recursion_guard_(b, l, "Code_1")) return false;
+ boolean r;
+ Marker m = enter_section_(b, l, _NOT_, null);
+ r = !Whitespace(b, l + 1);
+ exit_section_(b, l, m, null, r, false, null);
+ return r;
+ }
+
+ // (!'`' Inline)+
+ private static boolean Code_2(PsiBuilder b, int l) {
+ if (!recursion_guard_(b, l, "Code_2")) return false;
+ boolean r;
+ Marker m = enter_section_(b);
+ r = Code_2_0(b, l + 1);
+ int c = current_position_(b);
+ while (r) {
+ if (!Code_2_0(b, l + 1)) break;
+ if (!empty_element_parsed_guard_(b, "Code_2", c)) break;
+ c = current_position_(b);
+ }
+ exit_section_(b, m, null, r);
+ return r;
+ }
+
+ // !'`' Inline
+ private static boolean Code_2_0(PsiBuilder b, int l) {
+ if (!recursion_guard_(b, l, "Code_2_0")) return false;
+ boolean r;
+ Marker m = enter_section_(b);
+ r = Code_2_0_0(b, l + 1);
+ r = r && Inline(b, l + 1);
+ exit_section_(b, m, null, r);
+ return r;
+ }
+
+ // !'`'
+ private static boolean Code_2_0_0(PsiBuilder b, int l) {
+ if (!recursion_guard_(b, l, "Code_2_0_0")) return false;
+ boolean r;
+ Marker m = enter_section_(b, l, _NOT_, null);
+ r = !consumeToken(b, "`");
+ exit_section_(b, l, m, null, r, false, null);
+ return r;
+ }
+
+ /* ********************************************************** */
// BOM? Whitespace* AnonymousSection? (Whitespace* NamedSection)*
static boolean Document(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "Document")) return false;
@@ -716,13 +780,14 @@ public class MarkdownParser implements PsiParser {
}
/* ********************************************************** */
- // Strong | Emph | Link | PlainText
+ // Strong | Emph | Code | Link | PlainText
public static boolean Inline(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "Inline")) return false;
boolean r;
Marker m = enter_section_(b, l, _NONE_, "<inline>");
r = Strong(b, l + 1);
if (!r) r = Emph(b, l + 1);
+ if (!r) r = Code(b, l + 1);
if (!r) r = Link(b, l + 1);
if (!r) r = PlainText(b, l + 1);
exit_section_(b, l, m, INLINE, r, false, null);
diff --git a/src/Formats/HtmlFormatService.kt b/src/Formats/HtmlFormatService.kt
index 20cd4f83..c337b69b 100644
--- a/src/Formats/HtmlFormatService.kt
+++ b/src/Formats/HtmlFormatService.kt
@@ -20,15 +20,15 @@ public open class HtmlFormatService(locationService: LocationService,
}
override fun appendBlockCode(to: StringBuilder, line: String) {
- to.appendln("<code>")
- to.appendln(line)
- to.appendln("</code>")
+ to.append("<pre><code>")
+ to.append(line)
+ to.append("</code></pre>")
}
override fun appendBlockCode(to: StringBuilder, lines: Iterable<String>) {
- to.appendln("<code>")
- to.appendln(lines.join("\n"))
- to.appendln("</code>")
+ to.append("<pre><code>")
+ to.append(lines.join("\n"))
+ to.append("</code></pre>")
}
override fun appendHeader(to: StringBuilder, text: String, level: Int) {
@@ -85,8 +85,12 @@ public open class HtmlFormatService(locationService: LocationService,
return "<a href=\"${href}\">${text}</a>"
}
- override fun formatBold(text: String): String {
- return "<b>${text}</b>"
+ override fun formatStrong(text: String): String {
+ return "<strong>${text}</strong>"
+ }
+
+ override fun formatEmphasis(text: String): String {
+ return "<emph>${text}</emph>"
}
override fun formatCode(code: String): String {
diff --git a/src/Formats/MarkdownFormatService.kt b/src/Formats/MarkdownFormatService.kt
index a835a673..54298e2a 100644
--- a/src/Formats/MarkdownFormatService.kt
+++ b/src/Formats/MarkdownFormatService.kt
@@ -30,10 +30,14 @@ public open class MarkdownFormatService(locationService: LocationService,
return "`$code`"
}
- override public fun formatBold(text: String): String {
+ override public fun formatStrong(text: String): String {
return "**$text**"
}
+ override fun formatEmphasis(text: String): String {
+ return "*$text*"
+ }
+
override public fun formatLink(text: String, location: Location): String {
return "[$text](${location.path})"
}
diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt
index df11b835..75b51ab8 100644
--- a/src/Formats/StructuredFormatService.kt
+++ b/src/Formats/StructuredFormatService.kt
@@ -27,7 +27,8 @@ public abstract class StructuredFormatService(val locationService: LocationServi
public abstract fun formatLink(text: String, location: Location): String
public abstract fun formatLink(text: String, href: String): String
public open fun formatLink(link: FormatLink): String = formatLink(formatText(link.text), link.location)
- public abstract fun formatBold(text: String): String
+ public abstract fun formatStrong(text: String): String
+ public abstract fun formatEmphasis(text: String): String
public abstract fun formatCode(code: String): String
public abstract fun formatBreadcrumbs(items: Iterable<FormatLink>): String
@@ -42,7 +43,9 @@ public abstract class StructuredFormatService(val locationService: LocationServi
is ContentSymbol -> append(formatSymbol(content.text))
is ContentKeyword -> append(formatKeyword(content.text))
is ContentIdentifier -> append(formatIdentifier(content.text))
- is ContentEmphasis -> append(formatBold(formatText(location, content.children)))
+ is ContentStrong -> append(formatStrong(formatText(location, content.children)))
+ is ContentCode -> append(formatCode(formatText(location, content.children)))
+ is ContentEmphasis -> append(formatEmphasis(formatText(location, content.children)))
is ContentNodeLink -> {
val linkTo = locationService.relativeLocation(location, content.node, extension)
val linkText = formatText(location, content.children)
@@ -77,7 +80,7 @@ public abstract class StructuredFormatService(val locationService: LocationServi
for ((label, section) in node.doc.sections) {
if (label.startsWith("$"))
continue
- appendLine(to, formatBold(formatText(label)))
+ appendLine(to, formatStrong(formatText(label)))
appendLine(to, formatText(location, section))
appendLine(to)
}
diff --git a/src/Kotlin/ContentBuilder.kt b/src/Kotlin/ContentBuilder.kt
index b7290b58..9de3001a 100644
--- a/src/Kotlin/ContentBuilder.kt
+++ b/src/Kotlin/ContentBuilder.kt
@@ -39,6 +39,11 @@ public fun MarkdownTree.toContent(): Content {
processChildren()
parent.append(nodeStack.pop())
}
+ MarkdownElementTypes.CODE -> {
+ nodeStack.push(ContentCode())
+ processChildren()
+ parent.append(nodeStack.pop())
+ }
MarkdownElementTypes.ANONYMOUS_SECTION -> {
nodeStack.push(ContentSection(""))
processChildren()
diff --git a/src/Markdown/markdown.bnf b/src/Markdown/markdown.bnf
index d6fd2ed2..d1cd305c 100644
--- a/src/Markdown/markdown.bnf
+++ b/src/Markdown/markdown.bnf
@@ -75,13 +75,15 @@ ListContinuationBlock ::= BlankLine* (Indent ListBlock)+
// ---- INLINES ----
private Inlines ::= (!EndLine Inline | EndLine &Inline )+ EndLine?
-Inline ::= Strong | Emph | Link | PlainText
+Inline ::= Strong | Emph | Code | Link | PlainText
PlainText ::= (Word | Number | Space+)+
Emph ::= EmphStar | EmphUnderscore
private EmphStar ::= '*' !Whitespace (!'*' Inline)+ '*'
private EmphUnderscore ::= '_' !Whitespace (!'_' Inline)+ '_'
+Code ::= '`' !Whitespace (!'`' Inline)+ '`'
+
Strong ::= StrongStar | StrongUnderscore
StrongStar ::= '**' !Whitespace (!'**' Inline)+ '**'
StrongUnderscore ::= '__' !Whitespace (!'__' Inline)+ '__'
diff --git a/src/Model/Content.kt b/src/Model/Content.kt
index ce438835..a3691fd0 100644
--- a/src/Model/Content.kt
+++ b/src/Model/Content.kt
@@ -23,10 +23,12 @@ public class ContentText(val text: String) : ContentNode()
public class ContentKeyword(val text: String) : ContentNode()
public class ContentIdentifier(val text: String) : ContentNode()
public class ContentSymbol(val text: String) : ContentNode()
+
public class ContentEmphasis() : ContentBlock()
+public class ContentStrong() : ContentBlock()
+public class ContentCode() : ContentBlock()
public class ContentNodeLink(val node : DocumentationNode) : ContentBlock()
public class ContentExternalLink(val href : String) : ContentBlock()
-public class ContentStrong() : ContentBlock()
public class ContentList() : ContentBlock()
public class ContentSection(public val label: String) : ContentBlock()
diff --git a/styles/style.css b/styles/style.css
index 581ffe53..5bfb25bc 100644
--- a/styles/style.css
+++ b/styles/style.css
@@ -83,10 +83,10 @@ code, pre {
font-family:Monaco, Bitstream Vera Sans Mono, Lucida Console, Terminal;
color:#333;
font-size:12px;
- display: block;
}
pre {
+ display: block;
padding:8px 8px;
background: #f8f8f8;
border-radius:5px;