aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md23
-rw-r--r--groff-mom.outlang (renamed from groff.outlang)0
-rw-r--r--groff-ms.outlang40
-rwxr-xr-xhighlight.lua43
4 files changed, 101 insertions, 5 deletions
diff --git a/README.md b/README.md
index bfb27ec..73a9fe1 100644
--- a/README.md
+++ b/README.md
@@ -23,19 +23,20 @@ To build the sample `select-from.ebnf`, type something like:
cat samples/select-from.ebnf | ./ebnf.sno | pic | groff -Tps >select-from.ps
-## HIGHLIGHT
+## HIGHLIGHT (SNOBOL4)
`highlight.sno` is a small preprocessor written in [CSNOBOL4](http://www.snobol4.org/csnobol4/)
that processes blocks of source code embedded in your Groff document with
[GNU Source-highlight](http://www.gnu.org/software/src-highlite/) to produce
syntax highlighted text.
-The output is formatted according to `groff.outlang` which currently only works with
-the [mom macros](http://www.schaffter.ca/mom/).
+The output is formatted according to `groff.outlang`.
+Versions for the [mom macros](http://www.schaffter.ca/mom/) (`groff-mom.outlang`) and
+for the classic ms macros (`groff-ms.outlang`) are provided.
-Example:
+Example (mom):
-```
+```groff
.QUOTE
.CODE
.HIGHLIGHT c
@@ -51,6 +52,18 @@ int main(int argc, char **argv)
.QUOTE OFF
```
+## HIGHLIGHT (Lua)
+
+`highlight.lua` is a reimplementation of `highlight.sno` in Lua 5.2 and may work
+better on some operating systems.
+
+In addition to the aforementioned syntax, the Lua version allows you to specify a filename after
+the language identifier to process an external file:
+
+```groff
+.HIGHLIGHT c hello.c
+```
+
## UML
`uml.sno` is a small preprocessor (again requires CSNOBOL4) that
diff --git a/groff.outlang b/groff-mom.outlang
index 60e217e..60e217e 100644
--- a/groff.outlang
+++ b/groff-mom.outlang
diff --git a/groff-ms.outlang b/groff-ms.outlang
new file mode 100644
index 0000000..c7af6db
--- /dev/null
+++ b/groff-ms.outlang
@@ -0,0 +1,40 @@
+extension "ms"
+
+bold "\f[CB]$text\fP"
+italics "\f[CI]$text\fP"
+underline "\f[CI]$text\fP"
+fixed "\f[CR]$text\fP"
+color "\m[$style]$text\m[black]"
+
+#anchor "$infilename : $linenum - $text"
+#reference "$text \(-> $infile:$linenum, page : $infilename:$linenum"
+
+# lines may be empty, so begin them with the non-spacing \&
+# also, this allows "." and "'" at the beginning of the line
+lineprefix "\&"
+
+colormap
+"green" "green"
+"red" "red"
+"darkred" "darkred"
+"blue" "blue"
+"brown" "brown"
+"pink" "pink"
+"yellow" "yellow"
+"cyan" "cyan"
+"purple" "purple"
+"orange" "orange"
+"brightorange" "brightorange"
+"brightgreen" "brightgreen"
+"darkgreen" "darkgreen"
+"black" "black"
+"teal" "teal"
+"gray" "gray"
+"darkblue" "darkblue"
+default "black"
+end
+
+translations
+"\\" "\\e"
+#"\t" " "
+end
diff --git a/highlight.lua b/highlight.lua
new file mode 100755
index 0000000..eab9d2b
--- /dev/null
+++ b/highlight.lua
@@ -0,0 +1,43 @@
+#!/usr/local/bin/lua52
+local pipe
+local line_prefix = ''
+
+for line in io.input():lines() do
+ if pipe then
+ if line:match("^%. *HIGHLIGHT *") then
+ pipe:close()
+ pipe = nil
+ -- empty line to fix up line numbering
+ -- FIXME: the linefeed is necessary because source-highlight did not
+ -- terminate the last line
+ print "\n."
+ else
+ -- the last linefeed is not piped, so that we don't get empty lines
+ -- at the end of a code block
+ pipe:write(line_prefix, line)
+ line_prefix = '\n'
+ end
+ else
+ local lang = line:match("^%. *HIGHLIGHT +(.*)$")
+ if lang then
+ if lang:match(" ") then
+ local file
+ lang, file = lang:match("^([^ ]*) +(.*)$")
+ lang = lang == "default" and "--failsafe" or "-s "..lang
+ os.execute("source-highlight --outlang-def groff.outlang "..lang.." -i "..file)
+ -- FIXME: Emit .lf statement
+ -- FIXME: Omit the last character
+ print ""
+ else
+ lang = lang == "default" and "--failsafe" or "-s "..lang
+ pipe = io.popen("source-highlight --outlang-def groff.outlang "..lang, "w")
+ -- empty line to fix up line numbering
+ print "."
+ -- omit linefeed on first print
+ line_prefix = ''
+ end
+ else
+ print(line)
+ end
+ end
+end