From 4e0507b62393b8461b29cda7565f685d79b58ca3 Mon Sep 17 00:00:00 2001
From: Shulhan
Date: Tue, 30 May 2023 22:12:40 +0700
Subject: 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 ``.
---
README.md | 15 ++--
document_parser.go | 26 +++++--
parser.go | 10 +++
testdata/list_unordered_test.txt | 154 +++++++++++++++++++++++++++++++++++++++
testdata/test.adoc | 18 ++++-
testdata/test.exp.html | 67 ++++++++++++++++-
testdata/test.got.html | 67 ++++++++++++++++-
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
+
+>>> with_title
+
+.Possible DefOps manual locations
+* West wood maze
+** Maze heart
+*** Reflection pool
+** Secret exit
+* Untracked file in git repository
+
+<<< with_title
+
+
+
Possible DefOps manual locations
+
+
+
+>>> with_square_marker
+
+[square]
+* one
+* two
+* three
+
+<<< with_square_marker
+
+
+
+-
+
one
+
+-
+
two
+
+-
+
three
+
+
+
+
+>>> with_circle_marker
+
+[circle]
+* circles
+** all
+*** the
+**** way
+***** down
+
+<<< with_circle_marker
+
+
+
+>>> with_mixed_marker
+
+[square]
+* square l1
+** square l2
+[circle]
+*** circle l3
+**** circle l4
+* circle l1
+
+<<< with_mixed_marker
+
+
+
+-
+
square l1
+
+
+-
+
circle l1
+
+
+
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.
@@ -1029,6 +1054,40 @@ This line separated by comment.
+
+
+
+-
+
square l1
+
+
+-
+
circle l1
+
+
+
@@ -2995,7 +3054,7 @@ this sidebar.