Reputation: 35
I was wondering how people manages large markdown documents. Typically I would like to check whether small portions, sections or chapters are okay before I compile the whole document. They way I do these days, which many of us may already practice, break the whole document in smaller markdown files and use those as "child" documents in the master document.
One problem with that method is that all the contents do not exist in a single document and I have to hop around several documents to make connections and edits. But again, if I keep a single file it makes the whole compilation and debugging pretty difficult. Therefore I was wondering, is there any way I can run pandoc in selected portion of a document, say from line 23 to line 52, or selected sections or parts?
Upvotes: 0
Views: 253
Reputation: 207465
You can achieve that using bash
's "Process Substitution" feature. Basically, you run pandoc
but instead of giving it the name of a file, you give it the output of a command. So, we can run pandoc
on the first 10 lines of text.md
like this:
pandoc <(head text.md)
Or lines 23 to 52 like this:
pandoc <(sed -ne '23,52p' text.md)
or, same with awk
:
pandoc <(awk 'NR>22 && NR<53' text.md)
Or, run pandoc
on 10 lines following #I2C Section
chapter title:
pandoc <(grep -A10 "^#I2C Section" text.md)
It seems you can also do all the above with a simple pipe, which is easier for Windows users:
head text.md | pandoc
I guess you could also do more advanced things like getting the structure of a document by looking for lines beginning with #
like this:
grep "^#" text.md | pandoc > structure.html
Upvotes: 2