├── .gitignore ├── tools ├── md2phi.sh ├── md2zettel.py ├── phi2uly.py ├── mmap2phi.py └── md2phi.py ├── CSS ├── epub.css └── Bear.css ├── elisp └── zettel-compose.el ├── README.md ├── zettel-compose.py └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | compose-output.md 3 | zettel-compose.md 4 | .DS_Store 5 | -------------------------------------------------------------------------------- /tools/md2phi.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | PHI_PATH="/Users/brunoc/Dropbox/Fichas/Φ" 4 | 5 | BASE_FN=`basename "${1}" | sed 's/\.md$//'` 6 | PHI_ID=`echo "${BASE_FN}" | awk '{ print $1 }'` 7 | EXPAND_FN=$(echo "${PHI_PATH}/${PHI_ID} "*".markdown") 8 | NEW_FN="${PHI_PATH}/${BASE_FN}.markdown" 9 | TRASH_PATH="/Users/brunoc/.Trash" 10 | 11 | if [ -f "${EXPAND_FN}" ] && [ "${NEW_FN}" != "${EXPAND_FN}" ] || [ `ls -1 "${PHI_PATH}/${PHI_ID} "*".markdown" 2>/dev/null | wc -l ` -gt 1 ]; then 12 | STATUS=`osascript -so <&2 && exit 1 17 | mv -f "${PHI_PATH}/${PHI_ID} "*".markdown" "${TRASH_PATH}" 18 | fi 19 | 20 | /Users/brunoc/GitHub/zettel-composer/tools/md2phi.py "${PHI_PATH}" "${1}" -------------------------------------------------------------------------------- /CSS/epub.css: -------------------------------------------------------------------------------- 1 | /* This defines styles and classes used in the book */ 2 | body { margin: 0; text-align: justify; font-size: medium; font-family: Athelas, Georgia, serif; } 3 | code { font-family: monospace; } 4 | h1 { text-align: left; } 5 | h2 { text-align: left; } 6 | h3 { text-align: left; } 7 | h4 { text-align: left; } 8 | h5 { text-align: left; } 9 | h6 { text-align: left; } 10 | h1.title { } 11 | h2.author { } 12 | h3.date { } 13 | ol.toc { padding: 0; margin-left: 1em; } 14 | ol.toc li { list-style-type: none; margin: 0; padding: 0; } 15 | 16 | /* Disable hyphenation for headings to avoid single-syllable-lines. 17 | */ 18 | h1, 19 | h2 { 20 | -epub-hyphens: none; 21 | -webkit-hyphens: none; 22 | -moz-hyphens: none; 23 | hyphens: none; 24 | } 25 | 26 | h4 { 27 | display: inline; 28 | font-style: bold; 29 | } 30 | 31 | h4::after { 32 | content: "."; 33 | } 34 | 35 | h4 + p { display: inline; } 36 | 37 | h5 { 38 | display: inline; 39 | font-style: bold; 40 | } 41 | 42 | h5::after { 43 | content: ":"; 44 | } 45 | 46 | h5 + p { display: inline; } 47 | 48 | /* Set the minimum amount of lines to show up on a separate page. (There is not much support for this at the moment.) 49 | */ 50 | p, 51 | blockquote { 52 | orphans: 2; 53 | widows: 2; 54 | } 55 | 56 | /* Turn on hyphenation for paragraphs and captions only. 57 | */ 58 | p, 59 | figcaption { 60 | -epub-hyphens: auto; 61 | -webkit-hyphens: auto; 62 | -moz-hyphens: auto; 63 | hyphens: auto; 64 | } 65 | 66 | /* Shortcodes for page-break rules. 67 | Use data attributes to designate if and how the page should be broken before, inside or after an element. 68 | */ 69 | h1, h2, h3, h4, h5, h6, 70 | table, img, figure, video, 71 | [data-page-break~=inside][data-page-break~=avoid] { page-break-inside: avoid; } 72 | [data-page-break~=after] { page-break-after: always; } 73 | h1, h2, h3, h4, h5, h6, 74 | [data-page-break~=after][data-page-break~=avoid] { page-break-after: avoid; } 75 | [data-page-break~=before] { page-break-before: always; } 76 | [data-page-break~=before][data-page-break~=avoid] { page-break-before: avoid; } 77 | img[data-page-break~=before] { page-break-before: left; } -------------------------------------------------------------------------------- /tools/md2zettel.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # md2zettel.py 5 | # by Bruno L. Conte , 2020 6 | 7 | import re 8 | from collections import OrderedDict 9 | import os, sys 10 | 11 | fields_dict = OrderedDict([ 12 | ('origin', re.compile(r'^origin:\s+(?P.*)$')), 13 | ('tags', re.compile(r'^tags:\s+(?P.*)$')), 14 | ('blank_line', re.compile(r'^ $')) # two spaces in a line is a blank and should be disconsidered 15 | ]) 16 | 17 | rx_dict = OrderedDict([ 18 | ('cross_ref', re.compile(r'\*\*(?P\d{3,})\*\*')), # any three-or-more-digit bold text is a wikilink 19 | ('footnote', re.compile(r'\[\^(?P\d+)\]')) # markdown footnotes 20 | ]) 21 | 22 | title_rx = re.compile(r'(?P\d{3,})\s+(?P.+)$') 23 | 24 | z_id = None 25 | out_filename = None 26 | 27 | def _parse_line(line, thedict): 28 | for key, rx in thedict.items(): 29 | match = rx.search(line) 30 | if match: 31 | return key, match, match.end() 32 | return None, None, None 33 | 34 | def parse_chunk(chunk): 35 | global z_id, rx_dict 36 | key, match, end = _parse_line(chunk, rx_dict) 37 | 38 | if (key is None): 39 | return chunk 40 | 41 | left_chunk = chunk[:end] 42 | if key == 'cross_ref': 43 | ref_id = match.group('id') 44 | left_chunk = rx_dict['cross_ref'].sub("[[" + ref_id + "]]", left_chunk) 45 | if key == 'footnote': 46 | fn_id = match.group('fn_id') 47 | left_chunk = rx_dict['footnote'].sub("[^fn-" + z_id + "-" + fn_id + "]", left_chunk) 48 | 49 | return left_chunk + parse_chunk(chunk[end:]) 50 | 51 | def getHeader(zettel_id, title, fields): 52 | header = [ "---", "title:\t'" + title + "' ", "id:\t\t" + zettel_id + " "] 53 | for k in fields.keys(): 54 | if (len(k) < 5): 55 | tabs = "\t\t" 56 | else: 57 | tabs ="\t" 58 | header = header + [ k + ":" + tabs + fields[k]] 59 | 60 | return header + ["..."] 61 | 62 | 63 | def readFile(filepath): 64 | global z_id, out_filename 65 | 66 | with open(filepath, 'r') as file_object: 67 | lines = file_object.read().splitlines() 68 | 69 | fields = {} 70 | data = [] 71 | 72 | match = title_rx.search(lines[0]) 73 | if not match: 74 | raise Exception("Invalid file name for note detected in the first line") 75 | 76 | z_id = match.group('id') 77 | title = match.group('title') 78 | out_filename = z_id + " " + title + ".markdown" 79 | 80 | for line in lines[1:]: 81 | key, match, end = _parse_line(line, fields_dict) 82 | if (key): 83 | if key != 'blank_line': 84 | value = match.group('value') 85 | fields[key] = value 86 | continue 87 | line = parse_chunk(line) 88 | data.append(line) 89 | 90 | h = getHeader(z_id, title, fields) 91 | return h + data 92 | 93 | zk_dir = sys.argv[1] 94 | infile = sys.argv[2] 95 | d = readFile(infile) 96 | 97 | with open(zk_dir + "/" + out_filename, "w") as f_out: 98 | for l in d: 99 | f_out.write("%s\n" % l) -------------------------------------------------------------------------------- /tools/phi2uly.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | # phi2uly.py 5 | # by Bruno L. Conte <bruno@brunoc.com.br>, 2021 6 | 7 | import re 8 | from collections import OrderedDict 9 | import os, sys, urllib.parse 10 | 11 | # import subprocess, xcall 12 | 13 | XCALL_PATH = (os.path.dirname(os.path.abspath(__file__)) + 14 | '/lib/xcall.app/Contents/MacOS/xcall') 15 | 16 | fields_dict = OrderedDict([ 17 | ('tags', re.compile(r'^tags:\s+(?P<value>.*)\s*$')), 18 | ('title', re.compile(r'^title:\s+\'+(?P<value>.*)\'\s*$')), 19 | ('id', re.compile(r'^id:\s+Φ(?P<value>\d{3,})\s*$')), 20 | ('phi_uplink', re.compile(r'^△\[\[(?P<value>\d{3,})\]\]')), 21 | ('yaml_end_div', re.compile(r'^\.\.\.$')), 22 | ('yaml_div', re.compile(r'^\-\-\-$')), 23 | ('breadcrumb', re.compile(r'^○')) 24 | ]) 25 | 26 | rx_dict = OrderedDict([ 27 | ('phi_cross_ref', re.compile(r'\[\[(?P<id>\d{3,})\]\]')) # any three-or-more-digit bold text is a wikilink 28 | ]) 29 | 30 | def parse_line(line, thedict): 31 | for key, rx in thedict.items(): 32 | match = rx.search(line) 33 | if match: 34 | return key, match, match.end() 35 | return None, None, None 36 | 37 | def parse_chunk(chunk): 38 | global rx_dict 39 | key, match, end = parse_line(chunk, rx_dict) 40 | 41 | if (key is None): 42 | return chunk 43 | 44 | left_chunk = chunk[:end] 45 | if key == 'phi_cross_ref': 46 | ref_id = match.group('id') 47 | left_chunk = rx_dict['phi_cross_ref'].sub("**" + ref_id + "**", left_chunk) 48 | 49 | return left_chunk + parse_chunk(chunk[end:]) 50 | 51 | def getHeader(fields): 52 | try: 53 | tags = fields["tags"] 54 | except: 55 | tags = "" 56 | 57 | try: 58 | origin = fields["origin"] 59 | except: 60 | origin = "" 61 | 62 | try: 63 | uplink = fields["phi_uplink"] 64 | except: 65 | uplink = "" 66 | 67 | 68 | header = [ "uplink: " + uplink, "tags: " + tags, "origin: " + origin ] 69 | return header 70 | 71 | def readFile(filepath): 72 | with open(filepath, 'r') as file_object: 73 | lines = file_object.read().splitlines() 74 | 75 | fields = {} 76 | data = [] 77 | got_content = False 78 | 79 | for line in lines: 80 | key, match, end = parse_line(line, fields_dict) 81 | if (key): 82 | if key not in ['yaml_end_div', 'yaml_div', 'breadcrumb']: 83 | value = match.group('value') 84 | fields[key] = value 85 | continue 86 | if (line != ''): 87 | line = parse_chunk(line) 88 | got_content = True 89 | 90 | if got_content: 91 | data.append(line) 92 | 93 | return data, fields 94 | 95 | 96 | def xcall_ulysses(url): 97 | args = [XCALL_PATH, '-url', '"%s"' % url] 98 | # args = args + ['-activateApp', 'YES'] 99 | 100 | p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 101 | stdout, stderr = p.communicate() 102 | 103 | if stdout and (stderr == ''): 104 | response = urllib.unquote(stdout).decode('utf8') 105 | return response 106 | 107 | 108 | infile = sys.argv[1] 109 | d, f = readFile(infile) 110 | h = getHeader(f) 111 | titleline = [f["id"] + " " + f["title"]] 112 | out = "\n".join(titleline + [""] + d + [""] + h) 113 | 114 | os.system("open ulysses://x-callback-url/new-sheet?text=" + urllib.parse.quote(out)) 115 | 116 | # status = os.system(XCALL_PATH + " -url \"ulysses://x-callback-url/new-sheet?text=" + urllib.parse.quote(out) + "\"") 117 | 118 | # status = xcall_ulysses("ulysses://x-callback-url/new-sheet?text=" + urllib.parse.quote(out)) 119 | # print(status) 120 | 121 | # ULYSSES_XCALL = xcall.XCallClient('ulysses') 122 | # ULYSSES_XCALL.xcall("new-sheet", {"text": out}, activate_app=True) 123 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /tools/mmap2phi.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | import re 5 | import os, sys 6 | from urllib.parse import quote 7 | from collections import OrderedDict 8 | 9 | MINDNODE_URI='mindnode:/' 10 | MINDNODE_PHI_PATH = 'phi' 11 | 12 | 13 | rx_dict = OrderedDict([ 14 | # ('task', re.compile(r'\[(?P<status>.)\]\s+(?P<task>.*)')), 15 | ('paragraph-link', re.compile(r'\[§\s+(?P<anchor>.+)\]\(x-phi://(?P<link>\d{3,})\)')), 16 | ('link', re.compile(r'\[(?P<anchor>.+)\]\(x-phi://(?P<link>\d{3,})\)')), 17 | ('list_entry', re.compile(r'^\s*- (?P<entry>.*)$')), 18 | ('atx_header', re.compile(r'^#+')) 19 | ]) 20 | 21 | title_rx = re.compile(r'(?P<id>\d{3,})\s+(\|\s+){0,1}(?P<title>.+)$') 22 | 23 | def parse_chunk(chunk): 24 | global rx_dict 25 | 26 | for key, rx in rx_dict.items(): 27 | match = rx.search(chunk) 28 | if match: 29 | left_chunk = chunk[:match.end()] 30 | 31 | if (key == 'paragraph-link'): 32 | value = match.group('anchor') 33 | link = match.group('link') 34 | left_chunk = rx_dict[key].sub(value + " §[[" + link + "]]", left_chunk) 35 | if (key == 'link'): 36 | value = match.group('anchor') 37 | link = match.group('link') 38 | left_chunk = rx_dict[key].sub(value + " [[" + link + "]]", left_chunk) 39 | 40 | # if (key == 'list_entry'): 41 | # value = match.group('entry') 42 | # left_chunk = rx_dict['list_entry'].sub(value + ".", left_chunk) 43 | 44 | if (key == 'task'): 45 | value = match.group('status') 46 | task = match.group('task') 47 | left_chunk = rx_dict['task'].sub('- [' + value + '] ' + task, left_chunk) 48 | 49 | chunk = left_chunk + parse_chunk(chunk[match.end():]) 50 | 51 | return chunk 52 | 53 | def getHeader(zettel_id, title, filename, path): 54 | header = [ "---", "title:\t'" + title + "' ", "id:\t\tΦ" + zettel_id + " ", 55 | 'origin:\t' + MINDNODE_URI + '/open?name=' + quote(filename) + '.mindnode&path=' + path ] 56 | 57 | header.append("...") 58 | header.append("") 59 | 60 | return header 61 | 62 | def readFile(infile): 63 | global rx_dict, out_filename 64 | 65 | data = [] 66 | got_list_item = False 67 | atx_header = False 68 | got_blank = False 69 | 70 | with open(infile, 'r') as file_obj: 71 | lines = file_obj.read().splitlines() 72 | 73 | if not title_basename: 74 | match = title_rx.search(lines[0]) 75 | if not match: 76 | raise Exception("Invalid file name for note detected in the first line") 77 | else: 78 | match = title_rx.search(title_basename) 79 | 80 | phi_id = match.group('id') 81 | title = match.group('title') 82 | 83 | out_filename = phi_dir + '/' + phi_id + ' ' + title + '.markdown' 84 | data.append('# ' + title) 85 | 86 | for line in lines[1:]: 87 | line = parse_chunk(line) 88 | atx_header = rx_dict['atx_header'].search(line) 89 | 90 | if atx_header and got_blank: 91 | data.append('') 92 | if (line != '') or not got_list_item: 93 | data.append(line) 94 | if (line != ''): 95 | got_list_item = rx_dict['list_entry'].search(line) 96 | got_blank = False 97 | else: 98 | got_blank = True 99 | 100 | h = getHeader(phi_id, title, title_basename, mindnode_path) 101 | return h + data 102 | 103 | phi_dir = sys.argv[1] 104 | infile = sys.argv[2] 105 | mindnode_path = sys.argv[3] 106 | title_basename = os.path.splitext(os.path.basename(infile))[0] 107 | 108 | match = title_rx.search(title_basename) 109 | if not match: 110 | title_basename = None 111 | # raise Exception("Invalid file name for note detected in the first line") 112 | 113 | d = readFile(infile) 114 | 115 | with open(out_filename, 'w') as f_out: 116 | for l in d: 117 | f_out.write("%s\n" % l) 118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /tools/md2phi.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | # md2phi.py 5 | # by Bruno L. Conte <bruno@brunoc.com.br>, 2020-2021 6 | 7 | # Syntax: 8 | # md2phi.py <path to notes> <input file> 9 | 10 | import re 11 | from collections import OrderedDict 12 | import os, sys 13 | from datetime import datetime 14 | 15 | 16 | fields_dict = OrderedDict([ 17 | ('origin', re.compile(r'^origin:\s+(?P<value>.*)$')), 18 | ('tags', re.compile(r'^tags:\s+(?P<value>.*)$')), 19 | ('uplink', re.compile(r'^uplink:\s+(?P<value>\d{3,})\s*$')), 20 | ('blank_line', re.compile(r'^ $')) # two spaces in a line is a blank to be disconsidered 21 | ]) 22 | 23 | rx_dict = OrderedDict([ 24 | ('link', re.compile(r'\[(?P<anchor>.+)\]\(x-phi://(?P<link>\d{3,})\)')), 25 | # ('footnote', re.compile(r'\[\^(?P<fn_id>[a-zA-Z0-9_-]+)]')), 26 | ('cross_ref', re.compile(r'\*\*(?P<id>\d{3,})\*\*')), # any three-or-more-digit bold text is a wikilink 27 | ('parallel-text', re.compile(r'❖(?P<left_id>\d{3,})❖(?P<right_id>\d{3,})\b', re.UNICODE)), # parallel texts 28 | ('text', re.compile(r'❖(?P<id>\d{3,})\b', re.UNICODE)), # text 29 | ('paragraph', re.compile(r'❡(?P<id>\d{3,})', re.UNICODE)), # special symbol for reference to paragraph of text 30 | ('citation', re.compile(r'❦(?P<id>\d{3,})', re.UNICODE)), # cite reference 31 | ('alt_cross_ref', re.compile(r'[▸►▹❧▶︎☞☛▷Φ](?P<id>\d{3,})\b', re.UNICODE)) 32 | ]) 33 | 34 | title_rx = re.compile(r'(?P<id>\d{3,})\s+(\|\s+){0,1}(?P<title>.+)$') 35 | 36 | phi_id = None 37 | out_filename = None 38 | 39 | def _parse_line(line, thedict): 40 | for key, rx in thedict.items(): 41 | match = rx.search(line) 42 | if match: 43 | return key, match, match.end() 44 | return None, None, None 45 | 46 | def parse_chunk(chunk): 47 | global phi_id, rx_dict 48 | key, match, end = _parse_line(chunk, rx_dict) 49 | 50 | if (key is None): 51 | return chunk 52 | 53 | left_chunk = chunk[:end] 54 | if key in ['cross_ref','alt_cross_ref']: 55 | ref_id = match.group('id') 56 | left_chunk = rx_dict[key].sub("[[" + ref_id + "]]", left_chunk) 57 | # if key == 'footnote': 58 | # fn_id = match.group('fn_id') 59 | # left_chunk = rx_dict['footnote'].sub("[^fn-" + phi_id + "-" + fn_id + "]", left_chunk) 60 | if (key == 'link'): 61 | value = match.group('anchor') 62 | link = match.group('link') 63 | left_chunk = rx_dict['link'].sub(value + " §[[" + link + "]]", left_chunk) 64 | if (key == 'paragraph'): 65 | ref_id = match.group('id') 66 | left_chunk = rx_dict[key].sub("§[[" + ref_id + "]]", left_chunk) 67 | if (key == 'citation'): 68 | ref_id = match.group('id') 69 | left_chunk = rx_dict[key].sub("@[[" + ref_id + "]]", left_chunk) 70 | if (key == 'parallel-text'): 71 | left_id = match.group('left_id') 72 | right_id = match.group('right_id') 73 | left_chunk = rx_dict[key].sub(">[[" + left_id + "]]::[[" + right_id + ']]', left_chunk) 74 | if (key == 'text'): 75 | ref_id = match.group('id') 76 | left_chunk = rx_dict[key].sub(">[[" + ref_id + "]]", left_chunk) 77 | 78 | return left_chunk + parse_chunk(chunk[end:]) 79 | 80 | def getHeader(zettel_id, title, fields): 81 | header = [ "---", "title:\t'" + title + "' ", "id:\t\tΦ" + zettel_id + " "] 82 | fields['datetime'] = datetime.now().isoformat(timespec='minutes') # strftime('%d %B %Y %H:%M') 83 | for k in fields.keys(): 84 | if k not in ['uplink']: 85 | if (len(k) < 5): 86 | tabs = "\t\t" 87 | else: 88 | tabs ="\t" 89 | header = header + [ k + ":" + tabs + fields[k]] 90 | header = header + ["..."] 91 | 92 | if "uplink" in fields.keys(): 93 | header = header + [ "", "△[[" + fields["uplink"] + "]]" ] 94 | 95 | return header 96 | 97 | 98 | def readFile(filepath): 99 | global phi_id, out_filename 100 | 101 | with open(filepath, 'r') as file_object: 102 | lines = file_object.read().splitlines() 103 | 104 | fields = {} 105 | data = [] 106 | 107 | match = title_rx.search(lines[0]) 108 | if not match: 109 | raise Exception("Invalid file name for note detected in the first line") 110 | 111 | phi_id = match.group('id') 112 | title = match.group('title') 113 | out_filename = phi_id + " " + title + ".markdown" 114 | 115 | # data.append("# " + title) 116 | 117 | for line in lines[1:]: 118 | key, match, end = _parse_line(line, fields_dict) 119 | if (key): 120 | if key != 'blank_line': 121 | value = match.group('value') 122 | fields[key] = value 123 | continue 124 | line = parse_chunk(line) 125 | data.append(line) 126 | 127 | h = getHeader(phi_id, title, fields) 128 | return h + [ '' ] + data 129 | 130 | phi_dir = sys.argv[1] 131 | infile = sys.argv[2] 132 | d = readFile(infile) 133 | 134 | d.append('<!-- WARNING: Do not edit directly! -->') 135 | 136 | with open(phi_dir + "/" + out_filename, "w") as f_out: 137 | for l in d: 138 | f_out.write("%s\n" % l) 139 | 140 | -------------------------------------------------------------------------------- /elisp/zettel-compose.el: -------------------------------------------------------------------------------- 1 | ;;; zettel-compose.el --- Wrapper for zettel-compose.py -*- lexical-binding: t -*- 2 | 3 | (defgroup zettel-compose nil 4 | "Wrapper for zettel-compose.py script." 5 | :group 'tools) 6 | 7 | (defcustom zettel-compose-script-path "/usr/local/bin/zettel-compose" 8 | "Path to the zettel-compose.py script." 9 | :type 'string 10 | :group 'zettel-compose) 11 | 12 | (defun zettel-compose--build-args (options) 13 | "Build the argument list for zettel-compose.py based on OPTIONS." 14 | (let (args) 15 | (when (plist-get options :index-file) 16 | ;; Ensure the index file path is wrapped in quotes 17 | (push (format "\"%s\"" (plist-get options :index-file)) args)) 18 | 19 | ;; -O, --output= 20 | (when (plist-get options :output) 21 | ;; Ensure the output file path is wrapped in quotes 22 | (push (format "-O \"%s\"" (plist-get options :output)) args)) 23 | ;; -M, --stream-to-marked 24 | (when (plist-get options :stream-to-marked) 25 | (push "--stream-to-marked" args)) 26 | ;; -H, --heading-identifier= 27 | (when (plist-get options :heading-identifier) 28 | (push (concat "--heading-identifier=" (plist-get options :heading-identifier)) args)) 29 | ;; -W, --watch 30 | (when (plist-get options :watch) 31 | (push "--watch" args)) 32 | ;; -s, --sleep-time= 33 | (when (plist-get options :sleep-time) 34 | (push (concat "--sleep-time=" (number-to-string (plist-get options :sleep-time))) args)) 35 | ;; -n, --no-paragraph-headings 36 | (when (plist-get options :no-paragraph-headings) 37 | (push "--no-paragraph-headings" args)) 38 | ;; --no-separator 39 | (when (plist-get options :no-separator) 40 | (push "--no-separator" args)) 41 | ;; -C, --no-commented-references 42 | (when (plist-get options :no-commented-references) 43 | (push "--no-commented-references" args)) 44 | ;; -S, --suppress-index 45 | (when (plist-get options :suppress-index) 46 | (push "--suppress-index" args)) 47 | ;; -I (only-link-from-index) 48 | (when (plist-get options :only-link-from-index) 49 | (push "-I" args)) 50 | ;; -t (quote zettel count) 51 | (when (plist-get options :quote-z-count) 52 | (push (concat "-t " (number-to-string (plist-get options :quote-z-count))) args)) 53 | ;; -G (parallel texts selection) 54 | (when (plist-get options :parallel-texts-selection) 55 | (push (concat "-G " (plist-get options :parallel-texts-selection)) args)) 56 | ;; -v (verbose) 57 | (when (plist-get options :verbose) 58 | (push "-v" args)) 59 | ;; -h (handout mode) 60 | (when (plist-get options :handout-mode) 61 | (let ((handout-with-sections (plist-get options :handout-with-sections))) 62 | (push (concat "-h" (if handout-with-sections "+" "")) args))) 63 | ;; -P (parallel-texts-processor) 64 | (when (plist-get options :parallel-texts-processor) 65 | (push "-P" args)) 66 | ;; -L, --link-all 67 | (when (plist-get options :link-all) 68 | (push "--link-all" args)) 69 | ;; --custom-url= 70 | (when (plist-get options :custom-url) 71 | (push (concat "--custom-url=" (plist-get options :custom-url)) args)) 72 | ;; --section-symbol= 73 | (when (plist-get options :section-symbol) 74 | (push (concat "--section-symbol=" (plist-get options :section-symbol)) args)) 75 | ;; --no-title 76 | (when (plist-get options :no-title) 77 | (push "--no-title" args)) 78 | ;; --insert-bib-ref 79 | (when (plist-get options :insert-bib-ref) 80 | (push "--insert-bib-ref" args)) 81 | ;; --no-front-matter 82 | (when (plist-get options :no-front-matter) 83 | (push "--no-front-matter" args)) 84 | ;; -X (extract-mode) 85 | (when (plist-get options :extract-mode) 86 | (push "-X" args)) 87 | ;; Return the arguments 88 | args)) 89 | 90 | ;;;###autoload 91 | (defun zettel-compose-run (options) 92 | "Run the zettel-compose.py script with OPTIONS." 93 | (interactive 94 | (let ((output (read-string "Output file: " nil nil)) 95 | (stream-to-marked (yes-or-no-p "Stream to marked? ")) 96 | (watch (yes-or-no-p "Watch the input file? "))) 97 | (list (list :output output 98 | :stream-to-marked stream-to-marked 99 | :watch watch 100 | :index-file (buffer-file-name (current-buffer)))))) 101 | (let* ((args (zettel-compose--build-args options)) 102 | (command (mapconcat 'identity (cons zettel-compose-script-path args) " ")) 103 | (output-buffer-name (generate-new-buffer-name "*zettel-compose-output*"))) 104 | (message "Running command: %s" command) 105 | (start-process-shell-command "*zettel-compose*" output-buffer-name command))) 106 | 107 | ;;;###autoload 108 | (defun zettel-compose-stop-all-processes () 109 | "Stop all running asynchronous zettel-compose processes." 110 | (interactive) 111 | (let ((processes (cl-remove-if-not 112 | (lambda (proc) 113 | (when proc 114 | (string-match-p "*zettel-compose*" (buffer-name (process-buffer proc))))) 115 | (mapcar #'get-buffer-process (buffer-list))))) 116 | (if processes 117 | (progn 118 | (dolist (proc processes) 119 | (delete-process proc)) 120 | (message "Stopped all zettel-compose processes.")) 121 | (message "No running zettel-compose processes found.")))) 122 | 123 | (provide 'zettel-compose) 124 | 125 | ;;; zettel-compose.el ends here 126 | -------------------------------------------------------------------------------- /CSS/Bear.css: -------------------------------------------------------------------------------- 1 | /* 2 | This document has been created with Marked.app <http://marked2app.com> 3 | Content is property of the document author 4 | Please leave this notice in place, along with any additional credits below. 5 | --------------------------------------------------------------- 6 | Title: Bear 7 | Author: Brett Terpstra 8 | Description: A simulation of Bear.app 9 | --- 10 | Modified by Bruno Conte 11 | - better style for CriticMarkup, for use with zettel-compose.py 12 | - selection of fonts for Greek text 13 | */ 14 | 15 | 16 | 17 | @font-face { 18 | font-family: GreekFont; 19 | src: local('Consolas'), local('Hypatia Sans Pro'), local('Verdana'), local('Arial'); 20 | font-weight: 300; 21 | unicode-range: U+0370-03FF, U+1F00-1FFF; 22 | } 23 | 24 | body { 25 | -webkit-font-smoothing: antialiased; 26 | font-family: GreekFont, Consolas, "Avenir Next", Avenir, "Helvetica Neue", Helvetica, Arial, Verdana, sans-serif; 27 | margin: 30px 0 0; 28 | padding: 0; 29 | background: #fff; 30 | color: #303030; 31 | font-size: 12px; 32 | line-height: 1.5 33 | } 34 | 35 | 36 | 37 | #wrapper { 38 | padding: 20px; 39 | margin: 0 auto; 40 | } 41 | 42 | li { 43 | font-size: 110% 44 | } 45 | 46 | li li { 47 | font-size: 100% 48 | } 49 | 50 | li p { 51 | font-size: 100%; 52 | margin: .5em 0; 53 | line-height: 1.4; 54 | } 55 | 56 | .task-list-item-checkbox { 57 | top: 0!important; 58 | } 59 | 60 | h1 { 61 | color: #000 62 | } 63 | 64 | h2 { 65 | color: #111 66 | } 67 | 68 | h3 { 69 | color: #111 70 | } 71 | 72 | h4 { 73 | color: #111 74 | } 75 | 76 | h5 { 77 | color: #111 78 | } 79 | 80 | h6 { 81 | color: #111; 82 | font-style: italic 83 | } 84 | 85 | p, td, div { 86 | color: #111; 87 | font-family: GreekFont, Consolas, "Avenir Next", Avenir, "Helvetica Neue", Helvetica, Arial, Verdana, sans-serif; 88 | word-wrap: break-word 89 | } 90 | 91 | a { 92 | color: rgb(222, 84, 86); 93 | text-decoration: none; 94 | -webkit-transition: color .2s ease-in-out; 95 | -moz-transition: color .2s ease-in-out; 96 | -o-transition: color .2s ease-in-out; 97 | -ms-transition: color .2s ease-in-out; 98 | transition: color .2s ease-in-out 99 | } 100 | 101 | a:hover { 102 | color: #3593d9 103 | } 104 | 105 | h1, h2, h3, h4, h5 { 106 | margin: 2.75rem 0 2rem; 107 | font-weight: 500; 108 | line-height: 1.15 109 | } 110 | 111 | h1 { 112 | margin-top: 0; 113 | font-size: 2em 114 | } 115 | 116 | h2 { 117 | font-size: 1.7em 118 | } 119 | 120 | h3 { 121 | font-size: 1.2em 122 | } 123 | 124 | h4 { 125 | font-size: 1.563em 126 | } 127 | 128 | h5 { 129 | font-size: 1.25em 130 | } 131 | 132 | ul, ol, pre, table, blockquote { 133 | margin-top: 2em; 134 | margin-bottom: 2em 135 | } 136 | 137 | mark { 138 | background: rgb(211, 255, 164); 139 | } 140 | 141 | blockquote { 142 | padding: 0 0 0 1.5em; 143 | margin: 2em 0 0 -1.5em; 144 | border-left: 1px solid rgb(222, 84, 86); 145 | } 146 | 147 | hr { 148 | border: none; 149 | border-bottom: 1px solid #ddd; 150 | margin: 3em 0; 151 | } 152 | 153 | ul ul, ol ol, ul ol, ol ul { 154 | margin-top: 0; 155 | margin-bottom: 0 156 | } 157 | 158 | b, strong, em, small, code { 159 | line-height: 1 160 | } 161 | 162 | .footnote { 163 | color: #0d6ea1; 164 | font-size: .8em; 165 | vertical-align: super 166 | } 167 | 168 | abbr, acronym { 169 | border-bottom: 1px dotted #aaa 170 | } 171 | 172 | #wrapper img { 173 | max-width: 100%; 174 | height: auto 175 | } 176 | 177 | dd { 178 | font-size: 1em; 179 | margin-bottom: 1em 180 | } 181 | 182 | li>p:first-of-type { 183 | margin: 0 184 | } 185 | 186 | li p+p { 187 | margin-top: 16px 188 | } 189 | 190 | ul, ol { 191 | list-style-position: outside; 192 | padding-left: 0; 193 | } 194 | 195 | 196 | ul ul, ul ol, ol ul, ol ol { 197 | margin-bottom: .4em; 198 | padding-left: 2em; 199 | } 200 | 201 | ul li { 202 | list-style-type: none; 203 | position: relative; 204 | } 205 | 206 | ul li:not(.task-list-item)::before { 207 | color: rgb(222, 84, 86); 208 | content: '●'; 209 | display: inline; 210 | font-size: 11px; 211 | left: -20px; 212 | position: absolute; 213 | top: 2px; 214 | } 215 | 216 | ol { 217 | counter-reset: list; 218 | } 219 | 220 | ol li { 221 | counter-increment: list; 222 | list-style-type: none; 223 | position: relative; 224 | } 225 | ol li:before { 226 | color: rgb(222, 84, 86); 227 | content: counter(list) "."; 228 | left:-32px; 229 | position: absolute; 230 | text-align: right; 231 | width: 26px; 232 | } 233 | 234 | caption, col, colgroup, table, tbody, td, tfoot, th, thead, tr { 235 | border-spacing: 0 236 | } 237 | 238 | table { 239 | border: 1px solid rgba(0, 0, 0, 0.25); 240 | border-collapse: collapse; 241 | display: table; 242 | empty-cells: hide; 243 | margin: -1px 0 1.3125em; 244 | padding: 0; 245 | table-layout: fixed 246 | } 247 | 248 | caption { 249 | display: table-caption; 250 | font-weight: 700 251 | } 252 | 253 | col { 254 | display: table-column 255 | } 256 | 257 | colgroup { 258 | display: table-column-group 259 | } 260 | 261 | tbody { 262 | display: table-row-group 263 | } 264 | 265 | tfoot { 266 | display: table-footer-group 267 | } 268 | 269 | thead { 270 | display: table-header-group 271 | } 272 | 273 | td, th { 274 | display: table-cell 275 | } 276 | 277 | tr { 278 | display: table-row 279 | } 280 | 281 | table th, table td { 282 | font-size: 1.1em; 283 | line-height: 1.3; 284 | padding: .5em 1em 0 285 | } 286 | 287 | table thead { 288 | background: rgba(0, 0, 0, 0.15); 289 | border: 1px solid rgba(0, 0, 0, 0.15); 290 | border-bottom: 1px solid rgba(0, 0, 0, 0.2) 291 | } 292 | 293 | table tbody { 294 | background: rgba(0, 0, 0, 0.05) 295 | } 296 | 297 | table tfoot { 298 | background: rgba(0, 0, 0, 0.15); 299 | border: 1px solid rgba(0, 0, 0, 0.15); 300 | border-top: 1px solid rgba(0, 0, 0, 0.2) 301 | } 302 | 303 | figure { 304 | display: inline-block; 305 | overflow: hidden; 306 | position: relative; 307 | margin: 1em 0 2em 308 | } 309 | 310 | figcaption { 311 | font-style: italic; 312 | text-align: center; 313 | background: white; 314 | color: #666 315 | } 316 | 317 | .poetry pre { 318 | display: block; 319 | font-family: Georgia, Garamond, serif !important; 320 | font-size: 110% !important; 321 | font-style: italic; 322 | line-height: 1.6em; 323 | margin-left: 1em 324 | } 325 | 326 | .poetry pre code { 327 | font-family: Georgia, Garamond, serif !important; 328 | word-break: break-all; 329 | word-break: break-word; 330 | -webkit-hyphens: auto; 331 | -moz-hyphens: auto; 332 | hyphens: auto; 333 | white-space: pre-wrap 334 | } 335 | 336 | blockquote p { 337 | 338 | } 339 | 340 | sup, sub, a.footnote { 341 | font-size: 1.4ex; 342 | height: 0; 343 | line-height: 1; 344 | position: relative; 345 | vertical-align: super 346 | } 347 | 348 | sub { 349 | vertical-align: sub; 350 | top: -1px 351 | } 352 | 353 | p { 354 | font-size: 1.1429em; 355 | line-height: 1.72em; 356 | margin: 1.3125em 0 357 | } 358 | 359 | dt, th { 360 | font-weight: 700 361 | } 362 | 363 | table tr:nth-child(odd), table th:nth-child(odd), table td:nth-child(odd) { 364 | background: rgba(255, 255, 255, 0.06) 365 | } 366 | 367 | table tr:nth-child(even), table td:nth-child(even) { 368 | background: rgba(200, 200, 200, 0.25) 369 | } 370 | 371 | @media print { 372 | img, table, figure { 373 | page-break-inside: avoid 374 | } 375 | 376 | #wrapper { 377 | background: #fff; 378 | color: #303030; 379 | padding: 10px; 380 | position: relative; 381 | text-indent: 0 382 | } 383 | 384 | } 385 | 386 | 387 | /* critic markup – gray background and padding */ 388 | 389 | .critic.mkshowcomments .criticmarkup .criticcomment { 390 | background: #e6e6e6 !important; 391 | color: black; 392 | padding-left: 0.5em; 393 | padding-right: 0.5em; 394 | } 395 | 396 | .critic.inverted.mkshowcomments .criticmarkup .criticcomment { 397 | background: #881c1c !important; 398 | opacity: 1; 399 | color: black; 400 | padding-left: 0.5em; 401 | padding-right: 0.5em; 402 | } 403 | 404 | 405 | @media screen { 406 | .inverted { 407 | background: #252a2a 408 | } 409 | 410 | .inverted #wrapper { 411 | background: #252a2a; 412 | color: #eee 413 | } 414 | 415 | .inverted hr { 416 | border-color: #333f40 !important 417 | } 418 | 419 | .inverted p, .inverted td, .inverted li, .inverted h1, .inverted h2, .inverted h3, .inverted h4, .inverted h5, .inverted h6, .inverted th, .inverted .math, .inverted caption, .inverted dt, .inverted dd { 420 | color: #eee 421 | } 422 | 423 | .inverted pre { 424 | background: #ccc; 425 | color: #111 426 | } 427 | 428 | .inverted table { 429 | background: none 430 | } 431 | 432 | .inverted table tr:nth-child(odd), .inverted table td:nth-child(odd) { 433 | background: none 434 | } 435 | 436 | 437 | ::selection { 438 | background: rgba(157, 193, 200, 0.5) 439 | } 440 | 441 | h1::selection { 442 | background-color: rgba(45, 156, 208, 0.3) 443 | } 444 | 445 | h2::selection { 446 | background-color: rgba(90, 182, 224, 0.3) 447 | } 448 | 449 | h3::selection, h4::selection, h5::selection, h6::selection, li::selection, ol::selection { 450 | background-color: rgba(133, 201, 232, 0.3) 451 | } 452 | 453 | code::selection { 454 | background-color: rgba(0, 0, 0, 0.7); 455 | color: #eee 456 | } 457 | 458 | code span::selection { 459 | background-color: rgba(0, 0, 0, 0.7) !important; 460 | color: #eee !important 461 | } 462 | 463 | a::selection { 464 | background-color: rgba(255, 230, 102, 0.2) 465 | } 466 | 467 | .inverted a::selection { 468 | background-color: rgba(255, 230, 102, 0.6) 469 | } 470 | 471 | td::selection, th::selection, caption::selection { 472 | background-color: rgba(180, 237, 95, 0.5) 473 | } 474 | 475 | } 476 | 477 | .mkstyle--swiss #wrapper aside.blurb:before { 478 | margin-top: .7em 479 | } 480 | 481 | 482 | .synopsis { 483 | /* width: 300px; */ 484 | border: 15px solid rgba(0, 0, 0, 0.25); 485 | padding: 50px; 486 | margin: 20px; 487 | } 488 | 489 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Zettel Composer 2 | 3 | A tool for combining notes in a "Zettelkasten" system based on Markdown and wiki links. 4 | 5 | ## Installation 6 | 7 | Clone the project in a directory of your choosing (e. g. `~/GitHub`): 8 | 9 | ```shell 10 | mkdir -p ~/GitHub 11 | cd ~/GitHub 12 | clone https://github.com/brunocbr/zettel-composer.git 13 | ``` 14 | 15 | Link the script to a path from where it can be executed, e. g.: 16 | 17 | ```shell 18 | ln -s zettel-composer.py /usr/local/bin/zettel-compose 19 | ``` 20 | 21 | If you want to use Marked Streaming Preview, you have to install the Python Objective-C bridge: 22 | 23 | ```shell 24 | pip install -U pyobjc 25 | ``` 26 | 27 | ## Basic features 28 | 29 | The script takes as its argument the name of a file which will be used as an `index` note. Wiki links prepended with a section sign (`§ [[1234]]`) in the index will produce the combination of the corresponding notes in the output: 30 | 31 | ```sh 32 | ~/GitHub/zettel-composer/zettel-compose.py "~/archive/2345 My index note.markdown" 33 | ``` 34 | 35 | With the above command, the script will simply print the combined notes and quit. You can though get a live preview using [Marked 2](https://marked2app.com/) and telling the script to keep watching the files for changes: 36 | 37 | ```sh 38 | ~/GitHub/zettel-composer/zettel-compose.py --watch --stream-to-marked "~/archive/2345 My index note.markdown" 39 | ``` 40 | 41 | The `index` note will control the order in which notes will be printed. It is recommended that you include all the relevant notes in the index, e. g. in an outline (but the script will also include others as it finds references while scanning the notes). 42 | 43 | Often when working with "Zettelkasten" notes, you'll want to make cross references to notes not necessarily intended for "public" consumption. This is why the default behaviour is to only reference and print notes using a non-standard notation of wiki links prefixed by the section mark (this character can usually be typed with `⌥ 6` on the mac, `C-x 8 S` in emacs): 44 | 45 | ``` 46 | This is a reference to § [[1234]]. 47 | ``` 48 | 49 | You can override the default behaviour with the `--link-all` option if you want to print notes referenced with "standard" wiki links. 50 | 51 | There's also a notation for references that necessarily will not be printed, even with the above option. It consists in a wiki link at the very beginning of a line, followed by a colon: 52 | 53 | ``` 54 | [[1234]]: This develops some thoughts from a cross-referenced note that should never be printed. 55 | ``` 56 | 57 | Other special conventions are available for working with quotes and pandoc citations (see below). 58 | 59 | By default, the script will threat every separate note as a "section" or "paragraph" and number them sequentially (`1.`, `2.`, `3.`). They can always be cross referenced with the `§ [[1234]]` notation (which yields `(§1)`, `(§2)`, `(§3)` etc. in the output). 60 | 61 | Markdown headings in the beginning of the notes will be accomodated before the paragraph numbers, so that you can, e. g., break the output in different chapters and sections. You can also suppress paragraph headings by calling the script with the `-n` option. 62 | 63 | Footnote references will be adapted to avoid duplication. 64 | 65 | ### Basic parameters 66 | 67 | | Parameter | Description | 68 | |-------------------------------|----------------------------------------| 69 | | `-S`, `--suppress-index` | Do not print the `index` note. | 70 | | `-W`, `--watch` | Don't quit, watch files for changes. | 71 | | `-M`, `--stream-to-marked` | Stream to Marked 2. | 72 | | `-O`, `--output=` *file name* | Specify *file name* as the output. | 73 | | `-v` | Verbose mode. | 74 | | `-X` | Extract mode: only print the note ids. | 75 | 76 | 77 | ### Some tweaks 78 | 79 | | Parameter | Description | 80 | |----------------------------------------|--------------------------------------------------------------------------------------------------------------------------| 81 | | `--link-all` or `-L` | Link and print all wiki linked notes, even if not prefixed by `§`. | 82 | | `-n`, `--no-paragraph-headings` | Do not print paragraph headings (`1.`, `2.`, `3.` etc.) | 83 | | `--no-separator` | Do not separate notes in the output with a horizontal bar. | 84 | | `-I` | Only include notes linked from the `index` note. References found in children notes will not be printed. | 85 | | `--custom-url=` *string* | A custom URL prepended to IDs in order to create links inside the CriticMarkup comments. Default: `thearchive://match/`. | 86 | | `-C`, `--no-commented-references` | Disable CriticMarkup comments. | 87 | | `-s`, `--sleep-time=` *seconds* | How long to "sleep" between file watching cycles. Default is 2 seconds. | 88 | | `-H`, `--heading-identifier=` *string* | | 89 | | `--section-symbol=` *string* | Set symbol used in the output to print references to sections/paragraphs. Default is `§`. | 90 | | `--no-title` | Do not create headings out of a note's `title` field | 91 | | `--no-front-matter` | Do not print the YAML front-matter from the index note. | 92 | 93 | 94 | ## Advanced features 95 | ### Quotes and text fragments ### 96 | 97 | 98 | You may create a note (`1235` in this example) containing but a quote or fragment of text. You can then quote its actual contents inside another note in a line like the one below: 99 | 100 | ``` 101 | > [[1235]] 102 | ``` 103 | 104 | 105 | This is very useful if you do translations, as you may work with them in notes separated from the text where they are to be included (e. g. a paper, lecture notes). You can also create handouts from the very same note, using the handout option (`-h`). 106 | 107 | The quote will receive a sequential numerical identification (`T1`, `T2`, `T3` etc.) and may be later referenced[^2] (wiki links will be transformed in `T1`, `T2`, `T3` etc.). 108 | 109 | The quoted note's title is assumed to be a citation reference and will be printed either inside parentheses or in a heading (respectivelly in normal and handout modes)[^3]. 110 | 111 | If you just want to insert the contents of the body of a note[^1], without any special handling, you can use the following: 112 | 113 | ``` 114 | + [[1235]] 115 | ``` 116 | 117 | 118 | | Parameter | Description | 119 | | ---------- | ---------- | 120 | | `-t` *n* | Set the initial text number (`Tn`). | 121 | 122 | 123 | ### Handouts ### 124 | 125 | | Parameter | Description | 126 | | --------- | ---------- | 127 | | `-h` | Handout mode (only quotes will be printed). | 128 | | `-h+` | Also print section headings. | 129 | 130 | 131 | 132 | ### Parallel texts ### 133 | 134 | Bilingual passages may be inserted by designating "left" and "right" texts: 135 | 136 | ``` 137 | > [[1235]] :: [[1236]] 138 | ``` 139 | 140 | In normal mode, the "left" text will be printed first, followed by the "right" text (unless this behaviour is modified by `-G`). 141 | 142 | With option `-P`, proper parallel texts are rendered in `LaTeX` (via `pandoc`), the output requiring for later processing a `\ParallelTexts` macro that you should define e. g. in your pandoc template (making use of `reledpar` or other package). 143 | 144 | ```latex 145 | \ParallelTexts{% 146 | ... Left text ... 147 | }{% 148 | ... Right text ... 149 | } 150 | ``` 151 | 152 | | Parameter | Description | 153 | | --------- | ---------- | 154 | | `-G` *opt* | Choose which texts(s) to print. *opt* should be `l`, `r` or `lr` (default). | 155 | | `-P` | Render parallel texts in LaTeX. | 156 | 157 | 158 | ### Pandoc citations ### 159 | 160 | Notes may have bibliographical metadata in their frontmatter: 161 | 162 | ``` 163 | --- 164 | citekey: Author1999 165 | loc: 12-45 166 | ... 167 | ``` 168 | 169 | This information can be used elsewhere, creating pandoc-style citations by making a refence to the notes with `@ [[1234]]` (parenthetical citation), `-@ [[1234]]` (publication year), `@@ [[1233]]` (inline citation). 170 | 171 | 172 | ## Use-Cases 173 | 174 | You can create a shell script with preconfigured parameters for the `Zettel Composer`, passing the `index` file name as an argument. The examples below will assume this setup. 175 | 176 | Tip: If you are on the mac, you may use scripts like these with the `Automator`, creating applications. You may then use those applications to open your `index` notes from your preferred editor (such as [The Archive](https://zettelkasten.de/the-archive/) or [nvAlt](https://brettterpstra.com/projects/nvalt/)). 177 | 178 | 179 | Case 1: given a structure note, browse all wiki linked notes in Marked. This is very useful e. g. with a structure note related to annotations of a book, containing links for the individual chapter/section notes. 180 | 181 | ```bash 182 | #!/bin/bash 183 | open -a "Marked 2" 184 | $HOME/GitHub/zettel-composer/zettel-compose.py -L --stream-to-marked "${1}" 185 | ``` 186 | 187 | Case 2: Continuously generate a handout, while at the same time having a live preview: 188 | 189 | ```bash 190 | open -a "Marked 2" 191 | pkill -f zettel-compose.py 192 | $HOME/GitHub/zettel-composer/zettel-compose.py -W -h+ -P -O "$HOME/Downloads/Handout.md" "${1}" & 193 | $HOME/GitHub/zettel-composer/zettel-compose.py -W --stream-to-marked -h+ "${1}" 194 | ``` 195 | 196 | You can use `Handout.md` as input for some other process, like converting it to PDF with `LaTeX` and `pandoc`. 197 | 198 | Case 3: Compose a book consisting of many chapters distributed in different notes, but don't print the index itself. The output will be later processed with `LaTeX`, which will take care of creating a table of contents: 199 | 200 | ```bash 201 | OUT=$HOME/Documents/My-Book.md 202 | $HOME/GitHub/zettel-composer/zettel-compose.py -S -I -n --no-separator -O "${OUT}" "${1}" 203 | ``` 204 | 205 | 206 | [^1]: I speak of the "body" of a note because the script will recognize a YAML frontmatter and certain field declarations inside it, such as `title:`, `citekey:` or `loc:` (for the later fields, see below). 207 | 208 | 209 | [^2]: The script doesn't currently support forwarding linking. 210 | 211 | [^3]: I suggest that you use underline to format a note title, and avoid asterisks, e. g. `1234 PLATO. _Timaeus_, 29c.markdown`. 212 | -------------------------------------------------------------------------------- /zettel-compose.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # zettel-compose.py 5 | # by Bruno L. Conte <bruno@brunoc.com.br>, 2020-2022 6 | 7 | import re 8 | from glob import glob 9 | from collections import OrderedDict 10 | import os, time, sys, getopt 11 | import hashlib 12 | 13 | KEY_CITEKEY = 'citekey' 14 | KEY_LOCATION = 'loc' 15 | 16 | CF_PANDOC ='pandoc' 17 | 18 | STR_UNINDEXED_HEADING = '# Unindexed' 19 | STR_STREAMING_ID = "<!--\nzettel-compose.py\n-->\n" 20 | STR_SIGN_INSERT = ' ▼ ' # = '▾ ' 21 | STR_SIGN_COMMENT = ' ► ' # = '❧ ' = '▹ ' 22 | STR_HANDOUT_HEADING = '####' 23 | SEPARATOR = [ '\n', '-----', '\n' ] 24 | 25 | options = { 26 | 'output': None, 27 | 'no-commented-references': False, 28 | "no-paragraph-headings": False, 29 | "heading-identifier": "paragraph-", 30 | "watch": False, 31 | "sleep-time": 2, 32 | "suppress-index": False, 33 | "only-link-from-index": False, 34 | "verbose": False, 35 | "stream-to-marked": False, 36 | 'parallel-texts-processor': None, 37 | 'parallel-texts-selection': 'lr', 38 | 'no-separator': False, 39 | 'handout-mode': False, 40 | 'handout-with-sections': True, 41 | 'link-all': False, # link normal wikilinks 42 | 'custom-url': 'thearchive://match/', 43 | 'section-symbol': '§', 44 | 'no-title': False, 45 | 'insert-bib-ref': False, 46 | 'no-front-matter': False, 47 | 'extract-mode': False 48 | } 49 | 50 | rx_dict = OrderedDict([ 51 | ('ignore', re.compile(r'^(△|○)')), 52 | ('footnote', re.compile(r'\[\^(?P<fn_id>[a-zA-Z0-9_-]+)]')), 53 | ('parallel_texts', re.compile(r' *>\s{0,1} *\[\[(?P<id_left>\d{3,})\]\] *:: *\[\[(?P<id_right>\d{3,})\]\]')), # > [[dddd]] :: [[dddd]] 54 | ('pandoc_cite_noauthor', re.compile(r'-@ *\[\[(?P<id>\d{3,})\]\]')),# -@ [[dddd]] 55 | ('pandoc_cite_inline', re.compile(r'@@ *\[\[(?P<id>\d{3,})\]\]')), # @@ [[dddd]] 56 | ('pandoc_cite', re.compile(r'@ *\[\[(?P<id>\d{3,})\]\]')), # @ [[dddd]] 57 | ('no_ref', re.compile(r'- *\[\[(?P<id>\d{3,})\]\]')), # - [[dddd]] do not add note 58 | ('quote', re.compile(r' *>\s{0,1}\[\[(?P<id>\d{3,})\]\]')), # > [[dddd]] insert quote immediately 59 | ('add_ref', re.compile(r'\+ *\[\[(?P<id>\d{3,})\]\]')), # + [[dddd]] insert note immediately 60 | ('link', re.compile(r'§ *\[\[(?P<id>\d{3,})\]\]')), # § [[dddd]] print reference to paragraph or text 61 | ('cross_ref_alt', re.compile(r'\[\[(?P<id>\d{3,})\]\] *:')), # [[dddd]] : hidden cross reference 62 | ('cross_ref', re.compile(r'\s*\[\[(?P<id>\d{3,})\]\]')), # [[dddd]] hidden cross reference 63 | ('yaml_end_div', re.compile(r'^\.\.\.$')), 64 | ('yaml_div', re.compile(r'^\-\-\-$')), 65 | ('md_heading', re.compile(r'^#{1,4}[\s\w]')), 66 | ('title', re.compile(r"^title:\s*['\"](?P<id>.*)['\"]\s*$")) 67 | ]) 68 | 69 | fields_dict = { 70 | "citekey": re.compile(r'^' + KEY_CITEKEY + r':[ \t]*(?P<id>[A-Za-z\d:]+)\s*$'), 71 | # "loc": re.compile(r'^' + KEY_LOCATION + r':[ \t]*(?P<id>[\d-]+)\s*$') 72 | "loc": re.compile(r'^' + KEY_LOCATION + r':[ \t]*(?P<id>[\S]+)\s*$') 73 | } 74 | 75 | def _initialize_stack(): 76 | global z_count, z_stack, z_map, unindexed_links 77 | z_count = { "index": 0, "body": 0, "quote": 0, "sequential": 0, "citation": 0, "left_text": 0, "right_text": 0 } 78 | z_stack = [] 79 | z_map = {} # maps zettel id's to paragraph or sequence 80 | unindexed_links = [] 81 | 82 | def _z_get_filepath(zettel_id): 83 | """ 84 | Get file path for a note 85 | """ 86 | global zettel_dir, index_filename 87 | 88 | try: 89 | if (zettel_id == "index"): 90 | fn = index_filename 91 | else: 92 | fn = glob(zettel_dir + "/" + zettel_id + "[ \.]*")[0] 93 | mtime = os.path.getmtime(fn) 94 | except: 95 | print("ERROR: file not found for zettel " + zettel_id) 96 | fn, mtime = None, None 97 | return fn, mtime 98 | 99 | def _get_file_md5digest(pathname): 100 | md5_hash = hashlib.md5() 101 | 102 | with open(pathname, "rb") as a_file: 103 | content = a_file.read() 104 | 105 | md5_hash.update(content) 106 | digest = md5_hash.hexdigest() 107 | 108 | return digest 109 | 110 | def _z_set_index(pathname): 111 | global z_map, z_stack 112 | mtime = os.path.getmtime(pathname) 113 | md5hash = _get_file_md5digest(pathname) 114 | z_map["index"] = { "type": "index", "ref": 0, "path": pathname, "mtime": mtime, "md5hash": md5hash } 115 | if len(z_stack) == 0: 116 | z_stack.append("index") 117 | 118 | def _z_add_to_stack(zettel_id, z_type): 119 | """ 120 | Add a note to stack if not already in it 121 | """ 122 | global z_count 123 | global z_stack 124 | 125 | if not zettel_id in z_map: 126 | if z_type in ['left_text', 'right_text']: 127 | z_ref_type = 'quote' # counts as quote for numbering texts 128 | else: 129 | z_ref_type = z_type 130 | if z_type != 'right_text': # right texts don't increment the counter, buy may be referenced 131 | z_count[z_ref_type] += 1 132 | path, mtime = _z_get_filepath(zettel_id) 133 | md5hash = _get_file_md5digest(path) 134 | z_map[zettel_id] = { "type": z_type, "ref": z_count[z_ref_type], "path": path, "mtime": mtime, "md5hash": md5hash } 135 | if z_type in [ 'body', 'index', 'quote', 'citation', 'sequential', 'left_text', 'right_text' ]: 136 | z_stack.append(zettel_id) 137 | return z_map[zettel_id] 138 | 139 | def _out_link(ref, id): 140 | """ 141 | Formatted output for link to a reference 142 | """ 143 | global options 144 | if options["no-paragraph-headings"]: 145 | return " {>> [[" + str(id) + "]] <<}" 146 | else: 147 | if options["heading-identifier"]: 148 | return " ([" + options['section-symbol'] + str(ref) + "](#" + options["heading-identifier"] + str(ref) + "))" 149 | else: 150 | return " (" + options['section-symbol'] + str(ref) + ")" 151 | 152 | def _out_linked_zettel(id, anchor): 153 | return '[' + anchor + '](' + options['custom-url'] + str(id) + ')' 154 | 155 | def _out_quoteref(ref, id): 156 | """ 157 | Formatted output for text reference 158 | """ 159 | return "T" + str(ref) 160 | 161 | def _out_paragraph_heading(ref, zettel_id): 162 | """ 163 | Formatted output for a paragraph heading 164 | """ 165 | global options 166 | if options["no-paragraph-headings"]: 167 | return _out_commented_id(zettel_id) 168 | else: 169 | if options["heading-identifier"]: 170 | return "#### " + str(ref) + '. ' + _out_commented_id(zettel_id, pre=STR_SIGN_INSERT) + " {#" + options["heading-identifier"] + str(ref) + "}" 171 | else: 172 | return "#### " + str(ref) + '. ' 173 | 174 | def _out_commented_id(zettel_id, pre = "", post=""): 175 | """ 176 | Formatted output for [[id]] 177 | """ 178 | if options['no-commented-references']: 179 | return '' 180 | else: 181 | return ' {>> ' + _out_linked_zettel(zettel_id, pre) + post + ' <<}' 182 | 183 | def _out_text_quote(ref, zettel_id): 184 | """ 185 | Formatted output for quote preamble 186 | """ 187 | return '> ' + _out_commented_id(zettel_id, pre=STR_SIGN_INSERT) + ' **T' + str(ref) + ':** ' 188 | 189 | def _out_unindexed_notes(): 190 | output = [ STR_UNINDEXED_HEADING, "", ""] 191 | for n in unindexed_links: 192 | base = os.path.basename(_z_get_filepath(n)[0]) 193 | output.append(os.path.splitext(base)[0] + " " + _out_link(z_map[n]['ref'], n) + ".") 194 | return output 195 | 196 | def _out_latex_parallel_texts(left_text, right_text): 197 | import subprocess 198 | 199 | CMD = [CF_PANDOC, '-f', 'markdown', '-t', 'latex'] 200 | 201 | ps = subprocess.Popen(CMD,stdin=subprocess.PIPE,stdout=subprocess.PIPE,encoding="utf-8") 202 | left_text = (ps.communicate(input='\n'.join(left_text))[0]).splitlines() 203 | 204 | ps = subprocess.Popen(CMD,stdin=subprocess.PIPE,stdout=subprocess.PIPE,encoding="utf-8") 205 | right_text = (ps.communicate(input="\n".join(right_text))[0]).splitlines() 206 | 207 | output = ['\ParallelTexts{%'] + left_text + ['}{%'] + right_text + ['}'] + [''] 208 | return output 209 | 210 | def _out_parallel_texts(left, right): 211 | left_data = parse_zettel(z_map[left], left) 212 | right_data = parse_zettel(z_map[right], right) 213 | output = [] 214 | if not options['handout-mode']: # qual será o padrão? esperar quotes nas fichas ou não? 215 | if ('l' in options['parallel-texts-selection']): 216 | output.append(_out_text_quote(z_map[left]["ref"], left)) 217 | output = output + left_data 218 | else: 219 | output.append(_out_text_quote(z_map[right]["ref"], right)) 220 | if ('r' in options['parallel-texts-selection']): 221 | output.append('> ') 222 | if ('l' in options['parallel-texts-selection']): 223 | output.append("> " + _out_commented_id(right, pre=STR_SIGN_INSERT) + ' ') 224 | output = output + right_data 225 | else: 226 | output.append(STR_HANDOUT_HEADING + ' ' + z_map[right]['title']) 227 | output.append('') 228 | if not options['parallel-texts-processor']: 229 | output = output + left_data + ['\n'] + right_data 230 | else: 231 | output = output + _out_latex_parallel_texts(left_data, right_data) 232 | 233 | return output 234 | 235 | def _parse_line(line, thedict): 236 | l = [ ] 237 | for key, rx in thedict.items(): 238 | match = rx.search(line) 239 | if match: 240 | l.append((key, match)) 241 | if l: 242 | r = sorted(l, key=lambda x: x[1].start())[0] 243 | return r[0], r[1], r[1].end() 244 | else: 245 | return None, None, None 246 | 247 | def _remove_md_quotes(line): 248 | rx = re.compile(r'^\s*>\s*') 249 | match = rx.search(line) 250 | if match: 251 | line = rx.sub("", line) 252 | return line 253 | 254 | def _md_quote(line): 255 | line = _remove_md_quotes(line) 256 | line = '> ' + line 257 | return line 258 | 259 | 260 | def _pandoc_citetext(zettel_id): 261 | """ 262 | Get reference for pandoc-style citation 263 | """ 264 | global fields_dict 265 | citekey = None 266 | loc = None 267 | filepath, mtime = _z_get_filepath(zettel_id) 268 | 269 | with open(filepath, 'r') as file_obj: 270 | lines = file_obj.read().splitlines() 271 | 272 | for line in lines: 273 | key, match, end = _parse_line(line, fields_dict) 274 | if key == "citekey": 275 | citekey = match.group('id') 276 | if key == "loc": 277 | loc = match.group('id') 278 | 279 | citetext = None 280 | if (citekey and loc and loc != "0"): 281 | citetext = citekey + ", " + loc 282 | elif (citekey): 283 | citetext = citekey 284 | return citetext 285 | 286 | def _pandoc_cite(zettel_id, parenthetical = True): 287 | citetext = _pandoc_citetext(zettel_id) 288 | if citetext and parenthetical: 289 | return "[@" + citetext + "]" + _out_commented_id(zettel_id, pre=STR_SIGN_COMMENT) 290 | elif citetext: 291 | return "@" + citetext + _out_commented_id(zettel_id, pre=STR_SIGN_COMMENT) 292 | 293 | def _pandoc_cite_noauthor(zettel_id): 294 | citetext = _pandoc_citetext(zettel_id) 295 | if citetext: 296 | return "[-@" + citetext + "]" + _out_commented_id(zettel_id, pre=STR_SIGN_COMMENT) 297 | 298 | def parse_zettel(z_item, zettel_id): 299 | global options, z_map, unindexed_links 300 | 301 | filepath = z_item["path"] 302 | 303 | yaml_divert = False 304 | got_content = False 305 | got_title = False 306 | insert_sequence = [] 307 | data = [] 308 | frontmatter = [] 309 | 310 | def parse_chunk(chunk): 311 | key, match, end = _parse_line(chunk, rx_dict) 312 | 313 | if (key is None): 314 | return chunk 315 | 316 | left_chunk = chunk[:end] 317 | 318 | if key == 'quote': 319 | link = match.group('id') 320 | insert_quotes.append(link) 321 | left_chunk = rx_dict["quote"].sub("", left_chunk) 322 | 323 | elif key == 'parallel_texts': 324 | left_link, right_link = match.group('id_left'), match.group('id_right') 325 | insert_parallel_texts.append((left_link, right_link)) 326 | left_chunk = rx_dict['parallel_texts'].sub("", left_chunk) 327 | 328 | elif key == 'pandoc_cite': 329 | link = match.group('id') 330 | _z_add_to_stack(link, "citation") 331 | left_chunk = rx_dict["pandoc_cite"].sub(_pandoc_cite(link), left_chunk) 332 | 333 | elif key == 'pandoc_cite_inline': 334 | link = match.group('id') 335 | _z_add_to_stack(link, "citation") 336 | left_chunk = rx_dict["pandoc_cite_inline"].sub(_pandoc_cite(link, parenthetical = False), left_chunk) 337 | 338 | elif key == 'pandoc_cite_noauthor': 339 | link = match.group('id') 340 | _z_add_to_stack(link, "citation") 341 | left_chunk = rx_dict["pandoc_cite_noauthor"].sub(_pandoc_cite_noauthor(link), left_chunk) 342 | 343 | elif key == 'add_ref': 344 | link = match.group('id') 345 | insert_sequence.append(link) 346 | left_chunk = rx_dict["add_ref"].sub("", left_chunk) 347 | 348 | elif (key == 'link') or (options['link-all'] and (key == 'cross_ref')): 349 | link = match.group('id') 350 | if (link in z_map) and (z_map[link]["type"] in ['quote', 'left_text', 'right_text']): 351 | left_chunk = rx_dict["link"].sub(_out_quoteref(z_map[link]["ref"], link), left_chunk) 352 | elif (z_item["type"] not in [ "citation" ]) and ((z_item["type"] == "index") or (options["only-link-from-index"] is not True)): 353 | if (link not in z_map) and (z_item["type"] not in [ "index", "sequential" ]): 354 | unindexed_links.append(link) 355 | _z_add_to_stack(link, "body") 356 | left_chunk = rx_dict[key].sub(_out_link(z_map[link]["ref"], link), left_chunk) 357 | else: 358 | left_chunk = rx_dict[key].sub(_out_commented_id(link), left_chunk) 359 | 360 | elif key in [ 'cross_ref', 'cross_ref_alt' ]: 361 | link = match.group('id') 362 | left_chunk = rx_dict[key].sub(_out_commented_id(link, pre=STR_SIGN_COMMENT), left_chunk) 363 | 364 | elif key == 'no_ref': 365 | link = match.group('id') 366 | left_chunk = rx_dict["no_ref"].sub(_out_commented_id(link), left_chunk) 367 | 368 | elif key == 'footnote': 369 | fn_id = match.group('fn_id') 370 | left_chunk = rx_dict['footnote'].sub("[^fn-" + zettel_id + "-" + fn_id + "]", left_chunk) 371 | 372 | 373 | 374 | return left_chunk + parse_chunk(chunk[end:]) 375 | 376 | with open(filepath, 'r') as file_object: 377 | lines = file_object.read().splitlines() 378 | 379 | zettel_title = 'Untitled' 380 | for line in lines: 381 | insert_quotes = [] 382 | insert_parallel_texts = [] 383 | insert_sequence = [] 384 | # at each line check for a match with a regex 385 | key, match, end = _parse_line(line, rx_dict) 386 | 387 | if yaml_divert: 388 | yaml_divert = not key in ["yaml_div", "yaml_end_div"] 389 | if key == 'title': 390 | zettel_title = match.group('id') 391 | z_item['title'] = zettel_title 392 | frontmatter.append(line) 393 | continue 394 | 395 | if key == "yaml_div": 396 | yaml_divert = True 397 | frontmatter.append(line) 398 | continue 399 | 400 | if key == "ignore": 401 | continue 402 | 403 | # if the first content in a note is a heading, then insert 404 | # our paragraph heading after, not before it 405 | 406 | if (key == "md_heading") and not got_content: 407 | if (z_item["type"] != "quote" and ((not options['handout-mode']) or options['handout-with-sections'])): # headings in citation notes are ~~for handouts only~~ good for nothing 408 | data.append(line) 409 | data.append('') 410 | got_title = True 411 | got_content = False 412 | continue 413 | 414 | if (not line == '') and not got_content: 415 | if not got_title: 416 | if not options['no-title'] and not z_item["type"] in ['quote', 'left_text', 'right_text']: # insert note title as ATX heading unless it's a quote 417 | data.append("## " + zettel_title) 418 | got_title = True 419 | if (not options['handout-mode']): 420 | if (z_item["type"] == "body"): 421 | data.append(_out_paragraph_heading(z_item["ref"], zettel_id)) 422 | elif (z_item["type"] == "quote"): 423 | data.append(_out_text_quote(z_item["ref"], zettel_id)) 424 | elif (z_item["type"] in [ 'sequential' ]): 425 | data.append(_out_commented_id(zettel_id, pre=STR_SIGN_INSERT)) 426 | elif (z_item['type'] in ['quote']): # headings in handout before content 427 | data.append(STR_HANDOUT_HEADING + ' ' + zettel_title) 428 | data.append(_out_commented_id(zettel_id, pre=STR_SIGN_INSERT)) 429 | elif (z_item['type'] in ['left_text', 'right_text']) and not options['no-commented-references']: 430 | data.append(_out_commented_id(zettel_id, pre=STR_SIGN_INSERT)) 431 | got_content = True 432 | 433 | if got_content: 434 | if options['handout-mode']: 435 | if key == 'md_heading' and options['handout-with-sections']: 436 | data.append('') # prepend a line for safety reasons 437 | data.append(line) 438 | data.append('') 439 | else: 440 | line = parse_chunk(line) 441 | if z_item['type'] in ['left_text', 'right_text', 'quote']: 442 | line = _remove_md_quotes(line) 443 | data.append(line) 444 | else: 445 | line = parse_chunk(line) 446 | if (z_item['type'] in ['quote', 'left_text', 'right_text']): # enforce quotes when not printing handouts 447 | line = _md_quote(line) 448 | data.append(line) 449 | 450 | if insert_sequence is not []: 451 | for i in insert_sequence: 452 | _z_add_to_stack(i, "sequential") 453 | data = data + ['\n'] + parse_zettel(z_map[i], i) 454 | 455 | if insert_quotes is not []: 456 | for i in insert_quotes: 457 | _z_add_to_stack(i, "quote") # add to stack... 458 | insert_data = parse_zettel(z_map[i], i) 459 | data = data + ['\n'] + insert_data # ...but insert immediately after line 460 | 461 | if insert_parallel_texts is not []: 462 | for l, r in insert_parallel_texts: 463 | _z_add_to_stack(l, 'left_text') 464 | _z_add_to_stack(r, 'right_text') 465 | insert_data = _out_parallel_texts(l, r) 466 | data = data + ['\n'] + insert_data 467 | 468 | if (z_item['type'] in ['right_text']) and not options['handout-mode']: 469 | while (data[-1] == '\n'): 470 | del data[-1] # remove trailing lines 471 | data[-1] = data[-1] + ' (' + zettel_title + ')' # add reference to last line in quote 472 | elif options['insert-bib-ref']: 473 | citetxt = _pandoc_citetext(zettel_id) 474 | if citetxt: 475 | data.append('') 476 | data.append("@" + citetxt) 477 | 478 | if z_item['type'] == 'index': 479 | if options['suppress-index']: 480 | if not options['no-front-matter']: 481 | data = frontmatter 482 | else: 483 | data = [] 484 | elif not options['no-front-matter']: 485 | data = frontmatter + data 486 | 487 | return data 488 | 489 | def check_module_exists(module_name): 490 | try: 491 | if sys.version_info[0] >= 3: 492 | # Python 3: use importlib for checking installed modules 493 | import importlib 494 | importlib.import_module(module_name) 495 | else: 496 | # Python 2: use __import__ for compatibility 497 | __import__(module_name) 498 | return True 499 | except ImportError: 500 | return False 501 | 502 | 503 | 504 | def appkit_available(): 505 | return check_module_exists('AppKit') 506 | 507 | def stream_to_marked(data): 508 | from AppKit import NSPasteboard 509 | 510 | if options["verbose"]: 511 | print("Streaming...") 512 | 513 | pb = NSPasteboard.pasteboardWithName_("mkStreamingPreview") 514 | pb.clearContents() 515 | 516 | # TODO: testar se este decode é necessário apenas no 2.7 517 | if sys.version_info[0] < 3: 518 | data = data.decode('utf8') 519 | pb.setString_forType_(data, 'public.utf8-plain-text') 520 | 521 | def get_first_modified(): 522 | global z_stack 523 | global z_map 524 | c = 0 525 | result = None 526 | while (not result and c < len(z_stack)): 527 | cur_path, cur_mtime = _z_get_filepath(z_stack[c]) 528 | if cur_mtime != z_map[z_stack[c]]["mtime"]: 529 | md5hash = _get_file_md5digest(cur_path) 530 | if md5hash != z_map[z_stack[c]]["md5hash"]: 531 | result = c 532 | z_map[z_stack[c]]["path"], z_map[z_stack[c]]["mtime"] = cur_path, cur_mtime # update modified filenames and mtimes 533 | c += 1 534 | return result 535 | 536 | def parse_index(pathname): 537 | global z_stack, z_map, options, unindexed_links 538 | 539 | c = 0 540 | parse_index.output = [ ] # [ STR_STREAMING_ID ] not working? 541 | 542 | parse_index.f_out = None 543 | 544 | def write_to_output(contents, zn=None): 545 | if not options['no-separator']: 546 | contents = contents + SEPARATOR 547 | if parse_index.f_out: 548 | if options['extract-mode']: 549 | if (zn not in [ None, 'index' ]): 550 | parse_index.f_out.write("%s\n" % zn) 551 | else: 552 | for l in contents: 553 | parse_index.f_out.write("%s\n" % l) 554 | if options["stream-to-marked"]: 555 | parse_index.output = parse_index.output + contents 556 | 557 | _z_set_index(pathname) 558 | 559 | if options["output"] and (options["output"] != '-'): 560 | parse_index.f_out = open(options["output"], "w") 561 | elif not options["stream-to-marked"]: 562 | parse_index.f_out = sys.stdout 563 | 564 | while len(z_stack) > c: 565 | if options["verbose"]: 566 | print ("zettel id " + z_stack[c]) 567 | if z_map[z_stack[c]]['type'] not in [ 'quote', 'citation', 'left_text', 'right_text' ]: 568 | d = parse_zettel(z_map[z_stack[c]], z_stack[c]) + [''] 569 | if (z_map[z_stack[c]]["type"] not in [ "sequential" ]): 570 | write_to_output(d, z_stack[c]) 571 | c += 1 572 | 573 | if unindexed_links and not options['extract-mode']: 574 | d = _out_unindexed_notes() 575 | write_to_output(d) 576 | 577 | if parse_index.f_out and (parse_index.f_out is not sys.stdout): 578 | parse_index.f_out.close() 579 | 580 | if options["stream-to-marked"]: 581 | stream_to_marked("\n".join(parse_index.output)) 582 | 583 | def watch_folder(): 584 | global z_stack, options 585 | 586 | while True: 587 | modified = get_first_modified() 588 | if modified is not None: 589 | if options["verbose"]: 590 | print("note " + str(modified) + " id " + z_stack[modified] + " was modified") 591 | time.sleep(1) 592 | _initialize_stack() 593 | parse_index(index_filename) 594 | time.sleep(options["sleep-time"]) 595 | 596 | useroptions, infile = getopt.getopt(sys.argv[1:], 'CO:MH:s:WnSIt:G:vh:PLX', [ 'no-commented-references', 597 | 'no-paragraph-headings', 'heading-identifier=', 'watch', 'sleep-time=', 'output=', 'stream-to-marked', 598 | 'suppress-index', 'no-separator', 'link-all', 'custom-url=', 'section-symbol=', 'no-title', 'insert-bib-ref', 599 | 'no-front-matter']) 600 | 601 | if infile == [ ]: 602 | raise ValueError("Argument is missing: you must provide a file name for the index note.") 603 | 604 | _initialize_stack() 605 | 606 | for opt, arg in useroptions: 607 | if opt in ('-O', '--output='): 608 | options["output"] = arg 609 | elif opt in ('-M', '--stream-to-marked'): 610 | if appkit_available(): 611 | options["stream-to-marked"] = True 612 | else: 613 | print("Warning: can't stream because the AppKit module is not available") 614 | elif opt in ('-H', '--heading-identifier='): 615 | options["heading-identifier"] = arg 616 | elif opt in ('-W', '--watch'): 617 | options["watch"] = True 618 | elif opt in ('-s', '--sleep-time='): 619 | options["sleep-time"] = arg 620 | elif opt in ('-n', '--no-paragraph-headings'): 621 | options["no-paragraph-headings"] = True 622 | elif opt in ('--no-separator'): 623 | options["no-separator"] = True 624 | elif opt in ('-C', '--no-commented-references'): 625 | options['no-commented-references'] = True 626 | elif opt in ('-S', '--suppress-index'): 627 | options["suppress-index"] = True 628 | elif opt in ('-I'): 629 | options["only-link-from-index"] = True 630 | elif opt in ('-t'): 631 | z_count["quote"] = (int(arg) - 1) 632 | elif opt in ('-G'): 633 | if ('l' not in arg) and ('r' not in arg): 634 | raise ValueError("-G should take either 'l' or 'r' as argument") 635 | options['parallel-texts-selection'] = arg 636 | elif opt in ('-v'): 637 | options["verbose"] = True 638 | elif opt in ('-h'): 639 | options['handout-mode'] = True 640 | options['handout-with-sections'] = ('+' in arg) 641 | elif opt in ('-P'): 642 | options['parallel-texts-processor'] = True 643 | options['no-commented-references'] = True 644 | elif opt in ('-L', '--link-all'): 645 | options['link-all'] = True 646 | elif opt in ('--custom-url='): 647 | options['custom-url'] = arg 648 | elif opt in ('--section-symbol='): 649 | options['section-symbol'] = arg 650 | elif opt in ('--no-title'): 651 | options['no-title'] = True 652 | elif opt in ('--insert-bib-ref'): 653 | options['insert-bib-ref'] = True 654 | elif opt in ('--no-front-matter'): 655 | options['no-front-matter'] = True 656 | elif opt in ('-X'): 657 | options['extract-mode'] = True 658 | 659 | index_filename = infile[0] 660 | if options["verbose"]: 661 | print("Processing file " + infile[0]) 662 | 663 | zettel_dir = os.path.dirname(index_filename) 664 | 665 | parse_index(index_filename) 666 | 667 | if options["watch"]: 668 | if options["verbose"]: 669 | print("Will now watch for changes") 670 | watch_folder() 671 | 672 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | <one line to give the program's name and a brief idea of what it does.> 635 | Copyright (C) <year> <name of author> 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see <https://www.gnu.org/licenses/>. 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | <program> Copyright (C) <year> <name of author> 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | <https://www.gnu.org/licenses/>. 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | <https://www.gnu.org/licenses/why-not-lgpl.html>. 675 | --------------------------------------------------------------------------------