Some markdown flavours ignore these and assume they're part of the word. This can be tripped up by words containing underscores.Putting it all togetherĮverything together in a script that takes the markdown file name as an argument: #!/bin/bashīold=$(grep -Po '_.*?_' "$tempfile" | grep -o ']\ ' | wc -l) Ready for consumption by the commands from the first section. Line with _bold words and an escaped asterisk_Īnd *italics with a _bold_ word inside* With the following result: $ sed -rf md.sed infile.md MATLAB accepts oblique in place of italic and vice versa. Be careful not to mix this and the underscore sign up otherwise you may get italics in place of strikethrough and vice versa. S/\*\*/_/g # Make sure bold uses underscores Settings Description normal Normal font italic Italic font oblique Oblique font. ^ /d # Delete code lines (start with four spaces) One approach to clean up something like this up would be a sed script: /^$/d # Delete empty lines Line with bold words and * an escaped asteriskĪnd bold words with italics inside Code can have tons of *, ** and _ and we want to ignore them allĪlso inline code can have * and ** and _ to be ignored, right? Line with **bold words and \* an escaped asterisk**Īnd *italics with a **bold** word inside*Ĭode can have tons of *, ** and _ and we want to ignore them allĪlso `inline code can have * and ** and _ to be ignored`, right? Now, a real markdown file might have a few extra surprises (see "Assumptions"): * List item with **bold word** To combine these (for bold and italic), the command lists have to be combined. The same works for italics: grep -Po '\*.*?\*' infile.md | grep -o ']\ ' | wc -l The second grep matches the words: any sequence of one or more non-space characters and wc -l counts the lines of output. *?) otherwise, something like _bold_ not bold _bold_ would be just one match. I used the Perl regex engine ( -P) to enable non-greedy matching (. This looks for anything between two pairs of _. Now, to count bold words, we can use grep -Po '_.*?_' infile.md | grep -o ']\ ' | wc -l
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |