Skip to content

Commit df6dd00

Browse files
committed
fix: logseq accepts attributes with leading spaces, we have to trim them
1 parent a48b7ef commit df6dd00

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

parse.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ var dateLinkRegexp = regexp.MustCompile(`^\s*\[\[([^]]+?)]]\s*$`)
7676

7777
func parseAttributes(rawContent string) map[string]string {
7878
result := attrAndContentRegexp.FindStringSubmatch(rawContent)
79-
attrArray := regexp.MustCompile(`(?m:^(.*?)::\s*(.*)$)`).FindAllStringSubmatch(result[1], -1)
79+
attrArray := regexp.MustCompile(`(?m:^\s*(.*?)::\s*(.*?)$)`).FindAllStringSubmatch(result[1], -1)
8080
attributes := map[string]string{}
8181
for _, attrStrings := range attrArray {
8282
attributes[attrStrings[1]] = attrStrings[2]
@@ -103,7 +103,7 @@ func firstBulletPointsToParagraphs(from string) string {
103103
return regexp.MustCompile(`(?m:^- )`).ReplaceAllString(from, "\n")
104104
}
105105

106-
func unindentAllRemainingBulletPoints(from string) string {
106+
func removeTabFromMultiLevelBulletPoints(from string) string {
107107
return regexp.MustCompile(`(?m:^\t{1,}[^\t])`).ReplaceAllStringFunc(from, func(s string) string {
108108
return s[1:]
109109
})
@@ -150,8 +150,7 @@ func parseContent(rawContent string) parsedContent {
150150
firstBulletPointsToParagraphs,
151151
// since we turned the first bullet points to paragraphs
152152
// we shift all bullet points by one tab to the left
153-
// including subsequent lines for multiline strings
154-
unindentAllRemainingBulletPoints,
153+
removeTabFromMultiLevelBulletPoints,
155154
)
156155
return parsedContent{
157156
attributes: parseAttributes(rawContent),

parse_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ func TestParseContent(t *testing.T) {
136136
require.Equal(t, "true", result.attributes["public"])
137137
})
138138

139+
t.Run("trims attribute names and values", func(t *testing.T) {
140+
result := parseContent(" public:: true\n")
141+
require.Equal(t, "", result.content)
142+
require.Equal(t, "true", result.attributes["public"])
143+
})
144+
139145
t.Run("parses page with one line", func(t *testing.T) {
140146
result := parseContent("- a\n")
141147
require.Equal(t, "\na\n", result.content)

0 commit comments

Comments
 (0)