Skip to content

Commit 9ff5685

Browse files
feat: complete implementation with regression tests and docs for #258
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 53bb04b commit 9ff5685

8 files changed

Lines changed: 75 additions & 6 deletions

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Every command must be on its own line; empty lines are ignored.
115115
| `Category[: <category>]` | Create a category title. If unnamed it displays as `Category`. |
116116
| `<Link>` | Create a link to `<Link>` with the display name `<Link>`. |
117117
| `<Link> <Name>` | Create a link to `<Link>` with the display name `<Name>`. |
118-
| `Column` | Start a new column. |
118+
| `Column[: <name>]` | Start a new column and optionally name it. |
119119
| `Page[: <name>]` | Create a new page and optionally name it. |
120120
| `Tab[: <name>]` | Start a new tab. Without a name it reverts to the main tab (switch using `/tab/<index>`).|
121121
| `--` | Insert a horizontal rule and reset columns. |

‎bookmark_model.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -790,11 +790,11 @@ func StrictParseBookmarks(bookmarks string) (BookmarkList, error) {
790790
isColonForm := false
791791
columnName := ""
792792
trimmedColName := strings.TrimSpace(lower)
793-
if strings.HasPrefix(trimmedColName, "column") && len(trimmedColName) > 6 && strings.HasPrefix(strings.TrimSpace(trimmedColName[6:]), ":") {
794-
return nil, fmt.Errorf("line %d: expected category, tab, page, or separator, got %s", i+1, trimmed)
795-
} else if strings.HasPrefix(lower, "column:") {
793+
if strings.HasPrefix(lower, "column:") {
796794
isColonForm = true
797795
columnName = strings.TrimSpace(trimmed[7:])
796+
} else if strings.HasPrefix(trimmedColName, "column") && len(trimmedColName) > 6 && strings.HasPrefix(strings.TrimSpace(trimmedColName[6:]), ":") {
797+
return nil, fmt.Errorf("line %d: expected category, tab, page, or separator, got %s", i+1, trimmed)
798798
} else if strings.HasPrefix(lower, "column ") {
799799
isColonForm = true
800800
columnName = strings.TrimSpace(trimmed[7:])

‎parse_strict_test.go‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ func TestStrictParseBookmarks(t *testing.T) {
1212
"Tab: A\nPage: B\nCategory: C\nsearch:foo foo",
1313
"Category: X\n/local/path Local Path",
1414
"Tab\nPage\n--\nColumn\nCategory: Cat\nhttp://link",
15+
"Column: Named Column\nCategory: Alpha",
16+
"Tab: A\nPage: B\nColumn: Alpha\nCategory: A\nColumn: Beta\nCategory: B\nColumn\nCategory: C",
1517
"Category: Unnamed\nhttp://link",
1618
"Category: Test\nexample.com", // Single token should be parsed as a link (even without scheme)
1719
"Category: Test\nftp://test", // Other schemes
@@ -41,13 +43,16 @@ func TestStrictParseBookmarks(t *testing.T) {
4143
"Category: Valid\nPagge: Missing", // Misspelled directive inside a category
4244
"Category: Valid\nCategor: Missing",
4345
"Category: Valid\nColum:",
46+
"Category: Valid\nColumn\t: Bad Name",
47+
"Category: Valid\nColumn : Bad Name",
48+
"Category: Valid\nColumn : Bad Name",
4449
}
4550

4651
for _, input := range invalidInputs {
4752
_, err := StrictParseBookmarks(input)
4853
if err == nil {
4954
t.Errorf("Expected invalid input to fail parsing, got success\nInput: %q", input)
50-
} else if !strings.Contains(err.Error(), "unrecognized directive") && !strings.Contains(err.Error(), "malformed link") && !strings.Contains(err.Error(), "outside of category") && !strings.Contains(err.Error(), "malformed") && !strings.Contains(err.Error(), "misspelled") {
55+
} else if !strings.Contains(err.Error(), "unrecognized directive") && !strings.Contains(err.Error(), "malformed link") && !strings.Contains(err.Error(), "outside of category") && !strings.Contains(err.Error(), "malformed") && !strings.Contains(err.Error(), "misspelled") && !strings.Contains(err.Error(), "expected category, tab, page, or separator") {
5156
t.Errorf("Expected specific error message, got: %v", err)
5257
}
5358
}

‎templates/editNotes.gohtml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Simply edit your page using the keywords below then set it as your start page.<br>
44
"&lt;URL&gt; &lt;Name&gt; &lt;Newline&gt;" - Creates a link to URL with name, if you need spaces use %20.<br>
55
"Category: &lt;name&gt; &lt;Newline&gt;" - Creates a category named &lt;name&gt;.<br/>
6-
"Column &lt;Newline&gt;" - Creates a new column.<br/>
6+
"Column: &lt;name&gt; &lt;Newline&gt;" - Creates a new named column (or use "Column" for an unnamed column).<br/>
77
"Page &lt;Newline&gt;" - Creates a new page.<br/>
88
"--" - Inserts a horizontal rule and resets the columns.<br>
99
<i>Each category heading on the index page has a pencil icon that links to /editCategory for quick edits. Changes are checked against the file SHA to prevent losing updates.</i>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- input.txt --
2+
Tab: A
3+
Page: B
4+
Category: One
5+
--
6+
Column: Second Block First Column
7+
Category: Two
8+
-- expected.txt --
9+
Tab: A
10+
Page: B
11+
Category: One
12+
--
13+
Column: Second Block First Column
14+
Category: Two
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- input.txt --
2+
Tab: A
3+
Page: B
4+
Category: One
5+
Column : Something
6+
Category: Two
7+
-- expected.txt --
8+
Tab: A
9+
Page: B
10+
Category: One
11+
Column: Something
12+
Category: Two
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
-- input.txt --
2+
Tab: Main
3+
Page: Bookmarks
4+
Column: Alpha
5+
Category: A
6+
https://a.com A Link
7+
Column: Beta
8+
Category: B
9+
https://b.com B Link
10+
Column
11+
Category: C
12+
https://c.com C Link
13+
Column:
14+
Category: D
15+
https://d.com D Link
16+
-- expected.txt --
17+
Tab: Main
18+
Page: Bookmarks
19+
Column: Alpha
20+
Category: A
21+
https://a.com A Link
22+
Column: Beta
23+
Category: B
24+
https://b.com B Link
25+
Column
26+
Category: C
27+
https://c.com C Link
28+
Column
29+
Category: D
30+
https://d.com D Link
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- input.txt --
2+
Category: One
3+
Column:
4+
Category: Two
5+
-- expected.txt --
6+
Category: One
7+
Column
8+
Category: Two

0 commit comments

Comments
 (0)
⌂ 换网址