git @ Cat's Eye Technologies Feedmark / 655c47f
Get property priority order from schema instead of command line. Chris Pressey 7 years ago
3 changed file(s) with 18 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
1414 def __init__(self, document):
1515 self.document = document
1616 self.property_rules = {}
17 self.property_priority_order = []
1718 for section in self.document.sections:
1819 self.property_rules[section.title] = section
20 self.property_priority_order.append(section.title)
1921
2022 def check(self, section):
2123 results = []
2628 if key not in section.properties:
2729 results.append("Schema demands '{}' which is not present in {}".format(key, section))
2830 return results
31
32 def get_property_priority_order(self):
33 return self.property_priority_order
2934
3035
3136 def extract_links(html_text):
4949 yield key, item
5050
5151
52 def feedmark_markdownize(document, property_priority_order=None):
53 if property_priority_order is None:
54 property_priority_order = []
52 def feedmark_markdownize(document, schema=None):
53 property_priority_order = []
54 if schema is not None:
55 property_priority_order = schema.get_property_priority_order()
56
5557 md = u'{}\n{}\n\n'.format(document.title, '=' * len(document.title))
5658 md += u'\n'.join(document.preamble)
5759 for section in document.sections:
7375
7476
7577 def feedmark_htmlize(document, *args, **kwargs):
76 return markdown.markdown(feemark_markdownize(document, *args, **kwargs))
78 return markdown.markdown(feedmark_markdownize(document, *args, **kwargs))
2626 help='Check if web objects linked to from the entries exist'
2727 )
2828 argparser.add_argument('--check-against-schema', metavar='FILENAME', type=str, default=None,
29 help='Check if entries have the properties specified by this schema'
29 help='Check if entries have the properties specified by this schema. This schema will '
30 'also provide hints (such as ordering of properties) when outputting Markdown or HTML.'
3031 )
3132 argparser.add_argument('--output-atom', metavar='FILENAME', type=str,
3233 help='Construct an Atom XML feed from the entries and write it out to this file'
4243 )
4344 argparser.add_argument('--limit', metavar='COUNT', type=int, default=None,
4445 help='Process no more than this many entries when making an Atom or HTML feed'
45 )
46 argparser.add_argument('--property-priority-order', metavar='NAMES', type=str, default='',
47 help='Comma-seperated list of property names, giving the order in which '
48 'properties should be output (in Markdown and HTML)'
4946 )
5047
5148 options = argparser.parse_args(sys.argv[1:])
7471 if options.check_links or options.archive_links_to is not None:
7572 from feedmark.checkers import archive_links
7673 result = archive_links(documents, options.archive_links_to)
77 write(json.dumps(result, indent=4, sorted=True))
74 write(json.dumps(result, indent=4, sort_keys=True))
7875
76 schema = None
7977 if options.check_against_schema is not None:
8078 from feedmark.checkers import Schema
8179 schema_document = read_document_from(options.check_against_schema)
8987 'section': str(section),
9088 'result': result
9189 })
92 write(json.dumps(results, indent=4, sorted=True))
90 write(json.dumps(results, indent=4, sort_keys=True))
9391
9492 if options.dump_entries:
9593 for document in documents:
118116 if options.output_markdown:
119117 from feedmark.htmlizer import feedmark_markdownize
120118 for document in documents:
121 s = feedmark_markdownize(document, property_priority_order=options.property_priority_order.split(','))
119 s = feedmark_markdownize(document, schema=schema)
122120 write(s)
123121
124122 if options.output_html:
125123 from feedmark.htmlizer import feedmark_htmlize
126124 for document in documents:
127 s = feedmark_htmlize(document, property_priority_order=options.property_priority_order.split(','))
125 s = feedmark_htmlize(document, schema=schema)
128126 write(s)
129127
130128 if options.output_html_snippet: