Check lesson files and their contents.
"""
+from __future__ import print_function
import sys
import os
import glob
# Pattern to match figure references in HTML.
P_FIGURE_REFS = re.compile(r'<img[^>]+src="([^"]+)"[^>]*>')
+# Pattern to match internally-defined Markdown links.
+P_INTERNALLY_DEFINED_LINK = re.compile(r'\[[^\]]+\]\[[^\]]+\]')
+
# What kinds of blockquotes are allowed?
KNOWN_BLOCKQUOTES = {
'callout',
'source',
'bash',
'make',
+ 'matlab',
'python',
'r',
'sql'
reporter.check_field(config_file, 'configuration', config, 'carpentry', ('swc', 'dc'))
reporter.check_field(config_file, 'configuration', config, 'title')
reporter.check_field(config_file, 'configuration', config, 'email')
- reporter.check_field(config_file, 'configuration', config, 'repo')
- reporter.check_field(config_file, 'configuration', config, 'root')
- if ('repo' in config) and ('root' in config):
- reporter.check(config['repo'].endswith(config['root']),
- config_file,
- 'Repository name "{0}" not consistent with root "{1}"',
- config['repo'], config['root'])
+
+ reporter.check({'values': {'root': '..'}} in config.get('defaults', []),
+ 'configuration',
+ '"root" not set to ".." in configuration')
def read_all_markdown(source_dir, parser):
self.check_trailing_whitespace()
self.check_blockquote_classes()
self.check_codeblock_classes()
+ self.check_defined_link_references()
def check_metadata(self):
cls)
+ def check_defined_link_references(self):
+ """Check that defined links resolve in the file.
+
+ Internally-defined links match the pattern [text][label]. If
+ the label contains '{{...}}', it is hopefully a references to
+ a configuration value - we should check that, but don't right
+ now.
+ """
+
+ result = set()
+ for node in self.find_all(self.doc, {'type' : 'text'}):
+ for match in P_INTERNALLY_DEFINED_LINK.findall(node['value']):
+ if '{{' not in match:
+ result.add(match)
+ self.reporter.check(not result,
+ self.filename,
+ 'Internally-defined links may be missing definitions: {0}',
+ ', '.join(sorted(result)))
+
+
def find_all(self, node, pattern, accum=None):
"""Find all matches for a pattern."""
super(CheckIndex, self).__init__(args, filename, metadata, metadata_len, text, lines, doc)
self.layout = 'lesson'
+ def check_metadata(self):
+ super(CheckIndex, self).check_metadata()
+ self.reporter.check(self.metadata.get('root', '') == '.',
+ self.filename,
+ 'Root not set to "."')
+
class CheckEpisode(CheckBase):
"""Check an episode page."""