about summary refs log tree commit diff stats
path: root/ht3.awk
diff options
context:
space:
mode:
Diffstat (limited to 'ht3.awk')
-rwxr-xr-xht3.awk56
1 files changed, 42 insertions, 14 deletions
diff --git a/ht3.awk b/ht3.awk index 996cb1a..5226af7 100755 --- a/ht3.awk +++ b/ht3.awk
@@ -15,45 +15,71 @@ BEGIN {
15 } 15 }
16 # Output buffer. The output will be chunked into blocks. 16 # Output buffer. The output will be chunked into blocks.
17 BUFFER = "" 17 BUFFER = ""
18 # Default block type
19 DEFAULT_BLOCK = "p"
18 # The current block type. We start with a standard paragraph. 20 # The current block type. We start with a standard paragraph.
19 BLOCK = "p" 21 BLOCK = DEFAULT_BLOCK
20} 22}
21 23
22### RAW TEXT 24### RAW TEXT
23/^>>>/ { 25/^>>>/ {
26 BLOCK = "raw"
27 if ($1) {
28 split($1, raw_type, ",")
29 }
24} 30}
25 31
26/^<<</ { 32/^<<</ {
33 BLOCK = DEFAULT_BLOCK
34 for (type in raw_type) {
35 delete raw_type[type]
36 }
27} 37}
28 38
29### BLOCKS 39### BLOCKS
30/^#+/ { # Headers 40block == "raw" {
41 bufpush($0, "\n")
42 next
43}
44
45/^#+/ { # Headers
46 match($0, /^#+/)
47 if (! (BLOCK == "h" RLENGTH)) {
48 buflush()
49 tag = "h" RLENGTH
50 }
51 sub(/^#+[ \t]*/, "", $0)
31} 52}
32 53
33/^>/ { # Block quote 54/^>/ { # Block quote
34} 55}
35 56
36/^-/ { # Unordered list 57/^-/ { # Unordered list
37} 58}
38 59
39/^[0-9]\./ { # Ordered list 60/^[0-9]\./ { # Ordered list
40} 61}
41 62
42/^---$/ { # Section break 63/^---$/ { # Section break
64}
65
66/^$/ { # End a block
67 buflush()
68 BLOCK = DEFAULT_BLOCK
43} 69}
44 70
45### LINES 71### LINES
46/^=>/ { # Link 72/^=>/ { # Link
47} 73}
48 74
49/^</ { # HTML tag 75/^</ { # HTML tag
50} 76}
51 77
52/^;/ { # Comment 78/^;/ { # Comment
53} 79}
54 80
55### EVERYTHING ELSE 81# EVERYTHING ELSE
56{ 82/./ {
57} 83}
58 84
59### FINISH 85### FINISH
@@ -61,6 +87,7 @@ END {
61 buflush() 87 buflush()
62} 88}
63 89
90
64### FUNCTIONS 91### FUNCTIONS
65function buflush() 92function buflush()
66{ 93{
@@ -75,10 +102,11 @@ function buflush()
75 print 102 print
76} 103}
77 104
78function bufpush(str) 105function bufpush(str, sep)
79{ 106{
80 # Push STR onto the buffer after a newline. 107 # Push STR onto the buffer after SEP (defaults to space).
81 BUFFER = BUFFER (BUFFER ? "\n" : "") str 108 sep = sep ? sep : " "
109 BUFFER = BUFFER (BUFFER ? sep : "") str
82} 110}
83 111
84function ht_print(str) 112function ht_print(str)