git @ Cat's Eye Technologies Feedmark / 1b711a5
Add the --check-for-nodes option, to help conversion from Chrysoberyl. Chris Pressey 7 years ago
2 changed file(s) with 31 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
00 import os
1 import re
12 from time import sleep
23 import urllib
34
120121 if delay_between_fetches > 0:
121122 sleep(delay_between_fetches)
122123 return failures
124
125
126 def accumulate_links(text, links):
127 for match in re.finditer(r'\[\[(.*?)\]\]', text):
128 link = match.group(1)
129 segments = link.split('|')
130 if len(segments) > 1:
131 links[segments[0]] = segments[1]
132 else:
133 links[link] = link
134
135
136 def check_for_nodes(documents):
137 links = {}
138 for document in documents:
139 accumulate_links('\n'.join(document.preamble), links)
140 for section in document.sections:
141 accumulate_links(section.body, links)
142 return links
143
3131 argparser.add_argument('--check-against-schema', metavar='FILENAME', type=str, default=None,
3232 help='Check if entries have the properties specified by this schema. This schema will '
3333 'also provide hints (such as ordering of properties) when outputting Markdown or HTML.'
34 )
35 argparser.add_argument('--check-for-nodes', action='store_true',
36 help='Check if entries contain any Chrysoberyl-style links to nodes'
3437 )
3538
3639 argparser.add_argument('--output-atom', metavar='FILENAME', type=str,
9699 refdex = json.loads(f.read())
97100
98101 ### processing
102
103 if options.check_for_nodes:
104 from feedmark.checkers import check_for_nodes
105 result = check_for_nodes(documents)
106 if result:
107 write(json.dumps(result, indent=4, sort_keys=True))
108 sys.exit(1)
99109
100110 if options.check_links or options.archive_links_to is not None:
101111 from feedmark.checkers import archive_links