MycomarkupDocument ::=
TopLevelBlock*
TopLevelBlock ::=
Paragraph
| Heading
| CodeBlock
| ThematicBreak
| ImageGallery
| List
| LaunchPad
| Quote
| Table
| Transclusion
Keywords
Token =
Backslash
| LineEnd
| LineStart
| EOD # End Of Document
| Open
| Close
| HeadingToken1 | HeadingToken2 | HeadingToken3 | HeadingToken4
| TripleBacktick
| FourHyphens
| Img
| Rocket
| ListMarker
Backslash = "\"
LineStart = ? Found right after LineEnd, Open and Close ?
LineEnd = "\n"
Open = "{"
Close = "}"
HeadingToken1 = LineStart "=" LWS
HeadingToken2 = LineStart "==" LWS
HeadingToken3 = LineStart "===" LWS
HeadingToken4 = LineStart "====" LWS
TripleBacktick = LineStart "```"
FourHyphens = LineStart "----"
Img = LineStart "img" LWS
Rocket = LineStart "=>"
ListMarker = LineStart "*"+ ( "." | "v" | "x" )* LWS
Formatted
Formatted block is the most fundamental block in Mycomarkup. It represents a line formatted text.
Formatted block does not appear by itself. It is always part of something else. The most common container for Formatted is Paragraph. This is how a Paragraph containing a Formatted might look:
This is Formatted inside Paragraph.
Formatted has these types of elements inside. They are called spans, and are not found in any other blocks.
-
Text span is a sequence of unformatted text. A Formatted containing only one text span and nothing else is basically unformatted text.
-
Formatting markers that toggle formatting styles: italic, bold, highlight, underline, monospace, supertext, subtext, strike-through.
-
Inline links have a target and an optional displayed text. If there is no displayed text given by the writer, it is the same as target. Empty links are removed from the output.
-
Automatic links
Grammar:
Formatted ::=
Span+
Span ::=
TextSpan | Code | FormattingMarker | InlineLink | AutoLink
Code ::=
"`" Text "`"
FormattingMarker ::=
"**" | "//" | "++" | "__" | "^^" | ",," | "~~"
InlineLink ::=
"[[" LWS "]]" # empty link
| "[[" LWS LinkTarget LWS "]]" # link with target only
| "[[" LWS LinkTarget LWS "|" LWS LinkDisplayedText LWS "]]" # link with both target and displayed text
AutoLink ::=
...
Paragraph
Paragraph block is the container of one Formatted block.
Paragraph ::= ( LineBeginning Formatted NL )*
Heading
Heading introduces a new section. Headings go to the table of contents.
Heading ::=
(Heading1
| Heading2
| Heading3
| Heading4) NL
Heading1 ::= "=" LWS FormattedLine
Heading2 ::= "==" LWS FormattedLine
Heading3 ::= "===" LWS FormattedLine
Heading4 ::= "====" LWS FormattedLine
Codeblock
Codeblock is a preformatted block of code.
CodeBlock ::=
LineBeginning "```" Language? NL CodeBlockContents (NL "```" IgnoredText | EOD)
Language ::= (!NL)+
CodeBlockContents ::= CodeBlockLine*
CodeBlockLine ::= SomeText NL
Thematic break
Thematic break introduces a new section without a heading, it breaks themes.
ThematicBreak ::= "----" ThematicBreakAnchor? NL
ThematicBreakAnchor ::= (!NL)+
Image gallery
ImageGallery = Img [ ImgDescriptor ] Open ImgEntry ( Close | EOD )
ImgDescriptor = # not { or NL
ImgEntry = ( LineStart LWS LineEnd ) * LineStart Target [ Pipe LWS Sizes ] LWS*
got tired here
List
...
Launchpad
Launchpad = Rocket LinkTarget [ Pipe [ !NL + ] ] LineEnd;
Quote
Quote is an excerpt from somewhere else.
Quote ::= QuoteLine+
QuoteLine ::= ">" QuoteLineContent (NL | EOD)
Algorithm
After initial parsing, we end up with a collection of QuoteLineContents. This is not we need. We gotta convert it like that:
function QuoteLinesFinalized(lines []string) []string {
# Find the common space prefix length
prefixlen := 0
for line in lines {
curlen := 0
for char in line {
if char == " " {
curlen++
} else {
break
}
}
prefixlen := min(prefixlen, curlen)
}
# Remove the common space prefix
result := []string{}
for line in lines {
result << line[prefixlen:]
}
result
}
Table
Table is a table.
Table ::=
"table" Modifer* "{" TableContents "}" IgnoredText EOL
Modifier ::=
!NL
TableContents ::= (EmptyLine | TableRow)*
TableRow ::=
TableCellWithoutMarker? TableCell* NL
| TableCell+ NL
TableCell ::=
("|" | "!") TableCellWithoutMarker
TableCellWithoutMarker ::=
LWS FormattedLine LWS
| LWS "{" ((Paragraph | ImageGallery | LaunchPad) NL?)* "}" LWS
Transclusion
...