Htmlize code block highlighting

Signed-off-by: Magic_RB <magic_rb@redalder.org>
This commit is contained in:
Magic_RB 2021-05-24 00:10:12 +02:00
parent 2edfef83b3
commit f34d6fa4fa
No known key found for this signature in database
GPG key ID: 08D5287CC5DDCA0E
6 changed files with 1423 additions and 23 deletions

View file

@ -1,2 +1,3 @@
# website # website
To update the `org.css` file, you need to run `nix build .#generateCss.x86_64-linux && ./result` in the project root. This is only necessary when `modus-themes` is updated, not when a new major mode is added.

1287
assets/css/org.css Normal file

File diff suppressed because it is too large Load diff

View file

@ -16,6 +16,38 @@
"type": "github" "type": "github"
} }
}, },
"hcl-mode": {
"flake": false,
"locked": {
"lastModified": 1594425120,
"narHash": "sha256-Ai3OpQPmEQg96Q4JRJJM7vUY8G23l0FUGb1lQsU7SRY=",
"owner": "purcell",
"repo": "emacs-hcl-mode",
"rev": "e12b1df2ca28d2b06c471cd709c038a2dc0bcdbd",
"type": "github"
},
"original": {
"owner": "purcell",
"repo": "emacs-hcl-mode",
"type": "github"
}
},
"modus-themes": {
"flake": false,
"locked": {
"lastModified": 1621753731,
"narHash": "sha256-HFYsSPJWAY2/lYk8u1UxHMoe2l8taI6BvDZDfIO0pnE=",
"owner": "protesilaos",
"repo": "modus-themes",
"rev": "11006063c2f294adad827d42ab04ee239e85eb64",
"type": "github"
},
"original": {
"owner": "protesilaos",
"repo": "modus-themes",
"type": "github"
}
},
"nixng": { "nixng": {
"inputs": { "inputs": {
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
@ -78,9 +110,28 @@
"root": { "root": {
"inputs": { "inputs": {
"emacs-htmlize": "emacs-htmlize", "emacs-htmlize": "emacs-htmlize",
"hcl-mode": "hcl-mode",
"modus-themes": "modus-themes",
"nixng": "nixng", "nixng": "nixng",
"nixpkgs": "nixpkgs_2", "nixpkgs": "nixpkgs_2",
"org-thtml": "org-thtml" "org-thtml": "org-thtml",
"web-mode": "web-mode"
}
},
"web-mode": {
"flake": false,
"locked": {
"lastModified": 1612115905,
"narHash": "sha256-wZ+Sneh+vulcSs+n9fXHG321k9BauBiQvVJ6zw+cWrM=",
"owner": "fxbois",
"repo": "web-mode",
"rev": "8ef47935d638902ba35a557cae5edd6ab6ab1346",
"type": "github"
},
"original": {
"owner": "fxbois",
"repo": "web-mode",
"type": "github"
} }
} }
}, },

View file

@ -1,17 +1,24 @@
{ {
inputs = { inputs = {
nixpkgs.url = "nixpkgs"; nixpkgs.url = "nixpkgs";
org-thtml = {
url = "github:juanjosegarciaripoll/org-thtml"; org-thtml = { url = "github:juanjosegarciaripoll/org-thtml"; flake = false; };
flake = false; emacs-htmlize = { url = "github:hniksic/emacs-htmlize"; flake = false; };
}; modus-themes = { url = "github:protesilaos/modus-themes"; flake = false; };
emacs-htmlize = { web-mode = { url = "github:fxbois/web-mode"; flake = false; };
url = "github:hniksic/emacs-htmlize"; hcl-mode = { url = "github:purcell/emacs-hcl-mode"; flake = false; };
flake = false;
};
}; };
outputs = { self, nixpkgs, nixng, org-thtml, emacs-htmlize, ... }@inputs: outputs = { self
, nixpkgs
, nixng
, org-thtml
, emacs-htmlize
, modus-themes
, web-mode
, hcl-mode
, ...
}@inputs:
let let
supportedSystems = [ "x86_64-linux" "i686-linux" "aarch64-linux" ]; supportedSystems = [ "x86_64-linux" "i686-linux" "aarch64-linux" ];
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system); forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system);
@ -20,13 +27,23 @@
name = which; name = which;
version = "0.1"; version = "0.1";
src = ./.; src = ./.;
nativeBuildInputs = [ pkgs.emacs ]; nativeBuildInputs = [ pkgs.utillinux pkgs.emacs ];
buildPhase = '' buildPhase = ''
cp ${org-thtml}/ox-thtml.el ./ox-thtml.el export TMPDIR="$(mktemp -d)" HOME=$(pwd)/tmp
cp ${emacs-htmlize}/htmlize.el ./htmlize.el emacs -nw --fg-daemon &
mkdir tmp && export HOME=$(pwd)/tmp
emacs --script ./make.el -- ${which} timeout 10 bash -c 'until [ -e $TMPDIR/emacs$(id -u) ] ; do sleep 0.1 ; done'
emacsclient -e $'(add-to-list \'load-path "${org-thtml}")'
emacsclient -e $'(add-to-list \'load-path "${modus-themes}")'
emacsclient -e $'(add-to-list \'load-path "${emacs-htmlize}")'
emacsclient -e $'(add-to-list \'load-path "${web-mode}")'
emacsclient -e $'(add-to-list \'load-path "${hcl-mode}")'
emacsclient -e '(load-file "./make.el")'
emacsclient -e '(magic_rb/publish-website "${which}")'
emacsclient -e '(kill-emacs)'
find public_html -name 'sitemap.*' -exec rm {} \; find public_html -name 'sitemap.*' -exec rm {} \;
''; '';
@ -64,6 +81,42 @@
'' ''
); );
generateCss = forAllSystems (system:
let
pkgs = import nixpkgs { inherit system; };
script = pkgs.writeText "init.el"
''
(add-to-list 'load-path "${modus-themes}")
(add-to-list 'load-path "${emacs-htmlize}")
(require 'org)
(require 'ox)
(require 'ox-html)
(require 'modus-themes)
(load-theme 'modus-operandi t nil)
(org-html-htmlize-generate-css)
(with-current-buffer "*html*"
(write-file (getenv "OUTFILE")))
(kill-emacs)
'';
in
pkgs.writeShellScript "generate-css"
''
export PATH=$PATH:${pkgs.emacs}/bin
export OUTFILE="$(mktemp)" TMPDIR="$(mktemp -d)" HOME=$TMPDIR
emacs -l ${script}
mv $OUTFILE ./assets/css/org.css
rm -r $TMPDIR
''
);
defaultPackage = forAllSystems (system: defaultPackage = forAllSystems (system:
self.website.${system} self.website.${system}
); );

21
make.el
View file

@ -3,9 +3,10 @@
;;; ;;;
;;; Code: ;;; Code:
(load-file "./ox-thtml.el") (package-initialize)
;; (load-file "./htmlize.el")
(require 'org) (require 'org)
(require 'ox) (require 'ox)
(require 'ox-html) (require 'ox-html)
@ -13,6 +14,10 @@
(unless (file-exists-p d) (unless (file-exists-p d)
(make-directory d))) (make-directory d)))
(require 'web-mode)
(require 'hcl-mode)
(ignore-errors (require 'ox-thtml))
;; https://alhassy.github.io/AlBasmala.html#Floating-TOC ;; https://alhassy.github.io/AlBasmala.html#Floating-TOC
(advice-add 'org-html--translate :before-until 'display-toc-as-toc) (advice-add 'org-html--translate :before-until 'display-toc-as-toc)
(defun display-toc-as-toc (phrase info) (defun display-toc-as-toc (phrase info)
@ -27,8 +32,8 @@
org-export-headline-levels 6 org-export-headline-levels 6
; emacs-htmlize does not work when Emacs is ran in =script= mode unfortunately ; emacs-htmlize does not work when Emacs is ran in =script= mode unfortunately
;; org-html-html5-fancy t ;; org-html-html5-fancy t
;; org-html-htmlize-output-type 'inline-css org-html-htmlize-output-type 'css)
)
(defvar magic_rb/asset-include (defvar magic_rb/asset-include
"\\(ttf\\|svg\\|jpg\\|gif\\|png\\|css\\|js\\|el\\|nb\\|ipynb\\|pdf\\|xml\\)") "\\(ttf\\|svg\\|jpg\\|gif\\|png\\|css\\|js\\|el\\|nb\\|ipynb\\|pdf\\|xml\\)")
@ -171,10 +176,12 @@
:components ("nixng-assets" :components ("nixng-assets"
"nixng-examples")))) "nixng-examples"))))
(cond ((member "redalder.org" command-line-args-left) (defun magic_rb/publish-website (website)
"Publish WEBSITE."
(cond ((string= website "redalder.org")
(org-publish "redalder-publish" t)) (org-publish "redalder-publish" t))
((member "nixng.org" command-line-args-left) ((string= website "nixng.org")
(org-publish "nixng-publish"))) (org-publish "nixng-publish"))))
(provide 'make) (provide 'make)
;;; make.el ends here ;;; make.el ends here

View file

@ -2,6 +2,7 @@
<title>{{title}}</title> <title>{{title}}</title>
<link rel="stylesheet" href="/css/style.css"/> <link rel="stylesheet" href="/css/style.css"/>
<link rel="stylesheet" href="/css/org.css"/>
<link rel="icon" href="/icons/favicon-512x512.png" type="image/png" sizes="512x512"> <link rel="icon" href="/icons/favicon-512x512.png" type="image/png" sizes="512x512">
</head> </head>