From 48db2f04833ce74fe28bfe1f3f673e2416e3a7cb Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Sun, 21 May 2023 20:23:54 +0200 Subject: [PATCH] Started working on the custom .org exporter using pandoc NOTE: this breaks a lot of my custom css, so more work has to be done --- build.sh | 66 +++++++++++++- el/gruvbox.theme | 226 +++++++++++++++++++++++++++++++++++++++++++++++ el/html.template | 70 +++++++++++++++ el/pub.el | 7 +- 4 files changed, 367 insertions(+), 2 deletions(-) create mode 100644 el/gruvbox.theme create mode 100644 el/html.template diff --git a/build.sh b/build.sh index da4d7bd..08ca4d5 100755 --- a/build.sh +++ b/build.sh @@ -1,2 +1,66 @@ #!/bin/bash -yes yes | emacs --batch -l ./el/pub.el +# depends: pandoc, sed, awk + +root="$(dirname $0)" +srcdir="$root/src" +assetdir="$root/res" +builddir="$root/build" + +# pandoc syntax highlighting theme +pandocTheme="espresso" +# pandoc export target +pandocTarget="html5" +pandocTargetExtension="html" + +# function used to convert .org file to target format +function convertOrg() { + # read the org file as first argument + cat "$1" | \ + # pandoc does not support elisp syntax highlighting + # but it supports commonlisp, so we can just replace it + sed 's/elisp/commonlisp/' | \ + pandoc \ + -f org \ + -t $pandocTarget \ + -c '/base.css' \ + --template ./el/html.template \ + --highlight-style="$pandocTheme" \ + - | + # pandoc does not autoreplace the ->.org links, + # so we need to autodetect them and replace the file extension, + # with the extension of the format + sed -r "s/([\.]+\/[A-z\/\.0-9_-]*)\.org/\1\.$pandocTargetExtension/g" +} + +# delete old build artifacts +rm -rf $builddir +# create new build folder +mkdir -p $builddir + +# ASSETS +cp $assetdir/* -r $builddir + +prefix="s/^$(echo $srcdir | sed 's/\//\\\//')\///" + +# loop through all source files +find $srcdir -type f | \ + # remove leading $srcdir + sed "$prefix" | \ + while read file; do + # initialise builddir path + mkdir -p "$(dirname "$builddir/$file")" + + ext="$(echo $file | awk -F'.' '{ print $NF }')" + if [ "$ext" = "org" ]; then + # org files won't be called .org after conversion + # so we need to rename them + newName="$(echo $file | sed "s/\.org$/\.$pandocTargetExtension/")" + echo $newName + # me need to convert .org files + convertOrg $srcdir/$file \ + > $builddir/$newName + else + # all other files can just be copied to the build dir + cp $srcdir/$file $builddir/$file + fi + done diff --git a/el/gruvbox.theme b/el/gruvbox.theme new file mode 100644 index 0000000..5b99dac --- /dev/null +++ b/el/gruvbox.theme @@ -0,0 +1,226 @@ +{ + "metadata": { + "author": "Jakob Meier ", + "license": "MIT", + "name": "Gruvbox Pandoc theme", + "revision": 0 + }, + + "text-color": "#888888", + "background-color": "#666666", + "line-number-color": "#0000ff", + "line-number-background-color": "#00ff00", + + "text-styles": { + "Alert": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "Annotation": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "Attribute": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "BaseN": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "BuiltIn": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "Char": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "Comment": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "CommentVar": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "Constant": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "ControlFlow": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "DataType": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "DecVal": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "Documentation": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "Error": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "Extension": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "Float": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "Function": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "Import": { + "text-color": null, + "background-color": null, + "bold": null, + "italic": true, + "underline": false + }, + "Information": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "Keyword": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "Operator": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "Others": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "Preprocessor": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "RegionMarker": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "SpecialChar": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "SpecialString": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "String": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "Variable": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "VerbatimString": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + }, + "Warning": { + "text-color": "#ffffff", + "background-color": null, + "bold": true, + "italic": true, + "underline": false + } + } +} diff --git a/el/html.template b/el/html.template new file mode 100644 index 0000000..135372f --- /dev/null +++ b/el/html.template @@ -0,0 +1,70 @@ + + + + + + $for(author-meta)$ + + $endfor$ + $if(date-meta)$ + + $endif$ + $if(title-prefix)$$title-prefix$ - $endif$$pagetitle$ + + $if(quotes)$ + + $endif$ + $if(highlighting-css)$ + + $endif$ + $for(css)$ + + $endfor$ + $if(math)$ + $math$ + $endif$ + $for(header-includes)$ + $header-includes$ + $endfor$ + + + $for(include-before)$ + $include-before$ + $endfor$ + $if(title)$ +
+ + Up + + $if(date)$ +

$date$

+ $endif$ + +

$title$

+ + + $for(author)$ +

$author.name$

+

$author.affiliation$

+ $endfor$ + +
+ $endif$ + $if(toc)$ + + $endif$ + + $if(abstract)$ + +

Abstract: $abstract$

+ + $endif$ + + + $body$ + + diff --git a/el/pub.el b/el/pub.el index e20e134..656d0f0 100644 --- a/el/pub.el +++ b/el/pub.el @@ -1,6 +1,8 @@ (require 'ox-publish) -(setq package-list '(htmlize)) +(global-font-lock-mode 1) + +(setq package-list '(htmlize gruvbox-theme)) (package-initialize) ; fetch the list of packages available (unless package-archive-contents @@ -11,6 +13,9 @@ (unless (package-installed-p package) (package-install package))) +;;(require 'cl-lib) +;;(require 'ob-tangle) +(require 'gruvbox-theme) (require 'htmlize) (setq org-src-fontify-natively t) (setq org-html-htmlize-output-type 'css-inline) -- 2.38.5