aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-05-30 22:12:40 +0700
committerShulhan <ms@kilabit.info>2023-05-30 22:12:59 +0700
commit4e0507b62393b8461b29cda7565f685d79b58ca3 (patch)
treedee4458e68300225fcebb88a1ecc5577b97d4828
parent3c25256f105271c402eb56cd19b1e73fa8fd26fb (diff)
downloadasciidoctor-go-4e0507b62393b8461b29cda7565f685d79b58ca3.tar.xz
all: handle custom marker in between unordered list
Given the following markup, [square] * item 1 [circle] ** item 2 The list on item 2 now start with `<div class="ulist circle">`.
-rw-r--r--README.md15
-rw-r--r--document_parser.go26
-rw-r--r--parser.go10
-rw-r--r--testdata/list_unordered_test.txt154
-rw-r--r--testdata/test.adoc18
-rw-r--r--testdata/test.exp.html67
-rw-r--r--testdata/test.got.html67
7 files changed, 335 insertions, 22 deletions
diff --git a/README.md b/README.md
index 6a8b257..74ac00e 100644
--- a/README.md
+++ b/README.md
@@ -52,14 +52,15 @@ The numbered one is based on the old documentation.
* Quotation Marks and Apostrophes
* Subscript and Superscript
* Monospace
-* Unordered Lists (See Notes below)
- * Nested
- * Complex List Content
- * Custom Markers
+* List
+ * Unordered Lists (See Notes below)
+ * Nested
+ * Complex List Content
+ * Custom Markers
+ * Ordered Lists
+ * Nested
+ * Numbering Styles
* Checklist
-* Ordered Lists
- * Nested
- * Numbering Styles
* Description List
* Question and Answer Style List
* Tables
diff --git a/document_parser.go b/document_parser.go
index db2dec1..baeb82e 100644
--- a/document_parser.go
+++ b/document_parser.go
@@ -1292,6 +1292,7 @@ func (docp *documentParser) parseListUnordered(parent, el *element, line []byte,
kind: elKindListUnordered,
rawTitle: el.rawTitle,
}
+ elAttr = &elementAttribute{}
listItem *element
parentListItem *element
@@ -1382,6 +1383,12 @@ func (docp *documentParser) parseListUnordered(parent, el *element, line []byte,
el = &element{
kind: elKindListUnorderedItem,
}
+ if len(elAttr.rawStyle) > 0 {
+ el.addRole(el.rawStyle)
+ el.rawStyle = elAttr.rawStyle
+ elAttr = &elementAttribute{}
+ }
+
el.parseListUnorderedItem(line)
if listItem.level == el.level {
list.addChild(el)
@@ -1402,10 +1409,8 @@ func (docp *documentParser) parseListUnordered(parent, el *element, line []byte,
// *** Next list
parentListItem = parent
for parentListItem != nil {
- if parentListItem.kind == docp.kind &&
- parentListItem.level == el.level {
- list.postParseList(docp.doc,
- elKindListUnorderedItem)
+ if parentListItem.kind == docp.kind && parentListItem.level == el.level {
+ list.postParseList(docp.doc, elKindListUnorderedItem)
return line
}
parentListItem = parentListItem.parent
@@ -1508,7 +1513,6 @@ func (docp *documentParser) parseListUnordered(parent, el *element, line []byte,
docp.kind == elKindSectionL4 ||
docp.kind == elKindSectionL5 ||
docp.kind == lineKindAdmonition ||
- docp.kind == lineKindAttributeElement ||
docp.kind == lineKindBlockTitle ||
docp.kind == lineKindID ||
docp.kind == lineKindIDShort ||
@@ -1517,6 +1521,18 @@ func (docp *documentParser) parseListUnordered(parent, el *element, line []byte,
break
}
}
+ if docp.kind == lineKindAttributeElement {
+ if docp.prevKind == lineKindEmpty {
+ break
+ }
+ // Case:
+ // * item 1
+ // [circle] <-- we are here.
+ // ** item 2
+ elAttr.parseElementAttribute(line)
+ line = nil
+ continue
+ }
listItem.Write(bytes.TrimSpace(line))
listItem.WriteByte('\n')
diff --git a/parser.go b/parser.go
index 7b95773..b497384 100644
--- a/parser.go
+++ b/parser.go
@@ -256,6 +256,11 @@ const (
styleSectionGlossary
styleSectionBibliography
styleSectionIndex
+ styleListMarkerCircle
+ styleListMarkerDisc
+ styleListMarkerNone
+ styleListMarkerSquare
+ styleListMarkerUnstyled
styleParagraphLead
styleParagraphNormal
styleLink
@@ -298,6 +303,11 @@ var adocStyles map[string]int64 = map[string]int64{
`glossary`: styleSectionGlossary,
`bibliography`: styleSectionBibliography,
`index`: styleSectionIndex,
+ `circle`: styleListMarkerCircle,
+ `disc`: styleListMarkerDisc,
+ `none`: styleListMarkerNone,
+ `square`: styleListMarkerSquare,
+ `unstyled`: styleListMarkerUnstyled,
`.lead`: styleParagraphLead,
`.normal`: styleParagraphNormal,
`arabic`: styleNumberingArabic,
diff --git a/testdata/list_unordered_test.txt b/testdata/list_unordered_test.txt
index 01c62a8..6e9b627 100644
--- a/testdata/list_unordered_test.txt
+++ b/testdata/list_unordered_test.txt
@@ -155,3 +155,157 @@ a quote
</li>
</ul>
</div>
+
+>>> with_title
+
+.Possible DefOps manual locations
+* West wood maze
+** Maze heart
+*** Reflection pool
+** Secret exit
+* Untracked file in git repository
+
+<<< with_title
+
+<div class="ulist">
+<div class="title">Possible DefOps manual locations</div>
+<ul>
+<li>
+<p>West wood maze</p>
+<div class="ulist">
+<ul>
+<li>
+<p>Maze heart</p>
+<div class="ulist">
+<ul>
+<li>
+<p>Reflection pool</p>
+</li>
+</ul>
+</div>
+</li>
+<li>
+<p>Secret exit</p>
+</li>
+</ul>
+</div>
+</li>
+<li>
+<p>Untracked file in git repository</p>
+</li>
+</ul>
+</div>
+
+>>> with_square_marker
+
+[square]
+* one
+* two
+* three
+
+<<< with_square_marker
+
+<div class="ulist square">
+<ul class="square">
+<li>
+<p>one</p>
+</li>
+<li>
+<p>two</p>
+</li>
+<li>
+<p>three</p>
+</li>
+</ul>
+</div>
+
+>>> with_circle_marker
+
+[circle]
+* circles
+** all
+*** the
+**** way
+***** down
+
+<<< with_circle_marker
+
+<div class="ulist circle">
+<ul class="circle">
+<li>
+<p>circles</p>
+<div class="ulist">
+<ul>
+<li>
+<p>all</p>
+<div class="ulist">
+<ul>
+<li>
+<p>the</p>
+<div class="ulist">
+<ul>
+<li>
+<p>way</p>
+<div class="ulist">
+<ul>
+<li>
+<p>down</p>
+</li>
+</ul>
+</div>
+</li>
+</ul>
+</div>
+</li>
+</ul>
+</div>
+</li>
+</ul>
+</div>
+</li>
+</ul>
+</div>
+
+>>> with_mixed_marker
+
+[square]
+* square l1
+** square l2
+[circle]
+*** circle l3
+**** circle l4
+* circle l1
+
+<<< with_mixed_marker
+
+<div class="ulist square">
+<ul class="square">
+<li>
+<p>square l1</p>
+<div class="ulist">
+<ul>
+<li>
+<p>square l2</p>
+<div class="ulist circle">
+<ul class="circle">
+<li>
+<p>circle l3</p>
+<div class="ulist">
+<ul>
+<li>
+<p>circle l4</p>
+</li>
+</ul>
+</div>
+</li>
+</ul>
+</div>
+</li>
+</ul>
+</div>
+</li>
+<li>
+<p>circle l1</p>
+</li>
+</ul>
+</div>
diff --git a/testdata/test.adoc b/testdata/test.adoc
index 869d720..ee99271 100644
--- a/testdata/test.adoc
+++ b/testdata/test.adoc
@@ -429,8 +429,11 @@ This line separated by comment.
* square two
[circle]
-* circle one
-* circle two
+* circles
+** all
+*** the
+**** way
+***** down
[disc]
* disc one
@@ -452,6 +455,17 @@ This line separated by comment.
* what one
* what two
+With mixed marker,
+
+[square]
+* square l1
+** square l2
+[circle]
+*** circle l3
+**** circle l4
+* circle l1
+
+
=== Checklist
* [*] checked
diff --git a/testdata/test.exp.html b/testdata/test.exp.html
index ba0aa6f..b057ec1 100644
--- a/testdata/test.exp.html
+++ b/testdata/test.exp.html
@@ -972,10 +972,35 @@ This line separated by comment.</p>
<div class="ulist circle">
<ul class="circle">
<li>
-<p>circle one</p>
-</li>
+<p>circles</p>
+<div class="ulist">
+<ul>
<li>
-<p>circle two</p>
+<p>all</p>
+<div class="ulist">
+<ul>
+<li>
+<p>the</p>
+<div class="ulist">
+<ul>
+<li>
+<p>way</p>
+<div class="ulist">
+<ul>
+<li>
+<p>down</p>
+</li>
+</ul>
+</div>
+</li>
+</ul>
+</div>
+</li>
+</ul>
+</div>
+</li>
+</ul>
+</div>
</li>
</ul>
</div>
@@ -1029,6 +1054,40 @@ This line separated by comment.</p>
</li>
</ul>
</div>
+<div class="paragraph">
+<p>With mixed marker,</p>
+</div>
+<div class="ulist square">
+<ul class="square">
+<li>
+<p>square l1</p>
+<div class="ulist">
+<ul>
+<li>
+<p>square l2</p>
+<div class="ulist circle">
+<ul class="circle">
+<li>
+<p>circle l3</p>
+<div class="ulist">
+<ul>
+<li>
+<p>circle l4</p>
+</li>
+</ul>
+</div>
+</li>
+</ul>
+</div>
+</li>
+</ul>
+</div>
+</li>
+<li>
+<p>circle l1</p>
+</li>
+</ul>
+</div>
</div>
<div class="sect2">
<h3 id="checklist"><a class="anchor" href="#checklist"></a><a class="link" href="#checklist">15.2. Checklist</a></h3>
@@ -2995,7 +3054,7 @@ this sidebar.</p>
<div id="footer">
<div id="footer-text">
1.1.1<br>
-Last updated 2023-05-28 15:37:46 +0700
+Last updated 2023-05-30 01:01:33 +0700
</div>
</div>
</body>
diff --git a/testdata/test.got.html b/testdata/test.got.html
index aba6b1f..0d72804 100644
--- a/testdata/test.got.html
+++ b/testdata/test.got.html
@@ -970,10 +970,35 @@ This line separated by comment.</p>
<div class="ulist circle">
<ul class="circle">
<li>
-<p>circle one</p>
-</li>
+<p>circles</p>
+<div class="ulist">
+<ul>
<li>
-<p>circle two</p>
+<p>all</p>
+<div class="ulist">
+<ul>
+<li>
+<p>the</p>
+<div class="ulist">
+<ul>
+<li>
+<p>way</p>
+<div class="ulist">
+<ul>
+<li>
+<p>down</p>
+</li>
+</ul>
+</div>
+</li>
+</ul>
+</div>
+</li>
+</ul>
+</div>
+</li>
+</ul>
+</div>
</li>
</ul>
</div>
@@ -1027,6 +1052,40 @@ This line separated by comment.</p>
</li>
</ul>
</div>
+<div class="paragraph">
+<p>With mixed marker,</p>
+</div>
+<div class="ulist square">
+<ul class="square">
+<li>
+<p>square l1</p>
+<div class="ulist">
+<ul>
+<li>
+<p>square l2</p>
+<div class="ulist circle">
+<ul class="circle">
+<li>
+<p>circle l3</p>
+<div class="ulist">
+<ul>
+<li>
+<p>circle l4</p>
+</li>
+</ul>
+</div>
+</li>
+</ul>
+</div>
+</li>
+</ul>
+</div>
+</li>
+<li>
+<p>circle l1</p>
+</li>
+</ul>
+</div>
</div>
<div class="sect2">
<h3 id="checklist"><a class="anchor" href="#checklist"></a><a class="link" href="#checklist">15.2. Checklist</a></h3>
@@ -2997,7 +3056,7 @@ this sidebar.</p>
<div id="footer">
<div id="footer-text">
1.1.1<br>
-Last updated 2023-05-28 15:37:46 +0700
+Last updated 2023-05-30 01:01:33 +0700
</div>
</div>
</body>