sc0ttj / mdsh

A simple static site generator, using Markdown and Bash
https://sc0ttj.github.io/mdsh/
10 stars 0 forks source link

mdshell parsing problems #60

Closed sc0ttj closed 5 years ago

sc0ttj commented 5 years ago

mdshell.sh parses markdown files, and can parse bash sub-shells inside the markdown, where the sub-shells use the $(some code) syntax.

Problem

The code which grabs the contents of the $() sub-shell is very buggy.

Examples:

This will work:

Some para text $(foo) more text.

^ the output of the foo command will appear in the final markdown.

This also works:

Some para.

$(cmd1;
cmd2)

More text.

^ the output of both cmd1 and cmd2 appear in the final markdown.

This will not work:

Some text.

$(cat file)

^ fails if file contains $() or various escaped quotes or parentheses..

This will not work:

Some para.

$(cmd1 $(foo))

More text

^ the foo command (and remaining document!) will not get parsed correctly

This will not work:

Some para.

$(echo "$foo \"blah\" $more") 

More text

^ escaped ", (, ) and ' all cause problems...

Solution

Don't look for $() in markdown files to drop in and out of sub-shells... It's too brittle..

Use <?bash foo ?>, as this is unambiguous and way less brittle.. and it is what Bash on Steroids uses, which would make a better templating system than mo - more consistency in syntax across markdown and templates.

sc0ttj commented 5 years ago

Fixed in this PR: https://github.com/sc0ttj/mdsh/pull/74

sc0ttj commented 5 years ago

Fix in #74 now merged into main branch.. Closing as fixed.