Skip to content

Commit

Permalink
Merge branch 'gh-pages' of github.com:swcarpentry/styles into gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
gvwilson committed Jul 24, 2016
2 parents 927d517 + cebd855 commit 1ef3289
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions bin/lesson_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
# 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',
Expand Down Expand Up @@ -274,6 +277,7 @@ def check(self):
self.check_trailing_whitespace()
self.check_blockquote_classes()
self.check_codeblock_classes()
self.check_defined_link_references()


def check_metadata(self):
Expand Down Expand Up @@ -331,6 +335,26 @@ def check_codeblock_classes(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."""

Expand Down

0 comments on commit 1ef3289

Please sign in to comment.