├── LICENSE ├── README.md ├── mawkdown.awk ├── pipefox.sh └── screenshot.png /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Reto Habluetzel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Welcome to Mawkdown 2 | Mawkdown is a toy markdown parser written in AWK 3 | 4 | It requires GAWK, because it uses the `match` function. 5 | 6 | ## Try Mawkdown 7 | Generate html from the README: 8 | ```bash 9 | awk -f mawkdown.awk README.md 10 | ``` 11 | 12 | Open README in firefox: 13 | ```bash 14 | awk -f mawkdown.awk README.md | ./pipefox.sh 15 | ``` 16 | 17 | Or something simpler: 18 | ```bash 19 | echo -e "# title\n## subtitle" | awk -f mawkdown.awk 20 | ``` 21 | 22 | ## It supports all of these things 23 | Now look at this fine `rust` code: 24 | 25 | ``` 26 | let x = 5; 27 | printf!("{} + {} = {}", x, x, x + x); 28 | ``` 29 | 30 | here's a link to my other project called [digester](https://digester.app?ref=mawkdown). 31 | 32 | this is not the first time I'm having fun with AWK: [awk-jvm](https://github.com/rethab/awk-jvm). 33 | 34 | > and here's some quoted text 35 | 36 | ### Sample h3 37 | *what does the above code do?* 38 | - store the value 5 in the variable x 39 | - call the printf macro 40 | 41 | _italic with underscores_ 42 | 43 | **bold with asterisks** 44 | 45 | __bold with underscores__ 46 | 47 | *italic with asterisks* 48 | 49 | --- 50 | 51 | ## What does it look like? 52 |  53 | (note that pipefox does not work with relative images) 54 | 55 | ## Limitations 56 | *basically any line can only contain one thing* 57 | 58 | - formatting *within* a list does not work 59 | - langauge-specific formatting 60 | -------------------------------------------------------------------------------- /mawkdown.awk: -------------------------------------------------------------------------------- 1 | BEGIN { print "
"; inpre=1 } else { print ""; inpre=0 } } 10 | /^\*\*.+\*\*/ { _=1; print "", substr($0, 3, length($0)-4), "" } 11 | /^\*.+\*/ && !_ { _=1; print "", substr($0, 2, length($0)-2), "" } 12 | /^__.+__/ { _=1; print "", substr($0, 3, length($0)-4), "" } 13 | /^_.+_/ && !_ { _=1; print "", substr($0, 2, length($0)-2), "" } 14 | /^- / && !_ { _=1; if (!inli) { print "
"; inq=1 }; print substr($0, 2) } 16 | /^---/ { _=1; print "
" } 17 | match($0, /(.*)!\[(.+)\]\((.+)\)(.*)/, u) { _=1; printf("%s%s", u[1], u[3], u[2], u[4]) } 18 | !_ && match($0, /(.*)\[(.+)\]\((.+)\)(.*)/, u) { _=1; printf("%s%s%s", u[1], u[3], u[2], u[4]) } 19 | !_ && match($0, /(.*)`(.*)`(.*)/, u) { _=1; printf("%s
%s
%s", u[1], u[2], u[3]) } 20 | !_ { print $0 } 21 | /^$/ { print "
" } 22 | END { print "" } 23 | -------------------------------------------------------------------------------- /pipefox.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # from stackoverflow (Snowball): https://unix.stackexchange.com/a/86897/39897 4 | firefox "data:text/html;base64,$(base64 -w 0 <&0)" 5 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rethab/mawkdown/3178cbc131c6d3757b43eb77f02a98824df0092f/screenshot.png --------------------------------------------------------------------------------