Create markdown segments based on a table of contents
Project description
markdown-toc-segments
Purpose
Most structured cases in Philippine jurisprudence follow a certain format that can be dissected through an outline. See sample file. Assuming a proper table of contents can be generated from the markdown file, can create segments from the full text:
>>> from pathlib import Path
>>> from markdown_toc_segments import Outline
>>> f = Path().cwd() / "temp.md"
>>> obj = Outline(raw=f.read_text())
>>> obj.footnotes
[Footnote(id='fn:1', markup='I am no footnote\xa0↩'),
Footnote(id='fn:2', markup='One does not simply footnote\xa0↩'),
Footnote(id='fn:3', markup='A red day ere the sun foonotes\xa0↩'),
Footnote(id='fn:4', markup='The lord of the footnotes\xa0↩'),
Footnote(id='fn:5', markup='Footnotes is the precious\xa0↩')]
>>> obj.segments
[Segment(id='ponencia', markup='<p>This is a sample decision written in markdown to illustrate the ability to compartamentalize text.<sup id="fnref:1"><a class="footnote-ref" href="#fn:1">1</a></sup></p>'),
Segment(id='antecedents', markup='<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit,<sup id="fnref:2"><a class="footnote-ref" href="#fn:2">2</a></sup> sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 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<sup id="fnref:3"><a class="footnote-ref" href="#fn:3">3</a></sup> nulla pariatur. Excepteur sint occaecat cupidatat non proident,<sup id="fnref:4"><a class="footnote-ref" href="#fn:4">4</a></sup> sunt in culpa qui officia deserunt mollit anim id est laborum.</p>'),
Segment(id='version-of-the-defense', markup='<p>XXX</p>'),
...
Segment(id='the-courts-ruling', markup='<p>The Court dismisses the appeal.</p>'),
Segment(id='this-is-a-proper-headline', markup='<p>XXXX</p>'),
...]
>>> obj.tree
[
Item(
id='ponencia',
label='Ponencia',
segment=Segment(id='ponencia', markup='<p>This is a sample decision written in markdown to illustrate the ability to compartamentalize text.<sup id="fnref:1"><a class="footnote-ref" href="#fn:1">1</a></sup></p>'),
text='This is a sample decision written in markdown to illustrate the ability to compartamentalize text.%% I am no footnote %%',
children=[
Item(
id='antecedents',
label='Antecedents',
segment=Segment(id='antecedents', markup='<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit,<sup id="fnref:2"><a class="footnote-ref" href="#fn:2">2</a></sup> sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 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<sup id="fnref:3"><a class="footnote-ref" href="#fn:3">3</a></sup> nulla pariatur. Excepteur sint occaecat cupidatat non proident,<sup id="fnref:4"><a class="footnote-ref" href="#fn:4">4</a></sup> sunt in culpa qui officia deserunt mollit anim id est laborum.</p>'), text='Lorem ipsum dolor sit amet, consectetur adipiscing elit,%% One does not simply footnote %% sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 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%% A red day ere the sun foonotes %% nulla pariatur. Excepteur sint occaecat cupidatat non proident,%% The lord of the footnotes %% sunt in culpa qui officia deserunt mollit anim id est laborum.', children=[
Item(
id='version-of-the-defense',
label='Version of the Defense',
segment=Segment(id='version-of-the-defense',
markup='<p>sffffffffm dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Adipiscing diam donec adipiscing tristique risus nec feugiat in fermentum. Porttitor eget dolor morbi non. In arcu cursus euismod quis viverra nibh. Nec ultrices dui sapien eget mi proin sed. Ultrices eros in cursus turpis massa. Sit amet consectetur adipiscing elit. Quis ipsum suspendisse ultrices gravida. Vel elit scelerisque mauris pellentesque pulvinar pellentesque. At urna condimentum mattis pellentesque id nibh tortor. Amet tellus cras adipiscing enim eu turpis egestas. Non blandit massa enim nec dui nunc mattis. Viverra ipsum nunc aliquet bibendum enim facilisis gravida neque. Cras sed felis eget velit aliquet sagittis id consectetur. Donec pretium vulputate sapien nec sagittis aliquam malesuada. Orci eu lobortis elementum nibh tellus molestie nunc non. Risus sed vulputate odio ut enim blandit. Enim nulla aliquet porttitor lacus luctus accumsan tortor. Cursus euismod quis viverra nibh cras pulvinar mattis.</p>'), text='sffffffffm dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Adipiscing diam donec adipiscing tristique risus nec feugiat in fermentum. Porttitor eget dolor morbi non. In arcu cursus euismod quis viverra nibh. Nec ultrices dui sapien eget mi proin sed. Ultrices eros in cursus turpis massa. Sit amet consectetur adipiscing elit. Quis ipsum suspendisse ultrices gravida. Vel elit scelerisque mauris pellentesque pulvinar pellentesque. At urna condimentum mattis pellentesque id nibh tortor. Amet tellus cras adipiscing enim eu turpis egestas. Non blandit massa enim nec dui nunc mattis. Viverra ipsum nunc aliquet bibendum enim facilisis gravida neque. Cras sed felis eget velit aliquet sagittis id consectetur. Donec pretium vulputate sapien nec sagittis aliquam malesuada. Orci eu lobortis elementum nibh tellus molestie nunc non. Risus sed vulputate odio ut enim blandit. Enim nulla aliquet porttitor lacus luctus accumsan tortor. Cursus euismod quis viverra nibh cras pulvinar mattis.', children=[...])]
)
]
)
]
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file markdown_toc_segments-0.0.4.tar.gz
.
File metadata
- Download URL: markdown_toc_segments-0.0.4.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.0 CPython/3.10.6 Darwin/22.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77083e4eb07d5d121ef17cb7cd0c15997a61da2b561e015d43a81a9c8c70a3ec |
|
MD5 | 01ba4eb76dfc67b39819d56145950c75 |
|
BLAKE2b-256 | 2eb6d96945ce09d133b9b8a872aeaaa6636cb546c7fdf9cd4a293960adfca96b |
File details
Details for the file markdown_toc_segments-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: markdown_toc_segments-0.0.4-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.0 CPython/3.10.6 Darwin/22.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d16859749345d3bbdfb42a6b2d7dd8a2afd1fa07d57c5e4ad50b75d85c8b797 |
|
MD5 | e375d529f9287f8c5fc7a386843be056 |
|
BLAKE2b-256 | 29406a9de7af538a19b69b29dcbecf2deab7418aecd6969d64ad5de520208e95 |