Procházet zdrojové kódy

ox-html: Include the line number as a data attribute

* lisp/ox-html.el (org-html-do-format-code): If line numbers are enabled
then include a data-ox-html-linenr attribute that contains this line's
line number.

This allows you to have more control over line number formatting and
placement. For example, the following CSS hides the span that contains
the line number, and uses a CSS :before property to position and format
the line number with a border instead of a semi-colon separating content
and line number.

span.linenr { display: none; }

code[data-ox-html-linenr]:before {
  content: attr(data-ox-html-linenr);
  display: inline-block;
  border-right: 1px solid;
  width: 1rem;
  text-align: right;
}

TINYCHANGE
Nik Clayton před 6 roky
rodič
revize
380e2f7f82
1 změnil soubory, kde provedl 5 přidání a 1 odebrání
  1. 5 1
      lisp/ox-html.el

+ 5 - 1
lisp/ox-html.el

@@ -2255,7 +2255,11 @@ line of code."
 		(format "<span class=\"linenr\">%s</span>"
 			(format num-fmt line-num)))
 	      ;; Transcoded src line.
-	      (format "<code>%s</code>" loc)
+	      (format "<code%s>%s</code>"
+                      (if num-start
+                          (format " data-ox-html-linenr=\"%s\"" line-num)
+                        "")
+                      loc)
 	      ;; Add label, if needed.
 	      (when (and ref retain-labels) (format " (%s)" ref))))
        ;; Mark transcoded line as an anchor, if needed.