Update markdown support.
This commit is contained in:
parent
5d68c2cac9
commit
5d30259dfd
17
README.md
17
README.md
@ -50,7 +50,7 @@ Though a terminal utility, it's possible to add bookmarks to `buku` without touc
|
||||
|
||||
- Add, open, tag, comment on, search, update, remove URLs
|
||||
- Portable, merge-able database, to sync between systems
|
||||
- Import/export bookmarks HTML (Firefox, Google Chrome, IE compatible)
|
||||
- Import/export bookmarks in markdown or HTML (FF, Chrome, IE compatible)
|
||||
- Fetch page title from web, refresh all titles in a go
|
||||
- Open (multiple) search results directly in default browser
|
||||
- Manual password protection using AES256 encryption
|
||||
@ -175,6 +175,7 @@ Shell completion scripts for Bash, Fish and Zsh can be found in respective subdi
|
||||
use --tag to export only specific tags
|
||||
-i, --import file import bookmarks from html file; Firefox,
|
||||
Google Chrome and IE formats supported
|
||||
--markdown use markdown format, works with -e and -i
|
||||
-m, --merge file merge bookmarks from another buku database
|
||||
-p, --print [...] show details of bookmark by DB index
|
||||
accepts indices and ranges
|
||||
@ -184,7 +185,6 @@ Shell completion scripts for Bash, Fish and Zsh can be found in respective subdi
|
||||
-r, --replace oldtag [newtag ...]
|
||||
replace oldtag with newtag everywhere
|
||||
delete oldtag, if no newtag
|
||||
--markdown import/exports files from/to markdown format
|
||||
-j, --json Json formatted output for -p, -s, -S, --st
|
||||
--noprompt do not show the prompt, run and exit
|
||||
-o, --open [N] open bookmark at DB index N in web browser
|
||||
@ -323,13 +323,15 @@ Note that URL must precede tags.
|
||||
|
||||
$ buku -u 15012014 -c this is a new comment
|
||||
Applies to --url, --title and --tag too.
|
||||
7. **Export** bookmarks tagged `tag 1` or `tag 2`:
|
||||
7. **Export** bookmarks tagged `tag 1` or `tag 2` to HTML and markdown:
|
||||
|
||||
$ buku -e bookmarks.html tag 1, tag 2
|
||||
$ buku -e bookmarks.html --tag tag 1, tag 2
|
||||
$ buku -e bookmarks.md --markdown --tag tag 1, tag 2
|
||||
All bookmarks are exported if --tag is not specified.
|
||||
8. **Import** bookmarks:
|
||||
8. **Import** bookmarks from HTML and markdown:
|
||||
|
||||
$ buku -i bookmarks.html
|
||||
$ buku -i bookmarks.md --markdown
|
||||
HTML exports from Firefox, Google Chrome and IE are supported.
|
||||
9. **Delete only comment** for bookmark at 15012014:
|
||||
|
||||
@ -397,11 +399,6 @@ The same number of iterations must be specified for one lock & unlock instance.
|
||||
$ buku
|
||||
$ man buku
|
||||
|
||||
27. Export bookmarks into markdown format tagged `tag 1` or `tag 2`:
|
||||
|
||||
$ buku --markdown -e bookmarks.md tag 1, tag 2
|
||||
|
||||
|
||||
## Contributions
|
||||
|
||||
Pull requests are welcome. Please visit [#39](https://github.com/jarun/Buku/issues/39) for a list of TODOs.
|
||||
|
@ -11,8 +11,8 @@ _buku () {
|
||||
local cur=$2 prev=$3
|
||||
local -a opts opts_with_args
|
||||
opts=(-a --add -c --comment --deep -d --delete -e --export -h --help -i --import
|
||||
-k --unlock -l --lock -m --merge --noprompt -o --open -p --print -r --replace
|
||||
-s --sany -S --sall --st --stag --tag -t --title -u --update --url --markdown)
|
||||
-k --unlock -l --lock --markdown -m --merge --noprompt -o --open -p --print
|
||||
-r --replace -s --sany -S --sall --st --stag --tag -t --title -u --update --url)
|
||||
opts_with_arg=(-a --add -e --export -i --import -m --merge
|
||||
-o --open -r --replace -s --sany -S --sall --url)
|
||||
|
||||
|
@ -18,9 +18,9 @@ args=(
|
||||
'(-i --import)'{-i,--import}'[import bookmarks]:html imput file'
|
||||
'(-k --unlock)'{-k,--unlock}'[decrypt database]'
|
||||
'(-l --lock)'{-l,--lock}'[encrypt database]'
|
||||
'(--markdown)--markdown[markdown mode]'
|
||||
'(--merge)--merge[merge another buku database]:buku db file'
|
||||
'(--noprompt)--noprompt[noninteractive mode]'
|
||||
'(--markdown)--markdown[markdown mode]'
|
||||
'(-o --open)'{-o,--open}'[open bookmark in browser]:bookmark index'
|
||||
'(-p --print)'{-p,--print}'[show bookmark details]'
|
||||
'(-r --replace)'{-r,--replace}'[replace a tag]:tag to replace'
|
||||
|
21
buku
21
buku
@ -45,7 +45,6 @@ description = None # Description of the bookmark
|
||||
tagsearch = False # Search bookmarks by tag
|
||||
titleData = None # Title fetched from a webpage
|
||||
interrupted = False # Received SIGINT
|
||||
markdownFormat = False # Support import/export to markdown format
|
||||
DELIMITER = ',' # Delimiter used to store tags in DB
|
||||
_VERSION_ = '2.5' # Program version
|
||||
|
||||
@ -979,7 +978,7 @@ class BukuDb:
|
||||
except IndexError:
|
||||
logger.error('Index out of bound')
|
||||
|
||||
def export_bookmark(self, fp, taglist=None):
|
||||
def export_bookmark(self, fp, markdown=False, taglist=None):
|
||||
'''Export bookmarks to a Firefox
|
||||
bookmarks formatted html file.
|
||||
|
||||
@ -1035,7 +1034,7 @@ class BukuDb:
|
||||
logger.error(e)
|
||||
return
|
||||
|
||||
if not markdownFormat:
|
||||
if not markdown:
|
||||
f.write('''<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
||||
|
||||
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
|
||||
@ -1069,14 +1068,14 @@ class BukuDb:
|
||||
f.close()
|
||||
print('%s bookmarks exported' % count)
|
||||
|
||||
def import_bookmark(self, fp):
|
||||
def import_bookmark(self, fp, markdown=False):
|
||||
'''Import bookmarks from a html file.
|
||||
Supports Firefox, Google Chrome and IE imports
|
||||
|
||||
Params: Path to file to import
|
||||
'''
|
||||
|
||||
if not markdownFormat:
|
||||
if not markdown:
|
||||
try:
|
||||
import bs4
|
||||
with open(fp, mode='r', encoding='utf-8') as f:
|
||||
@ -1112,7 +1111,7 @@ class BukuDb:
|
||||
self.add_bookmark(m.group(2), None, None, desc, True)
|
||||
self.conn.commit()
|
||||
f.close()
|
||||
|
||||
|
||||
def mergedb(self, fp):
|
||||
'''Merge bookmarks from another Buku database file
|
||||
|
||||
@ -1781,6 +1780,7 @@ if __name__ == '__main__':
|
||||
use --tag to export only specific tags
|
||||
-i, --import file import bookmarks from html file; Firefox,
|
||||
Google Chrome and IE formats supported
|
||||
--markdown use markdown format, works with -e and -i
|
||||
-m, --merge file merge bookmarks from another buku database
|
||||
-p, --print [...] show details of bookmark by DB index
|
||||
accepts indices and ranges
|
||||
@ -1790,7 +1790,6 @@ if __name__ == '__main__':
|
||||
-r, --replace oldtag [newtag ...]
|
||||
replace oldtag with newtag everywhere
|
||||
delete oldtag, if no newtag
|
||||
--markdown import/exports files from/to markdown format
|
||||
-j, --json Json formatted output for -p, -s, -S, --st
|
||||
--noprompt do not show the prompt, run and exit
|
||||
-o, --open [N] open bookmark at DB index N in web browser
|
||||
@ -1842,8 +1841,6 @@ if __name__ == '__main__':
|
||||
description = ' '.join(args.desc)
|
||||
if args.jsonOutput:
|
||||
import json
|
||||
if args.markdown:
|
||||
markdownFormat = True
|
||||
if args.debug:
|
||||
logger.setLevel(logging.DEBUG)
|
||||
logger.debug('Version %s', _VERSION_)
|
||||
@ -2009,15 +2006,15 @@ if __name__ == '__main__':
|
||||
# Export bookmarks
|
||||
if args.export is not None:
|
||||
if args.tag is None:
|
||||
bdb.export_bookmark(args.export[0])
|
||||
bdb.export_bookmark(args.export[0], args.markdown)
|
||||
elif len(args.tag) == 0:
|
||||
logger.error('Missing tag')
|
||||
else:
|
||||
bdb.export_bookmark(args.export[0], args.tag)
|
||||
bdb.export_bookmark(args.export[0], args.markdown, args.tag)
|
||||
|
||||
# Import bookmarks
|
||||
if args.imports is not None:
|
||||
bdb.import_bookmark(args.imports[0])
|
||||
bdb.import_bookmark(args.imports[0], args.markdown)
|
||||
|
||||
# Merge a database file and exit
|
||||
if args.merge is not None:
|
||||
|
11
buku.1
11
buku.1
@ -11,7 +11,7 @@ is a command-line tool to save, tag and search bookmarks.
|
||||
.PP
|
||||
* Add, open, tag, comment on, search, update, remove URLs
|
||||
* Portable merge-able database, to sync between systems
|
||||
* Import/export bookmarks HTML (Firefox, Google Chrome, IE compatible)
|
||||
* Import/export bookmarks in markdown or HTML (FF, Chrome, IE compatible)
|
||||
* Fetch page title from web, refresh all titles in a go
|
||||
* Open (multiple) search results directly in default browser
|
||||
* Manual password protection using AES256 encryption
|
||||
@ -123,6 +123,9 @@ Export bookmarks to Firefox bookmarks formatted HTML. Works with --tag to export
|
||||
.BI \-i " " \--import " file"
|
||||
Import bookmarks exported from Firefox, Google Chrome or IE in HTML format.
|
||||
.TP
|
||||
.BI \--markdown
|
||||
Use markdown format for --export and --import.
|
||||
.TP
|
||||
.BI \-m " " \--merge " file"
|
||||
Merge bookmarks from another Buku database file.
|
||||
.TP
|
||||
@ -233,22 +236,24 @@ Note that URL must precede tags.
|
||||
Applies to --url, --title and --tag too.
|
||||
.PP
|
||||
.IP 7. 4
|
||||
\fBExport\fR bookmarks tagged 'tag 1' or 'tag 2':
|
||||
\fBExport\fR bookmarks tagged 'tag 1' or 'tag 2' to HTML and markdown:
|
||||
.PP
|
||||
.EX
|
||||
.IP
|
||||
.B buku -e bookmarks.html --tag tag 1, tag 2
|
||||
.B buku -e bookmarks.md --markdown --tag tag 1, tag 2
|
||||
.EE
|
||||
.PP
|
||||
.IP "" 4
|
||||
All bookmarks are exported if --tag is not specified.
|
||||
.PP
|
||||
.IP 8. 4
|
||||
\fBImport\fR bookmarks:
|
||||
\fBImport\fR bookmarks from HTML and markdown:
|
||||
.PP
|
||||
.EX
|
||||
.IP
|
||||
.B buku -i bookmarks.html
|
||||
.B buku -i bookmarks.md --markdown
|
||||
.EE
|
||||
.PP
|
||||
.IP "" 4
|
||||
|
Loading…
x
Reference in New Issue
Block a user