I'm struggling to add <dl>
tags around a definition list with sed, and perhaps there is an easier way to do it (I'd love to know).
I would like to search a file for any lines that contain a <dt>
, but only match if the previous line does not contain <dt>
or <dd>
. When a match is found, insert a <dl>
.
My attempt so far (which doesn't match at all):
sed '/^((?!<dt>).)*$/ {
N
/<dt>/ {
s/<dt>/<dl><dt>/
}
}' file
And the file
# TODO #
* Set up mail transfer agent
* Reconfigure timezone
```bash
dpkg-reconfigure tzdata
```
# Hardware #
<dt>RAM</dt>
<dd>2GB</dd>
# Partitions #
<dt>`/dev/sda1`</dt>
<dd>/boot</dd>
<dt>`/dev/sda2`</dt>
<dd>/</dd>
The purpose of all of this is to write a parser that converts moinmoin wiki markup to markdown, for porting to a new wiki engine. The defintion list is currently made with the following rule:
sed -i 's/^ \(.*\):: \(.*\)$/ <dt>\1<\/dt>\n <dd>\2<\/dd>/' file
I would like the output to look like this:
# TODO #
* Set up mail transfer agent
* Reconfigure timezone
```bash
dpkg-reconfigure tzdata
```
# Hardware #
<dl>
<dt>RAM</dt>
<dd>2GB</dd>
</dl>
# Partitions #
<dl>
<dt>`/dev/sda1`</dt>
<dd>/boot</dd>
<dt>`/dev/sda2`</dt>
<dd>/</dd>
</dl>
Note that I'd like valid html as much as possible. There needs to be a closing tag for each opening tag.
<dt>...</dt>\n<dd>...</dt>\n
tags within another pair of<dl>...</dl>
or an entire sequence of pairs be enclosed?