File tree 1 file changed +15
-0
lines changed
1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ package display
2
2
3
3
import (
4
4
"fmt"
5
+ "regexp"
6
+ "strings"
5
7
6
8
"code.rocketnine.space/tslocum/cview"
7
9
"github.com/gdamore/tcell/v2"
@@ -28,6 +30,9 @@ const (
28
30
var bkmkCh = make (chan bkmkAction )
29
31
var bkmkModalText string // The current text of the input field in the modal
30
32
33
+ // Regex for extracting top level 1 heading. The title will extracted from the 1st submatch.
34
+ var topHeadingRegex = regexp .MustCompile (`(?m)^#\s?[\w\s,;'":\.]+$` )
35
+
31
36
func bkmkInit () {
32
37
panels .AddPanel (PanelBookmarks , bkmkModal , false , false )
33
38
@@ -159,7 +164,17 @@ func addBookmark() {
159
164
return
160
165
}
161
166
name , exists := bookmarks .Get (p .URL )
167
+
168
+ // Retrieve & use top level 1 heading for name if bookmark does not already exist.
169
+ if ! exists {
170
+ match := topHeadingRegex .FindString (p .Raw )
171
+ if match != "" {
172
+ name = strings .TrimSpace (match [1 :])
173
+ }
174
+ }
175
+
162
176
// Open a bookmark modal with the current name of the bookmark, if it exists
177
+ // otherwise use the top level 1 heading as a suggested name
163
178
newName , action := openBkmkModal (name , exists )
164
179
165
180
//nolint:exhaustive
You can’t perform that action at this time.
0 commit comments