assigning variable names/tags to asciidoc document so I can use those names in jinja template

395 views Asked by At

I need a way to extract tags from an Asciidoc file and save them into a python dictionary. I generally write in Asciidoc but I do not know how I can create variable names in Asciidoc that I can extract as keys to create a python dictionary. I have been hunting through documentation, but to no avail.

author name
----------
Kb

section name
-----------
requirement number

description
----------
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod    
tempor incididunt ut labore et dolore magna aliqua.

multiple paragraphs
-------------------
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut 
aliquip ex ea commodo consequat.

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore 
eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, 
sunt in culpa qui officia deserunt mollit anim id est laborum.

So I need a way to convert this asciidoc markup into a dictionary that looks like

{ 'author name':u'Kb', 'section name':u'requirement number', ... }

I have tried to convert the asciidoc file to xml and then xmltodict to convert this into a dictionary. But that did not work very well because I get a lot of the xml formatting stuff in the dictionary. I looked at various parsers like beautifulsoup and such, but since asciidoc does not use close tags, not sure that will work either. Any suggestions.

1

There are 1 answers

1
LightGuard On

Any reason you don't use a glossary block (http://asciidoc.org/userguide.html section 17.5)?

[glossary]
A glossary term::
    The corresponding definition.
A second glossary term::
    The corresponding definition.

From there you could generate the xml and pull them out that way or you could create your own custom backend to emit the JSON.