(defun szotar-span-accent (word)
  "Replaces every occurence of .\" with an accent span."
  (let ((match (string-match ".\"" word)))
    (if match
        (concat (substring word 0 match)
                "<span class=\"accent\">"
                (substring word match (1+ match))
                (szotar-span-accent (substring word (+ match 2))))

(defun szotar-next-line ()
  "Takes the next line and prints its HTML representation."
  (if (re-search-forward "^\\(.*\\) = \\(.*\\)$" (point-max) t)
      (let* ((definition (match-string 2))
             (russian (szotar-span-accent (match-string 1))))
        (princ (concat "<p>\n"
                       "<span class=\"russian\">" russian "</span>\n"
                       "<span class=\"definition\">" definition "</span>\n"

(defun szotar-htmlize ()
  "Generates a CSS-driven HTML file from the current buffer.
The buffer is assumed to be in UTF-8 encoding."
  (with-output-to-temp-buffer (concat (buffer-name (current-buffer)) ".html")
    (princ (concat "<html>\n"
                   "<title>" (buffer-name (current-buffer)) "</title>\n"
                   "<link rel=\"stylesheet\" type=\"text/css\""
                   " href=\"szotar.css\" media=\"all\" />\n"
                   "<meta http-equiv=\"Content-Type\""
                   " content=\"text/html;charset=utf-8\" />\n"
      (goto-char (point-min))
      (while (szotar-next-line)))
    (princ "</body>\n</html>")))