Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I parse marked up text for further processing?
    primarykey
    data
    text
    <p><strong>See updated input and output data at Edit-1.</strong></p> <p>What I am trying to accomplish is turning</p> <pre> + 1 + 1.1 + 1.1.1 - 1.1.1.1 - 1.1.1.2 + 1.2 - 1.2.1 - 1.2.2 - 1.3 + 2 - 3 </pre> <p>into a python data structure such as </p> <pre><code>[{'1': [{'1.1': {'1.1.1': ['1.1.1.1', '1.1.1.2']}, '1.2': ['1.2.1', '1.2.2']}, '1.3'], '2': {}}, ['3',]] </code></pre> <p>I've looked at many different wiki markup languages, markdown, restructured text, etc but they are all extremely complicated for me to understand how it works since they must cover a large amount of tags and syntax (I would only need the "list" parts of most of these but converted to python instead of html of course.)</p> <p>I've also taken a look at tokenizers, lexers and parsers but again they are much more complicated than I need and that I can understand.</p> <p>I have no idea where to begin and would appreciate any help possible on this subject. Thanks</p> <p><strong>Edit-1</strong>: Yes the character at the beginning of the line matters, from the required output from before and now it could be seen that the <strong><code>*</code></strong> denotes a root node with children, the <strong>+</strong> has children and the <strong>-</strong> has no children (root or otherwise) and is just extra information pertaining to that node. The <strong><code>*</code></strong> is not important and can be interchanged with <strong>+</strong> (I can get root status other ways.) </p> <p>Therefore the new requirement would be using only <strong><code>*</code></strong> to denote a node with or without children and <strong>-</strong> cannot have children. I've also changed it so the key isn't the text after the <strong><code>*</code></strong> since that will no doubt changer later to an actual title.</p> <p>For example </p> <pre> * 1 * 1.1 * 1.2 - Note for 1.2 * 2 * 3 - Note for root </pre> <p>would give </p> <pre><code>[{'title': '1', 'children': [{'title': '1.1', 'children': []}, {'title': '1.2', 'children': []}]}, {'title': '2', 'children': [], 'notes': ['Note for 1.2', ]}, {'title': '3', 'children': []}, 'Note for root'] </code></pre> <p>Or if you have another idea to represent the outline in python then bring it forward.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload