From fc8118984fd90ed1979ae072d4650f0bbd0b6cde Mon Sep 17 00:00:00 2001 From: Amolith Date: Wed, 6 Aug 2025 18:56:15 -0600 Subject: [PATCH] feat: replace md2html with mdas --- .../private_fish/functions/md2html.fish | 27 ------ dot_config/private_fish/functions/mdas.fish | 90 +++++++++++++++++++ 2 files changed, 90 insertions(+), 27 deletions(-) delete mode 100644 dot_config/private_fish/functions/md2html.fish create mode 100644 dot_config/private_fish/functions/mdas.fish diff --git a/dot_config/private_fish/functions/md2html.fish b/dot_config/private_fish/functions/md2html.fish deleted file mode 100644 index 18b68edc5b5b349974d62caffccc0ac227a9b7b9..0000000000000000000000000000000000000000 --- a/dot_config/private_fish/functions/md2html.fish +++ /dev/null @@ -1,27 +0,0 @@ -function md2html - set NAME (eow) - set DIR ~/Downloads/tmp/responses - set FILENAME "$DIR/$NAME.md" - - mkdir -p $DIR - cat > $FILENAME - - cd $DIR - - if not prettier -w --parser markdown --prose-wrap always --no-editorconfig --no-config "$NAME.md" - echo "Error: prettier failed" >&2 - return 1 - end - - if not pandoc -so "$NAME.html" "$NAME.md" - echo "Error: pandoc failed" >&2 - return 1 - end - - if not xdg-open "$NAME.html" - echo "Error: xdg-open failed" >&2 - return 1 - end - - echo "Successfully created and opened $NAME.html" -end diff --git a/dot_config/private_fish/functions/mdas.fish b/dot_config/private_fish/functions/mdas.fish new file mode 100644 index 0000000000000000000000000000000000000000..d1924759fbc6e530951d0379e3ef7a38a9ce9a69 --- /dev/null +++ b/dot_config/private_fish/functions/mdas.fish @@ -0,0 +1,90 @@ +function mdas + set DIR "$HOME/LLM Responses" + mkdir -p $DIR + pushd $DIR + + set exit_status 0 + + # Parse command line arguments + argparse 'p/pdf' 'h/html' 'e/epub' -- $argv + or begin + echo "Usage: mdas [-p|--pdf] [-h|--html] [-e|--epub]" >&2 + echo "At least one format flag must be specified." >&2 + popd + return 1 + end + + # Check if at least one format is specified + if not set -q _flag_pdf; and not set -q _flag_html; and not set -q _flag_epub + echo "Error: At least one format flag (-p, -h, or -e) must be specified." >&2 + popd + return 1 + end + + read -z CONTENT + set FILENAME (echo "$CONTENT" | llm -f - -t 'srht:~amolith/filename') + set TITLE (llm -c "Give me that same file name but now in conversation case. For example, 'Port-out PIN implementation spec', but without quotes. The first letter should be capitalized, proper nouns capitalized, and most everything else lowercased.") + + # remove path traversal, special chars, limit length + set FILENAME (echo "$FILENAME" | sed 's/[^a-zA-Z0-9._-]/_/g' | sed 's/\.\.//g' | cut -c1-200) + # remove potentially dangerous chars but keep spaces + set TITLE (echo "$TITLE" | sed 's/[<>&"'\''`]//g' | sed 's/\$//g' | cut -c1-200) + + set date "$(date +%Y-%m-%d)" + set header "--- +title: $TITLE +date: $date +mainfont: Atkinson Hyperlegible Next +sansfont: Atkinson Hyperlegible Next +monofont: 0xProto +---" + + set CONTENT "$header + +$CONTENT" + + echo $CONTENT > "$FILENAME.md" + + if not prettier -w --parser markdown --no-editorconfig --no-config "$FILENAME.md" + echo "Error: prettier failed" >&2 + set exit_status 1 + else + echo "$FILENAME.md" + end + + # Convert to HTML if requested + if test $exit_status -eq 0; and set -q _flag_html + if not pandoc --from markdown --to html -so "$FILENAME.html" "$FILENAME.md" + echo "Error: HTML conversion failed" >&2 + set exit_status 1 + else + echo "$FILENAME.html" + end + end + + # Convert to PDF if requested + if test $exit_status -eq 0; and set -q _flag_pdf + if not pandoc --pdf-engine=xelatex --from markdown --to pdf --epub-title-page=false -o "$FILENAME.pdf" "$FILENAME.md" + echo "Error: PDF conversion failed" >&2 + set exit_status 1 + else + echo "$FILENAME.pdf" + end + end + + # Convert to EPUB if requested + if test $exit_status -eq 0; and set -q _flag_epub + if not pandoc --from markdown --to epub -o "$FILENAME.epub" "$FILENAME.md" + echo "Error: EPUB conversion failed" >&2 + set exit_status 1 + else + echo "$FILENAME.epub" + end + end + + popd + + + + return $exit_status +end