nopaste
nopaste copied to clipboard
Add simple file extension mapping to highlighted lang
Add a bash function for example:
nopaste() {
[[ -n "${2}" ]] && NOPASTE_URL="${2}" || NOPASTE_URL='https://cp.dimio.org'
FILE_EXT=$(printf '%s' "${1}" | awk -F . '{if (NF>1) {print $NF}}')
cat "${1}" | xz --format=lzma | base64 -w0 | printf "%s/?l=%s#%s\n" "${NOPASTE_URL}" "${FILE_EXT}" "$(cat -)"
}
Make a test file: echo 'echo "Hello World" | tee ./helloworld.sh' | tee ./helloworld.sh
Now use it like this: nopaste helloworld.sh - it's be highlighted as Shell
https://cp.dimio.org/?l=sh#XQAAgAD//////////wAymMlPivxG3YI4xcyNk1QKsBwb65mrsh4ppM+EJv4miAI/qa2MT8Mwb//8CoAA
or nopaste helloworld.sh https://bokub.github.io/nopaste (no highlight right now)
https://bokub.github.io/nopaste/?l=sh#XQAAgAD//////////wAymMlPivxG3YI4xcyNk1QKsBwb65mrsh4ppM+EJv4miAI/qa2MT8Mwb//8CoAA
UPD: highlighted preview: https://deploy-preview-19--nopaste.netlify.app/?l=sh#XQAAgAD//////////wAymMlPivxG3YI4xcyNk1QKsBwb65mrsh4ppM+EJv4miAI/qa2MT8Mwb//8CoAA
Hi !
I think CodeMirror.modeInfo already contains all the information you need to map a file extension to a language:
https://cdn.jsdelivr.net/npm/[email protected]/mode/meta.js
And as you can see, there is a CodeMirror.findModeByExtension function exported too.