2021-01-16 18:37:10 +00:00
|
|
|
package markdown
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-04-14 18:14:01 +00:00
|
|
|
"github.com/mickael-menu/zk/internal/core"
|
|
|
|
"github.com/mickael-menu/zk/internal/util/opt"
|
|
|
|
"github.com/mickael-menu/zk/internal/util/test/assert"
|
2021-01-16 18:37:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestParseTitle(t *testing.T) {
|
|
|
|
test := func(source string, expectedTitle string) {
|
|
|
|
content := parse(t, source)
|
|
|
|
assert.Equal(t, content.Title, opt.NewNotEmptyString(expectedTitle))
|
|
|
|
}
|
|
|
|
|
|
|
|
test("", "")
|
|
|
|
test("# ", "")
|
|
|
|
test("#A title", "")
|
|
|
|
test(" # A title", "A title")
|
|
|
|
test("# A title", "A title")
|
|
|
|
test("# A title ", "A title")
|
|
|
|
test("## A title", "A title")
|
|
|
|
test("Paragraph \n\n## A title\nBody", "A title")
|
|
|
|
test("# Heading 1\n## Heading 1.a\n# Heading 2", "Heading 1")
|
|
|
|
test("## Small Heading\n# Bigger Heading", "Bigger Heading")
|
|
|
|
test("# A **title** with [formatting](http://stripped)", "A title with formatting")
|
2021-01-24 12:42:57 +00:00
|
|
|
|
|
|
|
// From a YAML frontmatter
|
|
|
|
test(`---
|
|
|
|
Title: A title
|
|
|
|
Tags:
|
|
|
|
- tag1
|
|
|
|
- tag2
|
|
|
|
---
|
|
|
|
|
|
|
|
# Heading
|
|
|
|
`, "A title")
|
|
|
|
test(`---
|
|
|
|
title: lowercase key
|
|
|
|
---
|
|
|
|
Paragraph
|
|
|
|
`, "lowercase key")
|
2021-01-16 18:37:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseBody(t *testing.T) {
|
|
|
|
test := func(source string, expectedBody string) {
|
|
|
|
content := parse(t, source)
|
|
|
|
assert.Equal(t, content.Body, opt.NewNotEmptyString(expectedBody))
|
|
|
|
}
|
|
|
|
|
|
|
|
test("", "")
|
|
|
|
test("# A title\n \n", "")
|
|
|
|
test("Paragraph \n\n# A title", "")
|
|
|
|
test("Paragraph \n\n# A title\nBody", "Body")
|
|
|
|
|
|
|
|
test(
|
|
|
|
`## Small Heading
|
|
|
|
# Bigger Heading
|
|
|
|
|
|
|
|
## Smaller Heading
|
|
|
|
Body
|
|
|
|
several lines
|
|
|
|
# Body heading
|
|
|
|
|
|
|
|
Paragraph:
|
|
|
|
|
|
|
|
* item1
|
|
|
|
* item2
|
|
|
|
|
|
|
|
`,
|
|
|
|
`## Smaller Heading
|
|
|
|
Body
|
|
|
|
several lines
|
|
|
|
# Body heading
|
|
|
|
|
|
|
|
Paragraph:
|
|
|
|
|
|
|
|
* item1
|
|
|
|
* item2`,
|
|
|
|
)
|
2021-01-24 12:42:57 +00:00
|
|
|
test(`---
|
|
|
|
title: A title
|
|
|
|
---
|
|
|
|
|
|
|
|
Paragraph
|
|
|
|
`, "Paragraph")
|
2021-01-16 18:37:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseLead(t *testing.T) {
|
|
|
|
test := func(source string, expectedLead string) {
|
|
|
|
content := parse(t, source)
|
|
|
|
assert.Equal(t, content.Lead, opt.NewNotEmptyString(expectedLead))
|
|
|
|
}
|
|
|
|
|
|
|
|
test("", "")
|
|
|
|
test("# A title\n \n", "")
|
|
|
|
|
|
|
|
test(
|
|
|
|
`Paragraph
|
|
|
|
# A title`,
|
|
|
|
"",
|
|
|
|
)
|
|
|
|
|
|
|
|
test(
|
|
|
|
`Paragraph
|
|
|
|
# A title
|
|
|
|
Lead`,
|
|
|
|
"Lead",
|
|
|
|
)
|
|
|
|
|
|
|
|
test(
|
|
|
|
`# A title
|
|
|
|
Lead
|
|
|
|
multiline
|
|
|
|
|
|
|
|
other`,
|
|
|
|
"Lead\nmultiline",
|
|
|
|
)
|
|
|
|
|
|
|
|
test(
|
|
|
|
`# A title
|
|
|
|
|
|
|
|
Lead
|
|
|
|
multiline
|
|
|
|
|
|
|
|
## Heading`,
|
|
|
|
"Lead\nmultiline",
|
|
|
|
)
|
|
|
|
|
|
|
|
test(
|
|
|
|
`# A title
|
|
|
|
|
|
|
|
## Heading
|
|
|
|
Lead
|
|
|
|
multiline
|
|
|
|
|
|
|
|
other`,
|
|
|
|
`## Heading
|
|
|
|
Lead
|
|
|
|
multiline`,
|
|
|
|
)
|
|
|
|
|
|
|
|
test(
|
|
|
|
`# A title
|
|
|
|
|
|
|
|
* item1
|
|
|
|
* item2
|
|
|
|
|
|
|
|
Paragraph`,
|
|
|
|
`* item1
|
|
|
|
* item2`,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-03-06 18:38:52 +00:00
|
|
|
func TestParseHashtags(t *testing.T) {
|
|
|
|
test := func(source string, tags []string) {
|
|
|
|
content := parseWithOptions(t, source, ParserOpts{
|
|
|
|
HashtagEnabled: true,
|
|
|
|
MultiWordTagEnabled: false,
|
|
|
|
})
|
|
|
|
assert.Equal(t, content.Tags, tags)
|
|
|
|
}
|
|
|
|
|
|
|
|
test("", []string{})
|
|
|
|
test("#", []string{})
|
|
|
|
test("##", []string{})
|
|
|
|
test("# No tags around here", []string{})
|
|
|
|
test("#single-hashtag", []string{"single-hashtag"})
|
|
|
|
test("a #tag in the middle", []string{"tag"})
|
|
|
|
test("#multiple #hashtags", []string{"multiple", "hashtags"})
|
|
|
|
test("#multiple#hashtags", []string{})
|
|
|
|
// Unicode hashtags
|
|
|
|
test("#libellé-français, #日本語ハッシュタグ", []string{"libellé-français", "日本語ハッシュタグ"})
|
|
|
|
// Punctuation breaking tags
|
|
|
|
test(
|
|
|
|
"#a #b, #c; #d. #e! #f? #g* #h\", #i(, #j), #k[, #l], #m{, #n}",
|
|
|
|
[]string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n"},
|
|
|
|
)
|
|
|
|
// Authorized special characters
|
|
|
|
test("#a/@'~-_$%&+=: end", []string{"a/@'~-_$%&+=:"})
|
|
|
|
// Escape punctuation and space
|
|
|
|
test(`#an\ \\espaced\ tag\!`, []string{`an \espaced tag!`})
|
|
|
|
// Hashtags containing only numbers and dots are invalid
|
|
|
|
test("#123, #1.2.3", []string{})
|
|
|
|
// Must not be preceded by a hash or any other valid hashtag character
|
|
|
|
test("##invalid also#invalid", []string{})
|
|
|
|
// Bear's multi multi-word tags are disabled
|
|
|
|
test("#multi word# end", []string{"multi"})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseWordtags(t *testing.T) {
|
|
|
|
test := func(source string, tags []string) {
|
|
|
|
content := parseWithOptions(t, source, ParserOpts{
|
|
|
|
HashtagEnabled: true,
|
|
|
|
MultiWordTagEnabled: true,
|
|
|
|
})
|
|
|
|
assert.Equal(t, content.Tags, tags)
|
|
|
|
}
|
|
|
|
|
|
|
|
test("", []string{})
|
|
|
|
test("#", []string{})
|
|
|
|
test("##", []string{})
|
|
|
|
test("# No tags around here", []string{})
|
|
|
|
test("#single-hashtag", []string{"single-hashtag"})
|
|
|
|
test("a #tag in the middle", []string{"tag"})
|
|
|
|
test("#multiple #hashtags", []string{"multiple", "hashtags"})
|
|
|
|
test("#multiple#hashtags", []string{"multiple"})
|
|
|
|
// Unicode hashtags
|
|
|
|
test("#libellé-français, #日本語ハッシュタグ", []string{"libellé-français", "日本語ハッシュタグ"})
|
|
|
|
// Punctuation breaking tags
|
|
|
|
test(
|
|
|
|
"#a #b, #c; #d. #e! #f? #g* #h\", #i(, #j), #k[, #l], #m{, #n}",
|
|
|
|
[]string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n"},
|
|
|
|
)
|
|
|
|
// Authorized special characters
|
|
|
|
test("#a/@'~-_$%&+=: end", []string{"a/@'~-_$%&+=:"})
|
|
|
|
// Escape punctuation and space
|
|
|
|
test(`#an\ \\espaced\ tag\!`, []string{`an \espaced tag!`})
|
2021-03-07 16:00:09 +00:00
|
|
|
// Leading and trailing spaces are trimmed
|
|
|
|
test(`#\ \ tag\ \ end`, []string{`tag`})
|
2021-03-06 18:38:52 +00:00
|
|
|
// Hashtags containing only numbers and dots are invalid
|
|
|
|
test("#123, #1.2.3", []string{})
|
|
|
|
// Must not be preceded by a hash or any other valid hashtag character
|
|
|
|
test("##invalid also#invalid", []string{})
|
|
|
|
// Bear's multi multi-word tags
|
|
|
|
test("#multi word#", []string{"multi word"})
|
|
|
|
test("#surrounded# end", []string{"surrounded"})
|
|
|
|
test("#multi word#end", []string{"multi word"})
|
|
|
|
test("#multi word #other", []string{"multi", "other"})
|
|
|
|
test("#multi word# #other", []string{"multi word", "other"})
|
|
|
|
test("#multi word##other", []string{"multi word"})
|
|
|
|
test("a #multi word# in the middle", []string{"multi word"})
|
|
|
|
test("a #multi word#, and a #tag", []string{"multi word", "tag"})
|
|
|
|
test("#multi, word#", []string{"multi"})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseColontags(t *testing.T) {
|
|
|
|
test := func(source string, tags []string) {
|
|
|
|
content := parseWithOptions(t, source, ParserOpts{
|
|
|
|
ColontagEnabled: true,
|
|
|
|
})
|
|
|
|
assert.Equal(t, content.Tags, tags)
|
|
|
|
}
|
|
|
|
|
|
|
|
test("", []string{})
|
|
|
|
test(":", []string{})
|
|
|
|
test("::", []string{})
|
|
|
|
test("not:valid:", []string{})
|
|
|
|
test(":no tags:", []string{})
|
|
|
|
test(": no-tags:", []string{})
|
|
|
|
test(":no-tags :", []string{})
|
|
|
|
test(":single-colontag:", []string{"single-colontag"})
|
|
|
|
test("a :tag: in the middle", []string{"tag"})
|
|
|
|
test(":multiple:colontags:", []string{"multiple", "colontags"})
|
|
|
|
test(":multiple::colontags:", []string{"multiple"})
|
|
|
|
test(":multiple: :colontags:", []string{"multiple", "colontags"})
|
|
|
|
test(":multiple:,:colontags:", []string{"multiple", "colontags"})
|
|
|
|
test(":more:than:two:colontags:", []string{"more", "than", "two", "colontags"})
|
|
|
|
test(":multiple :colontags", []string{})
|
|
|
|
test(":multiple :colontags:", []string{"colontags"})
|
|
|
|
// Unicode colontags
|
|
|
|
test(":libellé-français:日本語ハッシュタグ:", []string{"libellé-français", "日本語ハッシュタグ"})
|
|
|
|
// Punctuation is not allowed
|
|
|
|
test(":a : :b,: :c;: :d.: :e!: :f?: :g*: :h\": :i(: :j): :k[: :l]: :m{: :n}:", []string{})
|
|
|
|
// Authorized special characters
|
|
|
|
test(":#a/@'~-_$%&+=: end", []string{"#a/@'~-_$%&+="})
|
|
|
|
// Escape punctuation and space
|
|
|
|
test(`:an\ \\espaced\ tag\!:`, []string{`an \espaced tag!`})
|
2021-03-07 16:00:09 +00:00
|
|
|
// Leading and trailing spaces are trimmed
|
|
|
|
test(`:\ \ tag\ \ :`, []string{`tag`})
|
2021-03-06 18:38:52 +00:00
|
|
|
// A colontag containing only numbers is valid
|
|
|
|
test(":123:1.2.3:", []string{"123"})
|
|
|
|
// Must not be preceded by a : or any other valid colontag character
|
|
|
|
test("::invalid also:invalid:", []string{})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseMixedTags(t *testing.T) {
|
|
|
|
test := func(source string, tags []string) {
|
|
|
|
content := parseWithOptions(t, source, ParserOpts{
|
|
|
|
HashtagEnabled: true,
|
|
|
|
MultiWordTagEnabled: true,
|
|
|
|
ColontagEnabled: true,
|
|
|
|
})
|
|
|
|
assert.Equal(t, content.Tags, tags)
|
|
|
|
}
|
|
|
|
|
|
|
|
test(":colontag: #tag #word tag#", []string{"colontag", "tag", "word tag"})
|
|
|
|
test(":#colontag: #:tag: #:word:tag:#", []string{"#colontag", ":tag:", ":word:tag:"})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseTagsFromFrontmatter(t *testing.T) {
|
|
|
|
test := func(source string, tags []string) {
|
|
|
|
content := parse(t, source)
|
|
|
|
assert.Equal(t, content.Tags, tags)
|
|
|
|
}
|
|
|
|
|
|
|
|
test(`---
|
|
|
|
Tags:
|
|
|
|
- "#tag1"
|
|
|
|
- tag 2
|
|
|
|
---
|
|
|
|
|
|
|
|
Body
|
|
|
|
`, []string{"tag1", "tag 2"})
|
|
|
|
|
|
|
|
test(`---
|
|
|
|
Keywords: [keyword1, "#keyword 2"]
|
|
|
|
---
|
|
|
|
|
|
|
|
Body
|
|
|
|
`, []string{"keyword1", "keyword 2"})
|
|
|
|
|
|
|
|
test(`---
|
2021-03-07 16:00:09 +00:00
|
|
|
tags: [tag1, " tag 2 "]
|
2021-03-06 18:38:52 +00:00
|
|
|
keywords:
|
2021-03-07 16:00:09 +00:00
|
|
|
- keyword1
|
2021-03-06 18:38:52 +00:00
|
|
|
- keyword 2
|
|
|
|
---
|
|
|
|
|
|
|
|
Body
|
|
|
|
`, []string{"tag1", "tag 2", "keyword1", "keyword 2"})
|
|
|
|
|
|
|
|
// When a string, parse space-separated tags.
|
|
|
|
test(`---
|
2021-03-07 16:00:09 +00:00
|
|
|
Tags: "tag1 #tag-2"
|
2021-03-06 18:38:52 +00:00
|
|
|
Keywords: kw1 kw2 kw3
|
|
|
|
---
|
|
|
|
|
|
|
|
Body
|
|
|
|
`, []string{"tag1", "tag-2", "kw1", "kw2", "kw3"})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseTagsIgnoresDuplicates(t *testing.T) {
|
|
|
|
test := func(source string, tags []string) {
|
|
|
|
content := parse(t, source)
|
|
|
|
assert.Equal(t, content.Tags, tags)
|
|
|
|
}
|
|
|
|
|
|
|
|
test(`---
|
|
|
|
Tags: [tag1, "#tag1", tag2]
|
|
|
|
---
|
|
|
|
|
|
|
|
#tag1 #tag2 #tag3 #tag3 :tag2:
|
|
|
|
`, []string{"tag1", "tag2", "tag3"})
|
|
|
|
}
|
|
|
|
|
2021-01-24 13:33:25 +00:00
|
|
|
func TestParseLinks(t *testing.T) {
|
2021-04-14 18:14:01 +00:00
|
|
|
test := func(source string, links []core.Link) {
|
2021-01-24 13:33:25 +00:00
|
|
|
content := parse(t, source)
|
|
|
|
assert.Equal(t, content.Links, links)
|
|
|
|
}
|
|
|
|
|
2021-04-14 18:14:01 +00:00
|
|
|
test("", []core.Link{})
|
|
|
|
test("No links around here", []core.Link{})
|
2021-01-24 13:33:25 +00:00
|
|
|
|
|
|
|
test(`
|
|
|
|
# Heading with a [link](heading)
|
|
|
|
|
2021-01-25 20:44:44 +00:00
|
|
|
Paragraph containing [multiple **links**](stripped-formatting), here's one [relative](../other).
|
2021-01-24 13:33:25 +00:00
|
|
|
A link can have [one relation](one "rel-1") or [several relations](several "rel-1 rel-2").
|
2021-01-25 20:44:44 +00:00
|
|
|
|
2021-02-12 18:34:04 +00:00
|
|
|
An https://inline-link.com and http://another-inline-link.com.
|
|
|
|
|
2021-02-28 10:21:33 +00:00
|
|
|
A [[Wiki link]] is surrounded by [[2-brackets | two brackets]].
|
|
|
|
|
2021-06-23 19:57:16 +00:00
|
|
|
[[lien accentué]]
|
|
|
|
|
2021-02-28 10:21:33 +00:00
|
|
|
It can contain [[esca]\]ped \[chara\\cters]].
|
2021-02-13 10:00:31 +00:00
|
|
|
|
|
|
|
A [[[Folgezettel link]]] is surrounded by three brackets.
|
|
|
|
|
|
|
|
Neuron also supports a [[trailing hash]]# for Folgezettel links.
|
|
|
|
|
|
|
|
A #[[leading hash]] is used for #uplinks.
|
|
|
|
|
2021-02-28 10:21:33 +00:00
|
|
|
Neuron links with titles: [[trailing|Trailing link]]# #[[leading | Leading link]]
|
|
|
|
|
2021-01-25 20:44:44 +00:00
|
|
|
[External links](http://example.com) are marked [as such](ftp://domain).
|
2021-04-14 18:14:01 +00:00
|
|
|
`, []core.Link{
|
2021-01-24 13:33:25 +00:00
|
|
|
{
|
2021-03-08 20:38:32 +00:00
|
|
|
Title: "link",
|
|
|
|
Href: "heading",
|
2021-04-14 18:14:01 +00:00
|
|
|
Rels: []core.LinkRelation{},
|
|
|
|
IsExternal: false,
|
2021-03-08 20:38:32 +00:00
|
|
|
Snippet: "Heading with a [link](heading)",
|
|
|
|
SnippetStart: 3,
|
|
|
|
SnippetEnd: 33,
|
2021-01-25 20:44:44 +00:00
|
|
|
},
|
|
|
|
{
|
2021-04-14 18:14:01 +00:00
|
|
|
Title: "multiple links",
|
|
|
|
Href: "stripped-formatting",
|
|
|
|
Rels: []core.LinkRelation{},
|
|
|
|
IsExternal: false,
|
2021-01-30 15:32:58 +00:00
|
|
|
Snippet: `Paragraph containing [multiple **links**](stripped-formatting), here's one [relative](../other).
|
|
|
|
A link can have [one relation](one "rel-1") or [several relations](several "rel-1 rel-2").`,
|
2021-03-08 20:38:32 +00:00
|
|
|
SnippetStart: 35,
|
|
|
|
SnippetEnd: 222,
|
2021-01-24 13:33:25 +00:00
|
|
|
},
|
|
|
|
{
|
2021-04-14 18:14:01 +00:00
|
|
|
Title: "relative",
|
|
|
|
Href: "../other",
|
|
|
|
Rels: []core.LinkRelation{},
|
|
|
|
IsExternal: false,
|
2021-01-30 15:32:58 +00:00
|
|
|
Snippet: `Paragraph containing [multiple **links**](stripped-formatting), here's one [relative](../other).
|
|
|
|
A link can have [one relation](one "rel-1") or [several relations](several "rel-1 rel-2").`,
|
2021-03-08 20:38:32 +00:00
|
|
|
SnippetStart: 35,
|
|
|
|
SnippetEnd: 222,
|
2021-01-24 13:33:25 +00:00
|
|
|
},
|
|
|
|
{
|
2021-04-14 18:14:01 +00:00
|
|
|
Title: "one relation",
|
|
|
|
Href: "one",
|
|
|
|
Rels: core.LinkRels("rel-1"),
|
|
|
|
IsExternal: false,
|
2021-01-30 15:32:58 +00:00
|
|
|
Snippet: `Paragraph containing [multiple **links**](stripped-formatting), here's one [relative](../other).
|
|
|
|
A link can have [one relation](one "rel-1") or [several relations](several "rel-1 rel-2").`,
|
2021-03-08 20:38:32 +00:00
|
|
|
SnippetStart: 35,
|
|
|
|
SnippetEnd: 222,
|
2021-01-24 13:33:25 +00:00
|
|
|
},
|
|
|
|
{
|
2021-04-14 18:14:01 +00:00
|
|
|
Title: "several relations",
|
|
|
|
Href: "several",
|
|
|
|
Rels: core.LinkRels("rel-1", "rel-2"),
|
|
|
|
IsExternal: false,
|
2021-01-30 15:32:58 +00:00
|
|
|
Snippet: `Paragraph containing [multiple **links**](stripped-formatting), here's one [relative](../other).
|
|
|
|
A link can have [one relation](one "rel-1") or [several relations](several "rel-1 rel-2").`,
|
2021-03-08 20:38:32 +00:00
|
|
|
SnippetStart: 35,
|
|
|
|
SnippetEnd: 222,
|
2021-01-24 13:33:25 +00:00
|
|
|
},
|
2021-02-12 18:34:04 +00:00
|
|
|
{
|
2021-03-08 20:38:32 +00:00
|
|
|
Title: "https://inline-link.com",
|
|
|
|
Href: "https://inline-link.com",
|
2021-04-14 18:14:01 +00:00
|
|
|
IsExternal: true,
|
|
|
|
Rels: []core.LinkRelation{},
|
2021-03-08 20:38:32 +00:00
|
|
|
Snippet: "An https://inline-link.com and http://another-inline-link.com.",
|
|
|
|
SnippetStart: 224,
|
|
|
|
SnippetEnd: 286,
|
2021-02-12 18:34:04 +00:00
|
|
|
},
|
|
|
|
{
|
2021-03-08 20:38:32 +00:00
|
|
|
Title: "http://another-inline-link.com",
|
|
|
|
Href: "http://another-inline-link.com",
|
2021-04-14 18:14:01 +00:00
|
|
|
IsExternal: true,
|
|
|
|
Rels: []core.LinkRelation{},
|
2021-03-08 20:38:32 +00:00
|
|
|
Snippet: "An https://inline-link.com and http://another-inline-link.com.",
|
|
|
|
SnippetStart: 224,
|
|
|
|
SnippetEnd: 286,
|
2021-02-12 18:34:04 +00:00
|
|
|
},
|
2021-02-13 10:00:31 +00:00
|
|
|
{
|
2021-03-08 20:38:32 +00:00
|
|
|
Title: "Wiki link",
|
|
|
|
Href: "Wiki link",
|
2021-04-14 18:14:01 +00:00
|
|
|
IsExternal: false,
|
|
|
|
Rels: []core.LinkRelation{},
|
2021-03-08 20:38:32 +00:00
|
|
|
Snippet: "A [[Wiki link]] is surrounded by [[2-brackets | two brackets]].",
|
|
|
|
SnippetStart: 288,
|
|
|
|
SnippetEnd: 351,
|
2021-02-28 10:21:33 +00:00
|
|
|
},
|
|
|
|
{
|
2021-03-08 20:38:32 +00:00
|
|
|
Title: "two brackets",
|
|
|
|
Href: "2-brackets",
|
2021-04-14 18:14:01 +00:00
|
|
|
IsExternal: false,
|
|
|
|
Rels: []core.LinkRelation{},
|
2021-03-08 20:38:32 +00:00
|
|
|
Snippet: "A [[Wiki link]] is surrounded by [[2-brackets | two brackets]].",
|
|
|
|
SnippetStart: 288,
|
|
|
|
SnippetEnd: 351,
|
2021-02-28 10:21:33 +00:00
|
|
|
},
|
2021-06-23 19:57:16 +00:00
|
|
|
{
|
|
|
|
Title: "lien accentué",
|
|
|
|
Href: "lien accentué",
|
|
|
|
IsExternal: false,
|
|
|
|
Rels: []core.LinkRelation{},
|
|
|
|
Snippet: "[[lien accentué]]",
|
|
|
|
SnippetStart: 353,
|
|
|
|
SnippetEnd: 371,
|
|
|
|
},
|
2021-02-28 10:21:33 +00:00
|
|
|
{
|
2021-03-08 20:38:32 +00:00
|
|
|
Title: `esca]]ped [chara\cters`,
|
|
|
|
Href: `esca]]ped [chara\cters`,
|
2021-04-14 18:14:01 +00:00
|
|
|
IsExternal: false,
|
|
|
|
Rels: []core.LinkRelation{},
|
2021-03-08 20:38:32 +00:00
|
|
|
Snippet: `It can contain [[esca]\]ped \[chara\\cters]].`,
|
2021-06-23 19:57:16 +00:00
|
|
|
SnippetStart: 373,
|
|
|
|
SnippetEnd: 418,
|
2021-02-13 10:00:31 +00:00
|
|
|
},
|
|
|
|
{
|
2021-03-08 20:38:32 +00:00
|
|
|
Title: "Folgezettel link",
|
|
|
|
Href: "Folgezettel link",
|
2021-04-14 18:14:01 +00:00
|
|
|
IsExternal: false,
|
|
|
|
Rels: core.LinkRels("down"),
|
2021-03-08 20:38:32 +00:00
|
|
|
Snippet: "A [[[Folgezettel link]]] is surrounded by three brackets.",
|
2021-06-23 19:57:16 +00:00
|
|
|
SnippetStart: 420,
|
|
|
|
SnippetEnd: 477,
|
2021-02-13 10:00:31 +00:00
|
|
|
},
|
|
|
|
{
|
2021-03-08 20:38:32 +00:00
|
|
|
Title: "trailing hash",
|
|
|
|
Href: "trailing hash",
|
2021-04-14 18:14:01 +00:00
|
|
|
IsExternal: false,
|
|
|
|
Rels: core.LinkRels("down"),
|
2021-03-08 20:38:32 +00:00
|
|
|
Snippet: "Neuron also supports a [[trailing hash]]# for Folgezettel links.",
|
2021-06-23 19:57:16 +00:00
|
|
|
SnippetStart: 479,
|
|
|
|
SnippetEnd: 543,
|
2021-02-13 10:00:31 +00:00
|
|
|
},
|
|
|
|
{
|
2021-03-08 20:38:32 +00:00
|
|
|
Title: "leading hash",
|
|
|
|
Href: "leading hash",
|
2021-04-14 18:14:01 +00:00
|
|
|
IsExternal: false,
|
|
|
|
Rels: core.LinkRels("up"),
|
2021-03-08 20:38:32 +00:00
|
|
|
Snippet: "A #[[leading hash]] is used for #uplinks.",
|
2021-06-23 19:57:16 +00:00
|
|
|
SnippetStart: 545,
|
|
|
|
SnippetEnd: 586,
|
2021-02-13 10:00:31 +00:00
|
|
|
},
|
2021-02-28 10:21:33 +00:00
|
|
|
{
|
2021-03-08 20:38:32 +00:00
|
|
|
Title: "Trailing link",
|
|
|
|
Href: "trailing",
|
2021-04-14 18:14:01 +00:00
|
|
|
IsExternal: false,
|
|
|
|
Rels: core.LinkRels("down"),
|
2021-03-08 20:38:32 +00:00
|
|
|
Snippet: "Neuron links with titles: [[trailing|Trailing link]]# #[[leading | Leading link]]",
|
2021-06-23 19:57:16 +00:00
|
|
|
SnippetStart: 588,
|
|
|
|
SnippetEnd: 670,
|
2021-02-28 10:21:33 +00:00
|
|
|
},
|
|
|
|
{
|
2021-03-08 20:38:32 +00:00
|
|
|
Title: "Leading link",
|
|
|
|
Href: "leading",
|
2021-04-14 18:14:01 +00:00
|
|
|
IsExternal: false,
|
|
|
|
Rels: core.LinkRels("up"),
|
2021-03-08 20:38:32 +00:00
|
|
|
Snippet: "Neuron links with titles: [[trailing|Trailing link]]# #[[leading | Leading link]]",
|
2021-06-23 19:57:16 +00:00
|
|
|
SnippetStart: 588,
|
|
|
|
SnippetEnd: 670,
|
2021-02-28 10:21:33 +00:00
|
|
|
},
|
2021-01-24 13:33:25 +00:00
|
|
|
{
|
2021-03-08 20:38:32 +00:00
|
|
|
Title: "External links",
|
|
|
|
Href: "http://example.com",
|
2021-04-14 18:14:01 +00:00
|
|
|
Rels: []core.LinkRelation{},
|
|
|
|
IsExternal: true,
|
2021-03-08 20:38:32 +00:00
|
|
|
Snippet: `[External links](http://example.com) are marked [as such](ftp://domain).`,
|
2021-06-23 19:57:16 +00:00
|
|
|
SnippetStart: 672,
|
|
|
|
SnippetEnd: 744,
|
2021-01-24 13:33:25 +00:00
|
|
|
},
|
|
|
|
{
|
2021-03-08 20:38:32 +00:00
|
|
|
Title: "as such",
|
|
|
|
Href: "ftp://domain",
|
2021-04-14 18:14:01 +00:00
|
|
|
Rels: []core.LinkRelation{},
|
|
|
|
IsExternal: true,
|
2021-03-08 20:38:32 +00:00
|
|
|
Snippet: `[External links](http://example.com) are marked [as such](ftp://domain).`,
|
2021-06-23 19:57:16 +00:00
|
|
|
SnippetStart: 672,
|
|
|
|
SnippetEnd: 744,
|
2021-01-24 13:33:25 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-03-08 20:38:32 +00:00
|
|
|
func TestParseMetadataFromFrontmatter(t *testing.T) {
|
|
|
|
test := func(source string, expectedMetadata map[string]interface{}) {
|
|
|
|
content := parse(t, source)
|
|
|
|
assert.Equal(t, content.Metadata, expectedMetadata)
|
|
|
|
}
|
|
|
|
|
|
|
|
test("", map[string]interface{}{})
|
|
|
|
test("# A title", map[string]interface{}{})
|
|
|
|
test("---\n---\n# A title", map[string]interface{}{})
|
|
|
|
test(`---
|
|
|
|
title: A title
|
|
|
|
tags:
|
|
|
|
- tag1
|
|
|
|
- "tag 2"
|
2021-03-19 20:19:55 +00:00
|
|
|
nested:
|
|
|
|
key: value
|
2021-03-08 20:38:32 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
Paragraph
|
|
|
|
`, map[string]interface{}{
|
|
|
|
"title": "A title",
|
|
|
|
"tags": []interface{}{"tag1", "tag 2"},
|
2021-03-19 20:19:55 +00:00
|
|
|
"nested": map[string]interface{}{
|
|
|
|
"key": "value",
|
|
|
|
},
|
2021-03-08 20:38:32 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-04-14 18:14:01 +00:00
|
|
|
func parse(t *testing.T, source string) core.ParsedNote {
|
2021-03-06 18:38:52 +00:00
|
|
|
return parseWithOptions(t, source, ParserOpts{
|
|
|
|
HashtagEnabled: true,
|
|
|
|
MultiWordTagEnabled: true,
|
|
|
|
ColontagEnabled: true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-04-14 18:14:01 +00:00
|
|
|
func parseWithOptions(t *testing.T, source string, options ParserOpts) core.ParsedNote {
|
2021-03-06 18:38:52 +00:00
|
|
|
content, err := NewParser(options).Parse(source)
|
2021-01-16 18:37:10 +00:00
|
|
|
assert.Nil(t, err)
|
2021-01-24 13:33:25 +00:00
|
|
|
return *content
|
2021-01-16 18:37:10 +00:00
|
|
|
}
|