|
55 | 55 | # Pattern to match reference links (to resolve internally-defined references). |
56 | 56 | P_INTERNAL_LINK_DEF = re.compile(r'^\[([^\]]+)\]:\s*(.+)') |
57 | 57 |
|
| 58 | +# Pattern to match {% include ... %} statements |
| 59 | +P_INTERNAL_INCLUDE_LINK = re.compile(r'^{% include ([^ ]*) %}$') |
| 60 | + |
58 | 61 | # What kinds of blockquotes are allowed? |
59 | 62 | KNOWN_BLOCKQUOTES = { |
60 | 63 | 'callout', |
@@ -208,29 +211,44 @@ def read_references(reporter, ref_path): |
208 | 211 | {symbolic_name : URL} |
209 | 212 | """ |
210 | 213 |
|
| 214 | + if not ref_path: |
| 215 | + raise Warning("No filename has been provided.") |
| 216 | + |
211 | 217 | result = {} |
212 | 218 | urls_seen = set() |
213 | | - if ref_path: |
214 | | - with open(ref_path, 'r') as reader: |
215 | | - for (num, line) in enumerate(reader): |
216 | | - line_num = num + 1 |
217 | | - m = P_INTERNAL_LINK_DEF.search(line) |
218 | | - require(m, |
219 | | - '{0}:{1} not valid reference:\n{2}'.format(ref_path, line_num, line.rstrip())) |
220 | | - name = m.group(1) |
221 | | - url = m.group(2) |
222 | | - require(name, |
223 | | - 'Empty reference at {0}:{1}'.format(ref_path, line_num)) |
224 | | - reporter.check(name not in result, |
225 | | - ref_path, |
226 | | - 'Duplicate reference {0} at line {1}', |
227 | | - name, line_num) |
228 | | - reporter.check(url not in urls_seen, |
229 | | - ref_path, |
230 | | - 'Duplicate definition of URL {0} at line {1}', |
231 | | - url, line_num) |
232 | | - result[name] = url |
233 | | - urls_seen.add(url) |
| 219 | + |
| 220 | + with open(ref_path, 'r') as reader: |
| 221 | + for (num, line) in enumerate(reader, 1): |
| 222 | + |
| 223 | + if P_INTERNAL_INCLUDE_LINK.search(line): continue |
| 224 | + |
| 225 | + m = P_INTERNAL_LINK_DEF.search(line) |
| 226 | + |
| 227 | + message = '{}: {} not a valid reference: {}' |
| 228 | + require(m, message.format(ref_path, num, line.rstrip())) |
| 229 | + |
| 230 | + name = m.group(1) |
| 231 | + url = m.group(2) |
| 232 | + |
| 233 | + message = 'Empty reference at {0}:{1}' |
| 234 | + require(name, message.format(ref_path, num)) |
| 235 | + |
| 236 | + unique_name = name not in result |
| 237 | + unique_url = url not in urls_seen |
| 238 | + |
| 239 | + reporter.check(unique_name, |
| 240 | + ref_path, |
| 241 | + 'Duplicate reference name {0} at line {1}', |
| 242 | + name, num) |
| 243 | + |
| 244 | + reporter.check(unique_url, |
| 245 | + ref_path, |
| 246 | + 'Duplicate definition of URL {0} at line {1}', |
| 247 | + url, num) |
| 248 | + |
| 249 | + result[name] = url |
| 250 | + urls_seen.add(url) |
| 251 | + |
234 | 252 | return result |
235 | 253 |
|
236 | 254 |
|
@@ -539,7 +557,6 @@ def __init__(self, args, filename, metadata, metadata_len, text, lines, doc): |
539 | 557 | (re.compile(r'index\.md'), CheckIndex), |
540 | 558 | (re.compile(r'reference\.md'), CheckReference), |
541 | 559 | (re.compile(r'_episodes/.*\.md'), CheckEpisode), |
542 | | - (re.compile(r'aio\.md'), CheckNonJekyll), |
543 | 560 | (re.compile(r'.*\.md'), CheckGeneric) |
544 | 561 | ] |
545 | 562 |
|
|
0 commit comments