From: Tommy F. <to...@la...> - 2017-12-20 22:26:20
|
Dave, My goal is to convert Markdown into a custom JSON schema. For example, if I had a file of: # Prerequisites prereq.md prereq-2.md # Do stuff here ```shell echo foo echo bar ``` # Do more stuff here ```shell echo baz ``` # Results The only thing that makes it a result is the code type is result. We assume the result is for the last command of the last code block ```result baz ``` An expected output from parsing the input doc would be: { 'prerequisites': ['prereq.md', 'prereq-2.md'], 'commands': [ { 'command': 'echo foo' }, { 'command': 'echo bar' }, { 'command': 'echo baz', 'expected_result': 'baz' } ] } Essentially, it takes everything inside the code block and creates a list of commands to run. (Some of the commands would have results to compare against. For example, "echo baz" should see a result of "baz"). Prerequisites are other files that it should run before the commands. My goal is to parse a markdown file and create a JSON document that contains the list of commands to execute, prerequisite files, etc. Am I going down the right path with building my own extension? If so, any pointers? On Wed, Dec 20, 2017 at 12:17 PM Dave Pawson <dav...@gm...> wrote: > Which input / which output is not exactly clear - no ID values in Python? > > General answer though. md has both block and inline constructs > so it would seem to meet json needs? > > Perhaps try it as an extension first? one block, one inline > and see how easy it is to work? > > I found it very logical. > YMMV > > > On 20 December 2017 at 17:44, Tommy Falgout <to...@la...> > wrote: > > Hello, > > > > I'm building a tool to convert markdown into runnable documentation and I > > came across your project. I'm currently using Mistune's BlockParser, > > because I don't want to convert to HTML, instead into a custom JSON > format. > > > > I looked at your documentation for writing an extension; however, I was > > unsure if this would be the right path for me. Can you please advise? > If > > so, would I want to use a Preprocessor/Postprocessor/InlinePattern/etc.? > > > > Here's an example of an input document: > > > https://github.com/lastcoolnameleft/simdem2/blob/master/tests/test_parser.py#L25 > > > > Here's the expected output: > > > https://github.com/lastcoolnameleft/simdem2/blob/master/tests/test_parser.py#L57 > > > > Thanks, > > -Tommy. > > > > > ------------------------------------------------------------------------------ > > Check out the vibrant tech community on one of the world's most > > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > > _______________________________________________ > > Python-markdown-discuss mailing list > > Pyt...@li... > > https://lists.sourceforge.net/lists/listinfo/python-markdown-discuss > > > > > > -- > Dave Pawson > XSLT XSL-FO FAQ. > Docbook FAQ. > http://www.dpawson.co.uk > |