git @ Cat's Eye Technologies Feedmark / 56c1b5b
Add --output-refdex-index option. Chris Pressey 5 years ago
3 changed file(s) with 29 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
33 0.10
44 ----
55
6 * Allow trailing `###` on h3-level section headers.
6 * Added `--output-refdex-index` option, which outputs the
7 refdex as a sorted list of entries in Markdown format.
8 * Parser now allows trailing `###` on h3-level section headers.
79
810 0.9-2019.105
911 ------------
8484
8585 def feedmark_htmlize(document, *args, **kwargs):
8686 return markdown_to_html5(feedmark_markdownize(document, *args, **kwargs))
87
88
89 def generate_index_from_refdex(refdex):
90 x = u''
91 for k, v in sorted(refdex.items()):
92 x += u"### {}\n\n".format(k)
93 if 'url' in v:
94 x += u"* [{}]({})\n\n".format(v['url'], v['url'])
95 elif 'anchor' in v:
96 link = u"{}#{}".format(v['filename'], v['anchor'])
97 x += u"* [{}]({})\n\n".format(link, link)
98 else:
99 raise NotImplementedError
100 return x
6161 argparser.add_argument('--input-refdexes', metavar='FILENAME', type=str,
6262 help='Load these JSON files as the reference-style links index before processing'
6363 )
64 argparser.add_argument('--input-refdex-filename-prefix', type=str, default=None,
65 help='After loading refdexes, prepend this to filename of each refdex'
66 )
6467 argparser.add_argument('--output-refdex', action='store_true',
6568 help='Construct reference-style links index from the entries and write it to stdout as JSON'
6669 )
67 argparser.add_argument('--input-refdex-filename-prefix', type=str, default=None,
68 help='After loading refdexes, prepend this to filename of each refdex'
70 argparser.add_argument('--output-refdex-index', action='store_true',
71 help='Construct a Markdown document from resulting refdex and write it to stdout'
6972 )
7073
7174 argparser.add_argument('--limit', metavar='COUNT', type=int, default=None,
106109 sys.exit(1)
107110
108111 ### processing: collect refdex phase
109 # NOTE: we only run this if we were asked to output a refdex -
112 # NOTE: we only run this if we were asked to output a refdex or an index-
110113 # this is to prevent scurrilous insertion of refdex entries when rewriting.
111114
112 if options.output_refdex:
115 if options.output_refdex or options.output_refdex_index:
113116 for document in documents:
114117 for section in document.sections:
115118 refdex[section.title] = {
127130
128131 if options.output_refdex:
129132 sys.stdout.write(json.dumps(refdex, indent=4, sort_keys=True))
133
134 if options.output_refdex_index:
135 from feedmark.formats.markdown import generate_index_from_refdex
136 index_contents = generate_index_from_refdex(refdex)
137 sys.stdout.write(index_contents)
130138
131139 if options.dump_entries:
132140 for document in documents: