├── 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 | ![Mawkdown Screensshot](screenshot.png) 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 "Mawkdown" } 2 | { _=0 } 3 | /^[^-]/ && inli { print ""; inli=0 } 4 | /^[^>]/ && inq { print ""; inq=0 } 5 | /^# / { _=1; print "

", substr($0, 2), "

" } 6 | /^## / { _=1; print "

", substr($0, 3), "

" } 7 | /^### / { _=1; print "

", substr($0, 4), "

" } 8 | /^#### / { _=1; print "

", substr($0, 5), "

" } 9 | /^```/ { _=1; if (!inpre) { 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 "