Loading tools/check.py +29 −16 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ Call at command line with flag -h to see options and usage instructions. import argparse import collections import functools import glob import hashlib import logging Loading @@ -25,6 +26,19 @@ import yaml import validation_helpers as vh NUMBER_OF_ERRORS = 0 def incr_error(func): """Wrapper to count the number of errors""" @functools.wraps(func) def wrapper(*args, **kwargs): global NUMBER_OF_ERRORS NUMBER_OF_ERRORS += 1 return func(*args, **kwargs) return wrapper logging.error = incr_error(logging.error) class MarkdownValidator(object): """Base class for Markdown validation Loading @@ -37,7 +51,7 @@ class MarkdownValidator(object): # Dict of tuples for each callout type: {style: (title, min, max)} CALLOUTS = {} WARN_ON_EXTRA_HEADINGS = True # Warn when other headings are present? WARN_ON_EXTRA_HEADINGS = False # Warn when other headings are present? # Validate YAML doc headers: dict of {header text: validation_func} DOC_HEADERS = {} Loading Loading @@ -456,7 +470,8 @@ class IndexPageValidator(MarkdownValidator): DOC_HEADERS = {'layout': vh.is_str, 'title': vh.is_str} CALLOUTS = {'prereq': ("Prerequisites", 1, 1)} CALLOUTS = {'prereq': ("Prerequisites", 1, 1), 'getready': ("Getting ready", 1, 1)} def _partition_links(self): """Check the text of every link in index.md""" Loading Loading @@ -500,17 +515,16 @@ class TopicPageValidator(MarkdownValidator): The top-level document has no headings indicating subtopics. The only valid subheadings are nested in blockquote elements""" heading_nodes = self.ast.get_section_headings() if len(heading_nodes) == 0: return True if len(heading_nodes) != 0: # Individual heading msgs are logged by validate_section_heading_order logging.error( logging.warning( "In {0}: " "The topic page should not have sub-headings " "outside of special blocks. " "If a topic needs sub-headings, " "it should be broken into multiple topics.".format(self.filename)) return False "Sub-headings are often a sign " "a lesson needs to be split into multiple topics. " "Please make sure this subsection doesn't belong " "in a separate lesson.".format(self.filename)) return True def _run_tests(self): parent_tests = super(TopicPageValidator, self)._run_tests() Loading Loading @@ -822,12 +836,11 @@ def main(parsed_args_obj): if all_valid is True: logging.debug("All Markdown files successfully passed validation.") sys.exit(0) else: logging.warning( "Some errors were encountered during validation. " "See log for details.") sys.exit(1) "{0} errors were encountered during validation. " "See log for details.".format(NUMBER_OF_ERRORS)) sys.exit(NUMBER_OF_ERRORS) if __name__ == "__main__": Loading tools/filters/blockquote2div.py +11 −1 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ SPECIAL_CLASSES = { "callout": ("panel-info", "glyphicon-pushpin"), "challenge": ("panel-success", "glyphicon-pencil"), "prereq": ("panel-warning", "glyphicon-education"), "getready": ("panel-warning", "glyphicon-check"), "objectives": ("panel-warning", "glyphicon-certificate"), } Loading Loading @@ -113,7 +114,16 @@ def blockquote2div(key, value, format, meta): # a blockquote is just a list of blocks, so it can be # passed directly to Div, which expects Div(attr, blocks) return pf.Div((id, classes, kvs), [panel_header, panel_body]) if classes[0] == "callout": return [{"t": "RawBlock", "c": [ "html", "<aside class=\"{0}\">".format(' '.join(classes)) ]}, panel_header, panel_body, {"t": "RawBlock", "c": [ "html", "</aside>" ]}] else: return [{"t": "RawBlock", "c": [ "html", "<section class=\"{0}\">".format(' '.join(classes)) ]}, panel_header, panel_body, {"t": "RawBlock", "c": [ "html", "</section>" ]}] if __name__ == '__main__': Loading Loading
tools/check.py +29 −16 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ Call at command line with flag -h to see options and usage instructions. import argparse import collections import functools import glob import hashlib import logging Loading @@ -25,6 +26,19 @@ import yaml import validation_helpers as vh NUMBER_OF_ERRORS = 0 def incr_error(func): """Wrapper to count the number of errors""" @functools.wraps(func) def wrapper(*args, **kwargs): global NUMBER_OF_ERRORS NUMBER_OF_ERRORS += 1 return func(*args, **kwargs) return wrapper logging.error = incr_error(logging.error) class MarkdownValidator(object): """Base class for Markdown validation Loading @@ -37,7 +51,7 @@ class MarkdownValidator(object): # Dict of tuples for each callout type: {style: (title, min, max)} CALLOUTS = {} WARN_ON_EXTRA_HEADINGS = True # Warn when other headings are present? WARN_ON_EXTRA_HEADINGS = False # Warn when other headings are present? # Validate YAML doc headers: dict of {header text: validation_func} DOC_HEADERS = {} Loading Loading @@ -456,7 +470,8 @@ class IndexPageValidator(MarkdownValidator): DOC_HEADERS = {'layout': vh.is_str, 'title': vh.is_str} CALLOUTS = {'prereq': ("Prerequisites", 1, 1)} CALLOUTS = {'prereq': ("Prerequisites", 1, 1), 'getready': ("Getting ready", 1, 1)} def _partition_links(self): """Check the text of every link in index.md""" Loading Loading @@ -500,17 +515,16 @@ class TopicPageValidator(MarkdownValidator): The top-level document has no headings indicating subtopics. The only valid subheadings are nested in blockquote elements""" heading_nodes = self.ast.get_section_headings() if len(heading_nodes) == 0: return True if len(heading_nodes) != 0: # Individual heading msgs are logged by validate_section_heading_order logging.error( logging.warning( "In {0}: " "The topic page should not have sub-headings " "outside of special blocks. " "If a topic needs sub-headings, " "it should be broken into multiple topics.".format(self.filename)) return False "Sub-headings are often a sign " "a lesson needs to be split into multiple topics. " "Please make sure this subsection doesn't belong " "in a separate lesson.".format(self.filename)) return True def _run_tests(self): parent_tests = super(TopicPageValidator, self)._run_tests() Loading Loading @@ -822,12 +836,11 @@ def main(parsed_args_obj): if all_valid is True: logging.debug("All Markdown files successfully passed validation.") sys.exit(0) else: logging.warning( "Some errors were encountered during validation. " "See log for details.") sys.exit(1) "{0} errors were encountered during validation. " "See log for details.".format(NUMBER_OF_ERRORS)) sys.exit(NUMBER_OF_ERRORS) if __name__ == "__main__": Loading
tools/filters/blockquote2div.py +11 −1 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ SPECIAL_CLASSES = { "callout": ("panel-info", "glyphicon-pushpin"), "challenge": ("panel-success", "glyphicon-pencil"), "prereq": ("panel-warning", "glyphicon-education"), "getready": ("panel-warning", "glyphicon-check"), "objectives": ("panel-warning", "glyphicon-certificate"), } Loading Loading @@ -113,7 +114,16 @@ def blockquote2div(key, value, format, meta): # a blockquote is just a list of blocks, so it can be # passed directly to Div, which expects Div(attr, blocks) return pf.Div((id, classes, kvs), [panel_header, panel_body]) if classes[0] == "callout": return [{"t": "RawBlock", "c": [ "html", "<aside class=\"{0}\">".format(' '.join(classes)) ]}, panel_header, panel_body, {"t": "RawBlock", "c": [ "html", "</aside>" ]}] else: return [{"t": "RawBlock", "c": [ "html", "<section class=\"{0}\">".format(' '.join(classes)) ]}, panel_header, panel_body, {"t": "RawBlock", "c": [ "html", "</section>" ]}] if __name__ == '__main__': Loading