Skip to content

Commit

Permalink
feat(parser/renderer): support sidebar blocks (#182)
Browse files Browse the repository at this point in the history
Fixes #139

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon authored Sep 2, 2018
1 parent 9cd9c9f commit e34547c
Show file tree
Hide file tree
Showing 6 changed files with 6,028 additions and 4,272 deletions.
40 changes: 36 additions & 4 deletions pkg/parser/asciidoc-grammar.peg
Original file line number Diff line number Diff line change
Expand Up @@ -736,19 +736,29 @@ ImageAttribute <- (!"," !"=" !"]" .)+ { // attribute is followed by "," or "]" (
// ------------------------------------------------------------------------------------
// Delimited Blocks (http://asciidoctor.org/docs/user-manual/#built-in-blocks-summary)
// ------------------------------------------------------------------------------------
DelimitedBlock <- FencedBlock / ListingBlock / ExampleBlock / CommentBlock / VerseBlock / QuoteBlock
DelimitedBlock <- FencedBlock / ListingBlock / ExampleBlock
/ CommentBlock / VerseBlock / QuoteBlock
/ SidebarBlock

BlockDelimiter <- LiteralBlockDelimiter / FencedBlockDelimiter / ListingBlockDelimiter / ExampleBlockDelimiter / CommentBlockDelimiter / QuoteBlockDelimiter
BlockDelimiter <- LiteralBlockDelimiter / FencedBlockDelimiter / ListingBlockDelimiter
/ ExampleBlockDelimiter / CommentBlockDelimiter / QuoteBlockDelimiter
/ SidebarBlockDelimiter


// -------------------------------------------------------------------------------------
// Fenced Blocks
// -------------------------------------------------------------------------------------
FencedBlockDelimiter <- "```"

FencedBlock <- attributes:(ElementAttribute)* FencedBlockDelimiter WS* NEWLINE content:(List / BlockParagraph / BlankLine)* ((FencedBlockDelimiter WS* EOL) / EOF) {
FencedBlock <- attributes:(ElementAttribute)* FencedBlockDelimiter WS* NEWLINE content:(FencedBlockContent)* ((FencedBlockDelimiter WS* EOL) / EOF) {
return types.NewDelimitedBlock(types.Fenced, content.([]interface{}), attributes.([]interface{}), types.None)
}

FencedBlockContent <- List / BlockParagraph / BlankLine

// -------------------------------------------------------------------------------------
// Listing blocks
// -------------------------------------------------------------------------------------
ListingBlockDelimiter <- "----"

// listing block: verbatim content
Expand All @@ -768,14 +778,15 @@ ListingBlockLineContent <- (!ListingBlockDelimiter !EOL .)* { // skip EOL in lin
return types.NewInlineElements(string(c.text))
}

// -------------------------------------------------------------------------------------
// Example blocks
// -------------------------------------------------------------------------------------
ExampleBlockDelimiter <- "===="

ExampleBlock <- attributes:(ElementAttribute)* ExampleBlockDelimiter WS* NEWLINE content:(List / BlockParagraph / BlankLine)* ((ExampleBlockDelimiter WS* EOL) / EOF) {
return types.NewDelimitedBlock(types.Example, content.([]interface{}), attributes.([]interface{}), types.None)
}


// blocks content
BlockParagraph <- lines:(BlockParagraphLine)+ {
return types.NewParagraph(lines.([]interface{}), nil)
Expand All @@ -790,7 +801,9 @@ BlockParagraphLine <- !(OrderedListItemPrefix)
return line, nil
}

// -------------------------------------------------------------------------------------
// Quote blocks
// -------------------------------------------------------------------------------------
QuoteBlockDelimiter <- "____" // same for verse blocks

QuoteBlock <- attributes:(QuoteBlockAttributes)+ QuoteBlockDelimiter WS* NEWLINE content:(QuoteBlockContent)* ((QuoteBlockDelimiter WS* EOL) / EOF) {
Expand All @@ -813,7 +826,11 @@ QuoteBlockContent <-
return element, nil
}

// -------------------------------------------------------------------------------------
// Verse blocks
// -------------------------------------------------------------------------------------
// VerseBlockDelimiter: see QuoteBlockDelimiter

VerseBlock <- attributes:(VerseBlockAttributes)+ QuoteBlockDelimiter WS* NEWLINE content:(VerseBlockContent)* ((QuoteBlockDelimiter WS* EOL) / EOF) {
return types.NewDelimitedBlock(types.Verse,
content.([]interface{}),
Expand All @@ -838,6 +855,21 @@ VerseBlockLineContent <- elements:(!QuoteBlockDelimiter !EOL WS* InlineElement W
return types.NewInlineElements(elements.([]interface{}))
}

// -------------------------------------------------------------------------------------
// Sidebars
// -------------------------------------------------------------------------------------
SidebarBlockDelimiter <- "****"

SidebarBlock <- attributes:(ElementAttribute)* SidebarBlockDelimiter WS* NEWLINE content:(SidebarBlockContent)* ((SidebarBlockDelimiter WS* EOL) / EOF) {
return types.NewDelimitedBlock(types.Sidebar, content.([]interface{}), attributes.([]interface{}), types.None)
}

SidebarBlockContent <- List / BlockParagraph / BlankLine / NonSidebarBlock

NonSidebarBlock <- !SidebarBlock content:(DelimitedBlock) {
return content, nil
}

// -------------------------------------------------------------------------------------
// Tables
// -------------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit e34547c

Please sign in to comment.