doc: wikiparser: When processing single pages, ignore header/footer

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2020-08-24 10:36:47 -07:00 committed by James Valleroy
parent 4ef2244af4
commit e947e99af3
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 14 additions and 2 deletions

View File

@ -117,7 +117,8 @@ $(manual-xmls): %.xml: %.raw.xml $(SCRIPTS_DIR)/fixes.xslt
xsltproc --output $@ $(SCRIPTS_DIR)/fixes.xslt $<
$(manual-pages-raw-xml): %.raw.xml: %.raw.wiki $(SCRIPTS_DIR)/wikiparser.py
python3 $(SCRIPTS_DIR)/wikiparser.py $< > $@
python3 $(SCRIPTS_DIR)/wikiparser.py --begin-marker="## BEGIN_INCLUDE" \
--end-marker='## END_INCLUDE' $< > $@
$(manual-pages-xml): %.xml: %.raw.xml $(SCRIPTS_DIR)/manual-page-fixes.xslt
xsltproc --output $@ $(SCRIPTS_DIR)/manual-page-fixes.xslt $<

View File

@ -1201,11 +1201,16 @@ PlainText('dialog.')])])])]
# Skip lines before begin_marker, if given.
if begin_marker:
removed_lines = []
while lines:
line = lines.pop(0).strip()
removed_lines.append(line)
if line.startswith(begin_marker):
break
if not lines: # No begin marker found
lines = removed_lines
while lines:
line = lines.pop(0)
# End of included file
@ -1722,6 +1727,10 @@ if __name__ == '__main__':
help='Skip module doctests')
parser.add_argument('--debug', action='store_true',
help='Show parser output')
parser.add_argument('--begin-marker', default=None,
help='Start parsing at this line')
parser.add_argument('--end-marker', default=None,
help='Stop parsing at this line')
parser.add_argument('input', type=Path, nargs='*',
help='input file path(s)')
arguments = parser.parse_args()
@ -1736,7 +1745,9 @@ if __name__ == '__main__':
wiki_text = wiki_file.read()
context = get_context(in_file)
parsed_wiki = parse_wiki(wiki_text, context)
parsed_wiki = parse_wiki(wiki_text, context,
begin_marker=arguments.begin_marker,
end_marker=arguments.end_marker)
if arguments.debug:
import pprint
pprint.pprint(parsed_wiki, indent=4)