aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-01-31 00:32:45 +0000
committerJohn Ankarström <john@ankarstrom.se>2021-01-31 00:32:45 +0000
commit2f7147aa05cbdcb8b1b2470877dffc663cb7a83e (patch)
treec85a09936d3d044e4a10e341e4cff8c5d83877c3
parent2c2367d45ca8bd24398543ddf338568aefc40cf1 (diff)
downloadem-2f7147aa05cbdcb8b1b2470877dffc663cb7a83e.tar.gz
Add blockquote syntax
-rw-r--r--BUGS12
-rw-r--r--README11
-rw-r--r--README.html11
-rwxr-xr-xemparse33
-rw-r--r--test.em5
-rw-r--r--test.html7
6 files changed, 59 insertions, 20 deletions
diff --git a/BUGS b/BUGS
index 7e7f7ed..cb764d6 100644
--- a/BUGS
+++ b/BUGS
@@ -1,9 +1,5 @@
-Sat Jan 30 21:40:01 CET 2021
+Sun Jan 31 01:16:11 CET 2021
-Blockquotes are not yet supported!
-
-Sat Jan 30 01:31:14 CET 2021
-
-A reference list containing only hyperlink references will
-result in an empty <ol> element. This doesn't matter
-much, as browsers seem to ignore it.
+Because excess spaces are stripped when processing inline formatting,
+there *is* actually more than one way to do it, currently. It doesn't
+matter too much, but I'd like to fix it eventually.
diff --git a/README b/README
index 470aa2d..072c473 100644
--- a/README
+++ b/README
@@ -164,6 +164,17 @@ reference item.
---
+=== Blockquotes ===
+
+Blockquotes are, in terms of syntax and behavior, actually another
+type of list, started with an initial space, followed by `> `:
+
+ > This is a quoted paragraph.
+ The paragraph continues on the next line.
+ > Here begins a new quoted paragraph.
+
+---
+
=== Preformatted blocks ===
_Preformatted blocks start with a single tab:_
diff --git a/README.html b/README.html
index c4c8e9f..cd64a87 100644
--- a/README.html
+++ b/README.html
@@ -189,6 +189,17 @@ inline references to them link directly to the link rather than the
reference item.
</p>
<hr/>
+<h3>Blockquotes</h3>
+<p>
+Blockquotes are, in terms of syntax and behavior, actually another
+type of list, started with an initial space, followed by <tt>&gt; </tt>:
+</p>
+<pre>
+ &gt; This is a quoted paragraph.
+The paragraph continues on the next line.
+ &gt; Here begins a new quoted paragraph.
+</pre>
+<hr/>
<h3>Preformatted blocks</h3>
<p>
<b>Preformatted blocks start with a single tab:</b>
diff --git a/emparse b/emparse
index 5ddb585..7423bb2 100755
--- a/emparse
+++ b/emparse
@@ -7,6 +7,7 @@ END { breakblock() }
/^$/ { breakblock(); getline }
expectblock && /^ / { newblock("table") }
+expectblock && /^ > / { newblock("blockquote") }
expectblock && /^ - / { newblock("ul") }
expectblock && /^ [0-9]+\. / { newblock("ol") }
expectblock && /^ \[[0-9]+\] / { newblock("nl") }
@@ -23,9 +24,9 @@ expectblock { newblock("p") }
openblock == "pre" { sub("^ ", ""); $0 = escape($0); printf "%s\n", $0; next }
+openblock == "blockquote" && /^ > / { item(1, "blockquote", line) }
openblock == "ul" && /^ - / { item(1, "ul", line) }
openblock == "ol" && /^ [0-9]+\. / { item(1, "ol", line) }
-#openblock == "nl" && /^ \[[0-9]+\] [^ ]+$/ { next } # hyperlink reference
openblock == "nl" && /^ \[[0-9]+\] / { item(1, "nl", line) } # text reference
openblock == "dl" && /^ .*: / { term(line) }
@@ -135,7 +136,10 @@ function breakblock() {
printf "(%s:%d) warning: open <%s> closed at block break\n", ARGV[1], NR, openformat > "/dev/stderr"
}
if (openitem) {
- printf "</li>\n"
+ if (openblock == "blockquote")
+ printf "</p>\n"
+ else
+ printf "</li>\n"
while (itemlevel-- > 1)
closetag(openblock)
itemlevel = 1
@@ -160,17 +164,22 @@ function heading(level, line) {
}
function item(level, type, line) {
+ if (type == "blockquote") {
+ if (openitem) printf "</p>"
+ openitem = 1
+ sub("^ > ", "")
+ printf "<p>"
+ return
+ }
if (openitem) printf "</li>"
openitem = 1
- if (type != "nl") {
- for (; itemlevel < level; itemlevel++) {
- printf "<%s>\n", type
- leveltype[itemlevel+1] = type
- }
- for (; itemlevel > level; itemlevel--) {
- printf "</%s>\n", leveltype[itemlevel]
- leveltype[itemlevel] = ""
- }
+ for (; itemlevel < level; itemlevel++) {
+ printf "<%s>\n", type
+ leveltype[itemlevel+1] = type
+ }
+ for (; itemlevel > level; itemlevel--) {
+ printf "</%s>\n", leveltype[itemlevel]
+ leveltype[itemlevel] = ""
}
if (type == "ul") {
sub("^ +- ", "")
@@ -185,7 +194,7 @@ function item(level, type, line) {
if (type == "nl") {
match($0, "\\[[0-9]+\\]")
v = substr($0, RSTART+1, RLENGTH-2)
- sub("^ +\\[[0-9]+\\] ", "")
+ sub("^ \\[[0-9]+\\] ", "")
printf "<li value=\"%s\" id=\"ref%s\">", v, v
}
}
diff --git a/test.em b/test.em
index 755736e..2965c09 100644
--- a/test.em
+++ b/test.em
@@ -8,6 +8,11 @@ Here is an asterisk at the end of a word*.
Here is an *unfinished inline formatting tag.
+ > Perhaps quotes could be regarded as lists.
+The paragraph goes on until a new "item" comes.
+ > Here, a new paragraph is started.
+Yeah, this seems like a very em-like approach.
+
- Here is an
unordered list item.
- Here is another.
diff --git a/test.html b/test.html
index cd98612..17f5566 100644
--- a/test.html
+++ b/test.html
@@ -11,6 +11,13 @@ Here is an asterisk at the end of a word*.
<p>
Here is an <i>unfinished inline formatting tag.
</i></p>
+<blockquote>
+<p>Perhaps quotes could be regarded as lists.
+The paragraph goes on until a new "item" comes.
+</p><p>Here, a new paragraph is started.
+Yeah, this seems like a very em-like approach.
+</p>
+</blockquote>
<ul>
<li>Here is an
unordered list item.