From: Waylan L. <way...@ic...> - 2016-05-28 00:51:04
|
Andrew, Have you looked at the list of existing third party extensions [1]? The outline [2] extension may be of interest to you. It breaks up a Markdown document into sections based on the headers within the document. No need for any special syntax to mark the sections. However, if you really need the special syntax, that extension might give you some ideas of how to implement your own. If not, then may I suggest you start with a treeprocessor. Step through the already parsed document (ElementTree Elements) and find each paragraph which contains a section marker. Replace that paragraph with a section Element and then insert into the section each sibling until you reach the next section marker. As everything should be at the document root, you shouldn't even need to look into children Elements. Should be pretty simple once you become familiar with the ElementTree API. [1]: https://github.com/waylan/Python-Markdown/wiki/Third-Party-Extensions [2]: https://github.com/aleray/mdx_outline Waylan Limberg > On May 25, 2016, at 7:21 PM, Slaughter, Andrew E <and...@in...> wrote: > > I am working on creating a custom extension to parse markdown into Reveal.js slides. I understand that Reveal.js already understands markdown, but I want to parse additional custom syntax that I already generated, thus I want to convert to html directly. > > Has anyone done something similar or can someone provide me with a similar example? I am just looking for something to kick me in the proper direction, I have created custom pattern extensions but I believe I will need a BlockProcessor or possibly a Preprocessor to do this. > > In short, I need to convert the demo.md to the demo.html shown below, which simply requires the delimiter (!---) to mark the location of a <section> break. Any help pointing me in the correct direction would be greatly appreciated. > > ---demo.md-------------------------------------------------------------- > Slide 1 > > * Item 1 > * Item 2 > > !--- > > Slide 2 > > Some thing really import > goes here, with custom markdown syntax. > > !--- > > Slide 3 > > ```python > for i in range(10): > print i > ``` > > This needs to be converted to, notice the '!---' lines are replace with <section>. > ---demo.html---------------------------------------------------------------- > <section> > <p>Slide 1</p> > <ul> > <li>Item 1</li> > <li>Item 2</li> > </ul> > </section> > <section> > <p>Slide 2</p> > <p>Some thing really import > goes here, with custom markdown syntax.</p> > </section> > <section> > <p>Slide 3</p> > <p><code>python > for i in range(10): > print i</code></p> > </section> > ------------------------------------------------------------------------------ > Mobile security can be enabling, not merely restricting. Employees who > bring their own devices (BYOD) to work are irked by the imposition of MDM > restrictions. Mobile Device Manager Plus allows you to control only the > apps on BYO-devices by containerizing them, leaving personal data untouched! > https://ad.doubleclick.net/ddm/clk/304595813;131938128;j > _______________________________________________ > Python-markdown-discuss mailing list > Pyt...@li... > https://lists.sourceforge.net/lists/listinfo/python-markdown-discuss |