I'm exploring the possibilities of tagging MarkDown files with json datastructures.
The json data can be kept hidden from print outs by putting them in "comments", see StackOverflow - Comments in Markdown
[json]:# (
[
"json goes here"
]
)
To extract the json tags I've been playing around with regexp and come up with
\[json]:#.\(([^*]*)\)
This however, only works if I only have one [json]-tag in the md-file.
(See One tag)
With more then one tag, the regexp gets greedy and includes everything in between the first and the last tag :/
(See Multiple tags)
This is sample code for reproducing the issue
$md = @'
[json]:# (
[
{"jira": "proj-4753"},
{"creation": "2021-09-25"}
]
)
# Title
## 1. Conclusion
Jada, jada
## 2. Recomendation
blah, blah
[json]:# (
[
{"sensitivity": "internal"}
]
)
More data
[json]:# (
[
{"uid": "abc002334"}
]
)
[json]:# (
[
{"mode": "hallow"}
]
)
and this
'@
($md | Select-String '\[json]:#.\(([^*]*)\)').Matches.Value
No output provided as it will be the complete md except the last line
...
A proper output example when using multiple tags and specifying tag 2 should be like
($md | Select-String '<a working regexp>' -AllMatches).Matches[1].Value
[json]:# (
[
{"sensitivity": "internal"}
]
)
($md | Select-String '<a working regexp>' -AllMatches).Matches.Value
[json]:# (
[
{"jira": "proj-4753"},
{"creation": "2021-09-25"}
]
)
[json]:# (
[
{"sensitivity": "internal"}
]
)
[json]:# (
[
{"uid": "abc002334"}
]
)
[json]:# (
[
{"mode": "hallow"}
]
)
I could of course opt for using only one [json] tag per md.
There's also an optional solution of keeping the tags on one line only, but that will hamper readability.
And that wouldn't make for very robust code with two very possible scenarios (multiple tags and multi line tags) breaking the code.