aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-01-31 00:14:05 +0000
committerJohn Ankarström <john@ankarstrom.se>2021-01-31 00:14:05 +0000
commit6a0cf3b57a51d5f3c60bd1bcc53619dce9cf0355 (patch)
tree63b327f38cfff3bf6a7ee531847f27b142cfb4fd
parent4de8bc7d3539ae3a8e64b7132b87c344eb46a5cb (diff)
downloadem-6a0cf3b57a51d5f3c60bd1bcc53619dce9cf0355.tar.gz
Remove (linktext) links, add <link> links
-rw-r--r--README53
-rw-r--r--README.html59
-rwxr-xr-xem1
-rwxr-xr-xemcollect7
-rwxr-xr-xemparse74
-rw-r--r--test.em6
-rw-r--r--test.html7
7 files changed, 121 insertions, 86 deletions
diff --git a/README b/README
index 8dd0f01..b93212b 100644
--- a/README
+++ b/README
@@ -8,7 +8,7 @@ never more than a single possible em representation.
Em values readability over expressiveness. This means that it is rather limited
in terms of what HTML it can produce. Most noticeably, only a very limited
-form of inline links are supported (see *Lists* and *Inline formatting*).
+form of inline links are supported (see *Hyperlinks* below).
Em also values consistency and predictability. As such, the syntax is rather
strict. This makes it a bit harder to learn, but much more predictable.
@@ -17,10 +17,6 @@ Em's complete and exact syntax is defined by its implementation [1], but a
general description follows below. For longer examples, see the source
code for this text [2] or the test file [3].
- [1] ../tree/README
- [2] ../tree/test.em
- [3] ../tree/emparse
-
Em is implemented in portable awk, with an rc script to bind it together.
It is written on and for Plan 9 primarily, but the rc code can (more or less)
trivially be translated to POSIX shell; the work just hasn't been done yet.
@@ -58,6 +54,16 @@ Inline references are created with square brackets:
[1] The quick brown fox ...
+In the final output, the inline reference becomes a link to the
+reference item later in the document:
+
+ <p>Example of an inline reference [<a href="#ref1">1</a>].
+ </p>
+ <ol class="reflist">
+ <li value="1" id="ref1">The quick brown fox ...
+ </li>
+ </ol>
+
For more information about references, see *Reference lists* below.
---
@@ -65,20 +71,21 @@ For more information about references, see *Reference lists* below.
=== Hyperlinks ===
Hyperlinks are a special case of inline references. When an inline
-reference refers to a reference containing only a web address,
-the inline reference is replaced with a hyperlink to that address.
+reference refers to a reference containing a single link, the inline
+reference points directly to that link, rather than at the reference.
- It is available for download [2].
+ It is available for download [1].
- [2] v1.tgz
+ [1] <./v1.tgz>
The above example translates to the following HTML:
- <p>It is available for download (<a href="v1.tgz">link</a>).
+ <p>It is available for download [<a href="./v1.tgz">1</a>].
</p>
-
-The default link text ("link") can be changed by setting
-the `linktext` environment variable.
+ <ol class="reflist">
+ <li value="1" id="ref1"><a href="./v1.tgz">./v1.tgz</a>
+ </li>
+ </ol>
---
@@ -147,15 +154,13 @@ to which you can make inline references:
[1] The quick brown fox ...
_Note:_ There is a special type of reference list item called a
-*hyperlink reference*. It contains only a single word,
-without whitespace:
+*hyperlink reference*. It contains only a single link:
- [1] http://example.com
+ [1] <http://example.com>
-Hyperlink reference items are removed in the final output,
-but you can still reference them inline:
-
- You can download the file here [1].
+Hyperlink references behave just like normal references, except
+inline references to them link directly to the link rather than the
+reference item.
---
@@ -176,3 +181,11 @@ _Paragraphs start with no space:_
with two lines.
This is another paragraph.
+
+---
+
+== References ==
+
+ [1] <../tree/README>
+ [2] <../tree/test.em>
+ [3] <../tree/emparse>
diff --git a/README.html b/README.html
index c6fa908..efcee0b 100644
--- a/README.html
+++ b/README.html
@@ -12,19 +12,17 @@ never more than a single possible em representation.
<p>
Em values readability over expressiveness. This means that it is rather limited
in terms of what HTML it can produce. Most noticeably, only a very limited
-form of inline links are supported (see <i>Lists</i> and <i>Inline formatting</i>).
+form of inline links are supported (see <i>Hyperlinks</i> below).
</p>
<p>
Em also values consistency and predictability. As such, the syntax is rather
strict. This makes it a bit harder to learn, but much more predictable.
</p>
<p>
-Em's complete and exact syntax is defined by its implementation (<a href="../tree/README">link</a>), but a
+Em's complete and exact syntax is defined by its implementation [<a href="../tree/README">1</a>], but a
general description follows below. For longer examples, see the source
-code for this text (<a href="../tree/test.em">link</a>) or the test file (<a href="../tree/emparse">link</a>).
+code for this text [<a href="../tree/test.em">2</a>] or the test file [<a href="../tree/emparse">3</a>].
</p>
-<ol class="reflist" style="font-size: small;">
-</ol>
<p>
Em is implemented in portable awk, with an rc script to bind it together.
It is written on and for Plan 9 primarily, but the rc code can (more or less)
@@ -66,31 +64,43 @@ Example of an inline reference [1].
[1] The quick brown fox ...
</pre>
<p>
+In the final output, the inline reference becomes a link to the
+reference item later in the document:
+</p>
+<pre>
+&lt;p&gt;Example of an inline reference [&lt;a href="#ref1"&gt;1&lt;/a&gt;].
+&lt;/p&gt;
+&lt;ol class="reflist"&gt;
+&lt;li value="1" id="ref1"&gt;The quick brown fox ...
+&lt;/li&gt;
+&lt;/ol&gt;
+</pre>
+<p>
For more information about references, see <i>Reference lists</i> below.
</p>
<hr/>
<h3>Hyperlinks</h3>
<p>
Hyperlinks are a special case of inline references. When an inline
-reference refers to a reference containing only a web address,
-the inline reference is replaced with a hyperlink to that address.
+reference refers to a reference containing a single link, the inline
+reference points directly to that link, rather than at the reference.
</p>
<pre>
-It is available for download [2].
+It is available for download [1].
- [2] v1.tgz
+ [1] &lt;./v1.tgz&gt;
</pre>
<p>
The above example translates to the following HTML:
</p>
<pre>
-&lt;p&gt;It is available for download (&lt;a href="v1.tgz"&gt;link&lt;/a&gt;).
+&lt;p&gt;It is available for download [&lt;a href="./v1.tgz"&gt;1&lt;/a&gt;].
&lt;/p&gt;
+&lt;ol class="reflist"&gt;
+&lt;li value="1" id="ref1"&gt;&lt;a href="./v1.tgz"&gt;./v1.tgz&lt;/a&gt;
+&lt;/li&gt;
+&lt;/ol&gt;
</pre>
-<p>
-The default link text ("link") can be changed by setting
-the <tt>linktext</tt> environment variable.
-</p>
<hr/>
<h2>Block-level formatting</h2>
<ul>
@@ -168,19 +178,16 @@ See footnote [1].
</pre>
<p>
<b>Note:</b> There is a special type of reference list item called a
-<i>hyperlink reference</i>. It contains only a single word,
-without whitespace:
+<i>hyperlink reference</i>. It contains only a single link:
</p>
<pre>
- [1] http://example.com
+ [1] &lt;http://example.com&gt;
</pre>
<p>
-Hyperlink reference items are removed in the final output,
-but you can still reference them inline:
+Hyperlink references behave just like normal references, except
+inline references to them link directly to the link rather than the
+reference item.
</p>
-<pre>
-You can download the file here [1].
-</pre>
<hr/>
<h3>Preformatted blocks</h3>
<p>
@@ -202,3 +209,11 @@ with two lines.
<pre>
This is another paragraph.
</pre>
+<hr/>
+<h2>References</h2>
+<ol class="reflist">
+<li value="1" id="ref1"><a href="../tree/README">../tree/README</a>
+</li><li value="2" id="ref2"><a href="../tree/test.em">../tree/test.em</a>
+</li><li value="3" id="ref3"><a href="../tree/emparse">../tree/emparse</a>
+</li>
+</ol>
diff --git a/em b/em
index 62d6d26..649ebd6 100755
--- a/em
+++ b/em
@@ -10,7 +10,6 @@ if(~ $#* 0){
if not
file=$1
-if(~ $#linktext 0) linktext=link
hrefs=`'
'{emcollect $file}
for(href in $hrefs){
diff --git a/emcollect b/emcollect
index 50f6a17..30cb7c0 100755
--- a/emcollect
+++ b/emcollect
@@ -7,12 +7,13 @@ function collect(line) {
right = $0
sub("^ \\[", "", left)
sub("\\].*$", "", left)
- sub("^ \\[[0-9a-z]+\\] ", "", right)
+ sub("^ \\[[0-9]+\\] <", "", right)
+ sub(">$", "", right)
printf "%s=%s\n", left, right
}
BEGIN { expectblock = 1 }
/^$/ { expectblock = 1; getline }
-expectblock && /^ \[[0-9a-z]+\] / { block = "nl"; expectblock = 0 }
-block = "nl" && /^ \[[0-9a-z]+\] [^ ]+$/ { collect($0); next }
+expectblock && /^ \[[0-9]+\] / { block = "nl"; expectblock = 0 }
+block = "nl" && /^ \[[0-9]+\] <[^ ]+>$/ { collect($0); next }
diff --git a/emparse b/emparse
index 3184488..5ddb585 100755
--- a/emparse
+++ b/emparse
@@ -2,19 +2,14 @@
# aux/emparse -- parse em source
-BEGIN {
- expectblock = 1
- itemlevel = 1
- linktext = ENVIRON["linktext"]
- if (!linktext) linktext = "link"
-}
+BEGIN { expectblock = 1; itemlevel = 1 }
END { breakblock() }
/^$/ { breakblock(); getline }
expectblock && /^ / { newblock("table") }
expectblock && /^ - / { newblock("ul") }
-expectblock && /^ [0-9a-z]+\. / { newblock("ol") }
-expectblock && /^ \[[0-9a-z]+\] / { newblock("nl") }
+expectblock && /^ [0-9]+\. / { newblock("ol") }
+expectblock && /^ \[[0-9]+\] / { newblock("nl") }
expectblock && /^ .*: / { newblock("dl") }
expectblock && /^ / { newblock("pre") }
expectblock && /^---$/ { expectblock = 0; printf "<hr/>\n"; next }
@@ -28,36 +23,43 @@ expectblock { newblock("p") }
openblock == "pre" { sub("^ ", ""); $0 = escape($0); printf "%s\n", $0; next }
-openblock == "ul" && /^ - / { item(1, "ul", line) }
-openblock == "ol" && /^ [0-9a-z]+\. / { item(1, "ol", line) }
-openblock == "nl" && /^ \[[0-9a-z]+\] [^ ]+$/ { next } # hyperlink reference
-openblock == "nl" && /^ \[[0-9a-z]+\] / { item(1, "nl", line) } # text reference
-openblock == "dl" && /^ .*: / { term(line) }
-
-(openblock == "ul" || openblock == "ol") && /^ -/ { item(2, "ul", line) }
-(openblock == "ul" || openblock == "ol") && /^ [0-9a-z]+\./ { item(2, "ol", line) }
-(openblock == "ul" || openblock == "ol") && /^ -/ { item(3, "ul", line) }
-(openblock == "ul" || openblock == "ol") && /^ [0-9a-z]+\./ { item(3, "ol", line) }
-(openblock == "ul" || openblock == "ol") && /^ -/ { item(4, "ul", line) }
-(openblock == "ul" || openblock == "ol") && /^ [0-9a-z]+\./ { item(4, "ol", line) }
-(openblock == "ul" || openblock == "ol") && /^ -/ { item(5, "ul", line) }
-(openblock == "ul" || openblock == "ol") && /^ [0-9a-z]+\./ { item(5, "ol", line) }
-(openblock == "ul" || openblock == "ol") && /^ -/ { item(6, "ul", line) }
-(openblock == "ul" || openblock == "ol") && /^ [0-9a-z]+\./ { item(6, "ol", 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) }
+
+(openblock == "ul" || openblock == "ol") && /^ -/ { item(2, "ul", line) }
+(openblock == "ul" || openblock == "ol") && /^ [0-9]+\./ { item(2, "ol", line) }
+(openblock == "ul" || openblock == "ol") && /^ -/ { item(3, "ul", line) }
+(openblock == "ul" || openblock == "ol") && /^ [0-9]+\./ { item(3, "ol", line) }
+(openblock == "ul" || openblock == "ol") && /^ -/ { item(4, "ul", line) }
+(openblock == "ul" || openblock == "ol") && /^ [0-9]+\./ { item(4, "ol", line) }
+(openblock == "ul" || openblock == "ol") && /^ -/ { item(5, "ul", line) }
+(openblock == "ul" || openblock == "ol") && /^ [0-9]+\./ { item(5, "ol", line) }
+(openblock == "ul" || openblock == "ol") && /^ -/ { item(6, "ul", line) }
+(openblock == "ul" || openblock == "ol") && /^ [0-9]+\./ { item(6, "ol", line) }
{ format($0) } # inline formatting
function format(line) {
line = escape(line)
- n = split(line, w, "[ ]")
+ n = split(line, w, "[ ]") # TODO: this removes spaces...
for (i = 0; i <= n; i++) {
if (w[i] == "") continue;
- if (match(w[i], "^\\[[0-9a-z]+\\]$"))
+ if (match(w[i], "^&lt;(\\./.*|\\.\\./.*|.*/.*)&gt;$"))
+ w[i] = link(substr(w[i], 5, RLENGTH-8))
+ else if (match(w[i], "^&lt;(\\./.*|\\.\\./.*|.*/.*)&gt;[.,:;?!)]$"))
+ w[i] = link(substr(w[i], 5, RLENGTH-9)) substr(w[i], RLENGTH)
+ else if (match(w[i], "^&lt;(\\./.*|\\.\\./.*|.*/.*)&gt;\\)[.,:;?!]$"))
+ w[i] = link(substr(w[i], 5, RLENGTH-10)) substr(w[i], RLENGTH-1)
+
+ if (match(w[i], "^\\[[0-9]+\\]$"))
w[i] = ref(substr(w[i], 2, RLENGTH-2))
- else if (match(w[i], "^\\[[0-9a-z]+\\][.,:;?!)]$"))
+ else if (match(w[i], "^\\[[0-9]+\\][.,:;?!)]$"))
w[i] = ref(substr(w[i], 2, RLENGTH-3)) substr(w[i], RLENGTH)
- else if (match(w[i], "^\\[[0-9a-z]+\\]\\)[.,:;?!]$"))
+ else if (match(w[i], "^\\[[0-9]+\\]\\)[.,:;?!]$"))
w[i] = ref(substr(w[i], 2, RLENGTH-4)) substr(w[i], RLENGTH-1)
if (!openformat) {
@@ -112,7 +114,7 @@ function format(line) {
}
function opentag(name) {
- if (name == "nl") printf "<ol class=\"reflist\" style=\"font-size: small;\">\n"
+ if (name == "nl") printf "<ol class=\"reflist\">\n"
else printf "<%s>\n", name
}
@@ -175,15 +177,15 @@ function item(level, type, line) {
printf "<li>"
}
if (type == "ol") {
- match($0, "[0-9a-z]+\.")
+ match($0, "[0-9]+\.")
v = substr($0, RSTART, RLENGTH-1)
- sub("^ +[0-9a-z]+\. ", "")
+ sub("^ +[0-9]+\. ", "")
printf "<li value=\"%s\">", v
}
if (type == "nl") {
- match($0, "\\[[0-9a-z]+\\]")
+ match($0, "\\[[0-9]+\\]")
v = substr($0, RSTART+1, RLENGTH-2)
- sub("^ +\\[[0-9a-z]+\\] ", "")
+ sub("^ +\\[[0-9]+\\] ", "")
printf "<li value=\"%s\" id=\"ref%s\">", v, v
}
}
@@ -201,10 +203,14 @@ function term(line, t) { # t is a local variable
function ref(v) {
if (ENVIRON["ref" v] != "")
- return "(<a href=\"" ENVIRON["ref" v] "\">" linktext "</a>)"
+ return "[<a href=\"" ENVIRON["ref" v] "\">" v "</a>]"
return "[<a href=\"#ref" v "\">" v "</a>]"
}
+function link(h) {
+ return "<a href=\"" h "\">" h "</a>"
+}
+
function escape(s) {
gsub("&", "\\&amp;", s)
gsub("<", "\\&lt;", s)
diff --git a/test.em b/test.em
index 4fb6997..755736e 100644
--- a/test.em
+++ b/test.em
@@ -1,6 +1,6 @@
= Em example =
-This is an example of *em* [a].
+This is an example of *em*.
Here is some `teletype text`, some _bold text_.
@@ -20,10 +20,10 @@ ordered list item.
1. With another list inside it [1]
- And yet another list
- Inside that list
- 2. And now we're back at the first level
+ 2. And now we're back at the first level [2]
[1] Reference list item
- [a] http://example.com
+ [2] <http://example.com/abc>
term: definition
long term: long
diff --git a/test.html b/test.html
index fca431b..cd98612 100644
--- a/test.html
+++ b/test.html
@@ -1,6 +1,6 @@
<h1>Em example</h1>
<p>
-This is an example of <i>em</i> (<a href="http://example.com">link</a>).
+This is an example of <i>em</i>.
</p>
<p>
Here is some <tt>teletype text</tt>, some <b>bold text</b>.
@@ -32,11 +32,12 @@ ordered list item.
</li><li>Inside that list
</li></ul>
</ol>
-<li value="2">And now we're back at the first level
+<li value="2">And now we're back at the first level [<a href="http://example.com/abc">2</a>]
</li>
</ol>
-<ol class="reflist" style="font-size: small;">
+<ol class="reflist">
<li value="1" id="ref1">Reference list item
+</li><li value="2" id="ref2"><a href="http://example.com/abc">http://example.com/abc</a>
</li>
</ol>
<dl>