Skip to content

Commit

Permalink
feat: add support for image, hr and page break
Browse files Browse the repository at this point in the history
  • Loading branch information
nlopes committed Oct 6, 2024
1 parent 63686d6 commit 9554b65
Show file tree
Hide file tree
Showing 12 changed files with 452 additions and 17 deletions.
3 changes: 3 additions & 0 deletions acdc-parser/fixtures/tests/basic_image_block.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
image::sunset.jpg[alt=Sunset,width=300,height=400]

image::sunset2.jpg[Sunset,300,400]
59 changes: 59 additions & 0 deletions acdc-parser/fixtures/tests/basic_image_block.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"header": null,
"content": [
{
"Image": {
"source": {
"Path": "sunset.jpg"
},
"metadata": {
"roles": [],
"options": [],
"style": null,
"id": null
},
"attributes": [
{
"name": "alt",
"value": "Sunset"
},
{
"name": "width",
"value": "300"
},
{
"name": "height",
"value": "400"
}
]
}
},
{
"Image": {
"source": {
"Path": "sunset2.jpg"
},
"metadata": {
"roles": [],
"options": [],
"style": null,
"id": null
},
"attributes": [
{
"name": "alt",
"value": "Sunset"
},
{
"name": "width",
"value": "300"
},
{
"name": "height",
"value": "400"
}
]
}
}
]
}
5 changes: 5 additions & 0 deletions acdc-parser/fixtures/tests/hr_after_paragraph.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
A paragraph

'''

Another paragraph
59 changes: 59 additions & 0 deletions acdc-parser/fixtures/tests/hr_after_paragraph.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"header": null,
"content": [
{
"Paragraph": {
"roles": [],
"options": [],
"style": null,
"id": null,
"attributes": [],
"content": "A paragraph",
"location": {
"start": {
"line": 0,
"column": 0
},
"end": {
"line": 0,
"column": 0
}
}
}
},
{
"HorizontalRule": {
"location": {
"start": {
"line": 3,
"column": 1
},
"end": {
"line": 5,
"column": 1
}
}
}
},
{
"Paragraph": {
"roles": [],
"options": [],
"style": null,
"id": null,
"attributes": [],
"content": "Another paragraph",
"location": {
"start": {
"line": 0,
"column": 0
},
"end": {
"line": 0,
"column": 0
}
}
}
}
]
}
6 changes: 6 additions & 0 deletions acdc-parser/fixtures/tests/page_break_with_attributes.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
A paragraph

[page-layout=landscape]
<<<

Another paragraph
71 changes: 71 additions & 0 deletions acdc-parser/fixtures/tests/page_break_with_attributes.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"header": null,
"content": [
{
"Paragraph": {
"roles": [],
"options": [],
"style": null,
"id": null,
"attributes": [],
"content": "A paragraph",
"location": {
"start": {
"line": 0,
"column": 0
},
"end": {
"line": 0,
"column": 0
}
}
}
},
{
"PageBreak": {
"metadata": {
"roles": [],
"options": [],
"style": null,
"id": null
},
"attributes": [
{
"name": "page-layout",
"value": "landscape"
}
],
"location": {
"start": {
"line": 3,
"column": 1
},
"end": {
"line": 6,
"column": 1
}
}
}
},
{
"Paragraph": {
"roles": [],
"options": [],
"style": null,
"id": null,
"attributes": [],
"content": "Another paragraph",
"location": {
"start": {
"line": 0,
"column": 0
},
"end": {
"line": 0,
"column": 0
}
}
}
}
]
}
2 changes: 1 addition & 1 deletion acdc-parser/grammar/asciidoc.pest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ document = _{
SOI ~
(NEWLINE | comment)* ~
(document_header ~ NEWLINE)? ~
block* ~
blocks ~
(NEWLINE | comment)* ~
EOI
}
33 changes: 30 additions & 3 deletions acdc-parser/grammar/block.pest
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
block = {
blocks = {
(
section |
delimited_block |
image_block |
horizontal_rule |
page_break_block |
list |
paragraph
)
)*
}

section = {
Expand All @@ -21,13 +24,37 @@ section_level_symbol = _{ ("=" | "#") }
section_level = { section_level_symbol{2,6} }
section_title = { ONE_CHAR* }

// TODO(nlopes): can we have multiple anchor statements? What does that mean? Multiple IDs
// or should I have an ID with multiple aliases/anchors?
//
// When working on anchors, check https://docs.asciidoctor.org/asciidoc/latest/attributes/id/#add-additional-anchors-to-a-section
image_block = { anchor* ~ image ~ (NEWLINE{2,} | EOI) }
image = { "image::" ~ (url | path) ~ attrlist }

horizontal_rule = @{
(
"'''\n\n" |
// Below are the markdown-style ones
"---\n\n" |
"- - -\n\n" |
"***\n\n" |
"* * *\n\n"
) ~ NEWLINE*
}

page_break_block = {
attribute_list ~ page_break ~ NEWLINE*
}

page_break = _{ "<<<\n\n" }

// Paragraphs
paragraph = {
(anchor | attribute_list | blocktitle)* ~
paragraph_inner ~ NEWLINE*
}

paragraph_inner = { (!((NEWLINE{2,}) | EOI) ~ ANY)+ }
paragraph_inner = { (&(!((NEWLINE{2,}) | EOI)) ~ ANY)+ }

// WIP
//inline_element = {}
10 changes: 10 additions & 0 deletions acdc-parser/grammar/core.pest
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,13 @@ named_attribute_value = {
}
positional_attribute_value = { (!("\"" | "," | "]" | "#" | "." | "%") ~ ANY)+ }
inner_attribute_value = _{ ( "\\\"" | (!"\"" ~ ANY))* }

url = ${proto ~ "://" ~ path}
proto = ${
"https" |
"http" |
"ftp" |
"irc" |
"mailto"
}
path = @{ (ASCII_ALPHANUMERIC | "_" | "-" | "." | "/" | "~" )+ }
3 changes: 0 additions & 3 deletions acdc-parser/grammar/delimited.pest
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
delimited_block = {
// TODO(nlopes): `attribute_list` doesn't conform to what's in the docs.
//
// Check what this should be at https://docs.asciidoctor.org/asciidoc/latest/attributes/positional-and-named-attributes/
(anchor | attribute_list | blocktitle)* ~
(
delimited_comment |
Expand Down
Loading

0 comments on commit 9554b65

Please sign in to comment.