Skip to content

Commit

Permalink
feat(parser/renderer): support passthrough (#41)
Browse files Browse the repository at this point in the history
support for:
- "single plus" (i.e., wrapping with `+`)
- "triple plus" (i.e., wrapping with `+++`)
- using the `pass:[]` and `pass:q[]` macros

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon authored Nov 11, 2017
1 parent 8e59c45 commit aa501da
Show file tree
Hide file tree
Showing 29 changed files with 2,159 additions and 1,422 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ tmp

# exclude code coverage merged results
coverage.txt
*.html
16 changes: 16 additions & 0 deletions LIMITATIONS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,19 @@ whereas Asciidoc/Asciidoctor will produce :
<p><strong>some *nested bold</strong> content*.</p>
```

== Passthroughs

The Inline pass macro will not render nothing at all instead of an empty paragraph
when the macro is empty. I.e.:

````
pass:[]
````

will produce no HTML element at all, whereas Asciidoc/Asciidoctor will produce :

````
<div class="paragraph">
<p></p>
</div>
````
1 change: 1 addition & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ It is is available under the terms of the https://raw.githubusercontent.com/byte
* Delimited Source Blocks (using the `+++```+++` delimiter, a.k.a "fences")
* Literal blocks (paragraph starting with a space, with the "...." delimiter or with the `[literal]` attribute)
* Quoted text (+bold+, _italic_ and `monospace`) and substitution prevention using the `\` escape character
* Passtrough (wrapping with a single plus or a triple plus, or using the `pass:[]` or `pass:q[]` macros)
* Unordered lists, using the `-` marker for simple lists, or the `\*` marker for nested lists (and `\**`, `\***`, etc. for the sublists)
* External links in paragraphs (`https://`, `http://`, `ftp://`, `irc://`, `mailto:`)
* Inline images in paragraphs (`image://`)
Expand Down
110 changes: 0 additions & 110 deletions README.html

This file was deleted.

4 changes: 2 additions & 2 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion libasciidoc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/stretchr/testify/require"
)

var _ = Describe("Rendering documents in HTML", func() {
var _ = Describe("Documents", func() {

Context("Document Body", func() {

Expand Down
61 changes: 47 additions & 14 deletions parser/asciidoc-grammar.peg
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ Preamble <- elements:(StandaloneBlock*) {
// ------------------------------------------
FrontMatter <- YamlFrontMatter

FrontMatter <- YamlFrontMatterToken content:(!YamlFrontMatterToken .)* YamlFrontMatterToken {
return types.NewYamlFrontMatter(content.([]interface{}))
FrontMatter <- YamlFrontMatterToken content:(YamlFrontMatterContent) YamlFrontMatterToken {
return types.NewYamlFrontMatter(content.(string))
}

YamlFrontMatterToken <- "---" EOL

YamlFrontMatterContent <- (!YamlFrontMatterToken .)* {
return string(c.text), nil
}

// ------------------------------------------
// Document Header
// ------------------------------------------
Expand Down Expand Up @@ -65,7 +69,7 @@ DocumentAuthor <- WS* namePart1:(DocumentAuthorNamePart) namePart2:(DocumentAuth
}

// "<" marks the beginning of the author email, and ";" is the authors separator
DocumentAuthorNamePart <- !"<" !";" Word WS*
DocumentAuthorNamePart <- !"<" !";" Characters WS*

DocumentAuthorEmail <- "<" email:(!">" !EOL .)+ ">"

Expand Down Expand Up @@ -216,11 +220,11 @@ InlineContent <- !FencedBlockDelimiter elements:(WS* InlineElement WS*)+ &EOL {
return types.NewInlineContent(elements.([]interface{}))
}

InlineElement <- InlineImage / QuotedText / ExternalLink / DocumentAttributeSubstitution / Word
InlineElement <- Passthrough / InlineImage / QuotedText / ExternalLink / DocumentAttributeSubstitution / Characters

// ------------------------------------------
// Quoted Texts (bold, italic and monospace)
// ------------------------------------------
// ----------------------------------------------------------------------------
// Quoted Texts (bold, italic and monospace) including substitution prevention
// ----------------------------------------------------------------------------
QuotedText <- BoldText / ItalicText / MonospaceText /
EscapedBoldText / EscapedItalicText / EscapedMonospaceText

Expand Down Expand Up @@ -316,17 +320,42 @@ EscapedMonospaceTextUnbalancedPunctuation <- backslashes:(`\` `\`*) "``" conten

QuotedTextContent <- QuotedTextContentElement (WS+ QuotedTextContentElement)*

QuotedTextContentElement <- QuotedText / QuotedTextWord / WordWithQuotePunctuation // word with quote punctuation is only accepted if nothing matched before, so we have a chance to stop
QuotedTextContentElement <- QuotedText / QuotedTextCharacters / CharactersWithQuotePunctuation // word with quote punctuation is only accepted if nothing matched before, so we have a chance to stop

QuotedTextWord <- (!NEWLINE !WS !"*" !"_" !"`" .)+ // cannot have "*", "_" or "`" within
WordWithQuotePunctuation <- (!NEWLINE !WS .)+ { // can have "*", "_" or "`" within, maybe because the user inserted another quote, or made an error (extra or missing space, for example)
QuotedTextCharacters <- (!NEWLINE !WS !"*" !"_" !"`" .)+ // cannot have "*", "_" or "`" within
CharactersWithQuotePunctuation <- (!NEWLINE !WS .)+ { // can have "*", "_" or "`" within, maybe because the user inserted another quote, or made an error (extra or missing space, for example)
return c.text, nil
}

// make sure unbalanced punctuation for quoted text is treated accordingly
UnbalancedQuotePunctuation <- "*" / "_" / "`"


// ------------------------------------------
// Passthrough
// ------------------------------------------
Passthrough <- TriplePlusPassthrough / SinglePlusPassthrough / PassthroughMacro

SinglePlusPassthrough <- "+" content:(!NEWLINE !"+" .)* "+" {
return types.NewPassthrough(types.SinglePlusPassthrough, content.([]interface{}))
}

TriplePlusPassthrough <- "+++" content:(!"+++" .)* "+++" {
return types.NewPassthrough(types.TriplePlusPassthrough, content.([]interface{}))
}

PassthroughMacro <- SimplePassthroughMacro / PassthroughWithQuotedText

SimplePassthroughMacro <- "pass:[" content:(PassthroughMacroCharacter)* "]" {
return types.NewPassthrough(types.PassthroughMacro, content.([]interface{}))
}

PassthroughWithQuotedText <- "pass:q[" content:(QuotedText / PassthroughMacroCharacter)* "]" {
return types.NewPassthrough(types.PassthroughMacro, content.([]interface{}))
}

PassthroughMacroCharacter <- (!"]" .)

// ------------------------------------------
// Links
// ------------------------------------------
Expand Down Expand Up @@ -422,16 +451,20 @@ ElementTitle <- "." !"." !WS title:(!NEWLINE .)+ EOL {
return types.NewElementTitle(title.([]interface{}))
}

// ------------------------------------------
// BlankLine
// ------------------------------------------
BlankLine <- !EOF WS* EOL {
return types.NewBlankLine()
}

// ------------------------------------------
// Base Types
// ------------------------------------------
Word <- (!NEWLINE !WS .)+ {
Characters <- (!NEWLINE !WS .)+ {
return string(c.text), nil
}

BlankLine <- !EOF WS* EOL {
return types.NewBlankLine()
}

URL <- (!NEWLINE !WS !"[" !"]" .)+ {
return string(c.text), nil
Expand Down
Loading

0 comments on commit aa501da

Please sign in to comment.