diff --git a/README.md b/README.md index 133a65f..a9a299e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,30 @@ # CC-FORMAT -Scripts that format a word processor text into a (semi-)ready format to be published on http://computationalculture.net \ No newline at end of file +Scripts that format a word processor text into a (semi-)ready format to be published on http://computationalculture.net + +Dependency: [pandoc](https://pandoc.org) + +``` +$> ./cc-format.sh + +usage: ./cc-format.sh [action] [files...] +where action can be: [src-md|md-html|src-cc-html|src-html] +``` + +``` +$> python format-cc-notes.py --help + +usage: format-cc-notes.py [-h] --text TEXT [--divider DIVIDER] --output OUTPUT [--format FORMAT] + +CC notes formatter + +options: + -h, --help show this help message and exit + --text TEXT, -t TEXT Text file + --divider DIVIDER, -d DIVIDER + In-text markup divider for notes + --output OUTPUT, -o OUTPUT + Output file + --format FORMAT, -f FORMAT + Output format (cc, html) +``` \ No newline at end of file diff --git a/cc-format.sh b/cc-format.sh new file mode 100755 index 0000000..72e8140 --- /dev/null +++ b/cc-format.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +if ! [[ "$1" =~ ^(src-md|md-html|src-cc-html|src-html|html-txt) ]]; then + echo "usage: $0 [action] [files...]" + echo "where action can be: [src-md|md-html|src-cc-html|src-html]" + exit 1 +fi + +if [[ $# -lt 2 ]]; then + echo "wrong number of parameters (need at least a command and an input file)" + exit 2 +fi + +case $1 in + + src-md) + echo "converting input file to md (via pandoc)" + pandoc --wrap=none -t markdown "${@:2}" -o "${@:2}".md + ;; + md-html) + echo "converting md input file to html" + pandoc --wrap=none --standalone --mathjax=https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js "${@:2}" -o "${@:2}".html + ;; + src-cc-html) + echo "converting src input file to CC html" + pandoc --wrap=none -t markdown "${@:2}" -o "${@:2}".md + python format-cc-notes.py -t "${@:2}".md -o "${@:2}".html.md -f cc + pandoc --wrap=none --template ./template.html --mathjax=https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js "${@:2}".html.md -o "${@:2}".CC.html + rm "${@:2}".html.md + rm "${@:2}".md + ;; + src-html) + echo "converting src input file to bare html" + pandoc --wrap=none -t markdown "${@:2}" -o "${@:2}".md + python format-cc-notes.py -t "${@:2}".md -o "${@:2}".html.md -f html + pandoc --wrap=none --template ./template.html --mathjax=https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js "${@:2}".html.md -o "${@:2}".html + rm "${@:2}".html.md + rm "${@:2}".md + ;; +esac \ No newline at end of file diff --git a/format-cc-notes.py b/format-cc-notes.py new file mode 100644 index 0000000..d238ff6 --- /dev/null +++ b/format-cc-notes.py @@ -0,0 +1,78 @@ +import argparse, re, sys + +def fd_fn_forward(post_id, note_id): + return f"{note_id}" + +def fd_fn_reverse(post_id, note_id, note_txt): + return f"