Add the --check-for-nodes option, to help conversion from Chrysoberyl.
Chris Pressey
7 years ago
0 | 0 |
import os
|
|
1 |
import re
|
1 | 2 |
from time import sleep
|
2 | 3 |
import urllib
|
3 | 4 |
|
|
120 | 121 |
if delay_between_fetches > 0:
|
121 | 122 |
sleep(delay_between_fetches)
|
122 | 123 |
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 |
|
31 | 31 |
argparser.add_argument('--check-against-schema', metavar='FILENAME', type=str, default=None,
|
32 | 32 |
help='Check if entries have the properties specified by this schema. This schema will '
|
33 | 33 |
'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'
|
34 | 37 |
)
|
35 | 38 |
|
36 | 39 |
argparser.add_argument('--output-atom', metavar='FILENAME', type=str,
|
|
96 | 99 |
refdex = json.loads(f.read())
|
97 | 100 |
|
98 | 101 |
### 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)
|
99 | 109 |
|
100 | 110 |
if options.check_links or options.archive_links_to is not None:
|
101 | 111 |
from feedmark.checkers import archive_links
|