Skip to content

Instantly share code, notes, and snippets.

@phuhl
Last active April 20, 2023 11:33
Show Gist options
  • Save phuhl/d6765e170453376e809cee20723e5b03 to your computer and use it in GitHub Desktop.
Save phuhl/d6765e170453376e809cee20723e5b03 to your computer and use it in GitHub Desktop.
A (non-complete) Prismjs syntax highlighting mode for Emacs' Restclient-mode
/*
Author: Philipp Uhl
*/
const standardFeatures = {
comment: /(^|[\n\r])\s*#.*/,
tag: {
pattern: /(^|[\n\r])[^ :]+: .*/,
inside: {
variable: {
pattern: / :[a-zA-Z-\d]+/,
},
string: {
pattern: /([^:\n\r]+: )(.*)/,
lookbehind: true,
},
},
},
variable: {
pattern: /(^|[\n\r]):[a-zA-Z-\d]+/,
},
operator: {
pattern: /( := )|( = )/,
},
};
Prism.languages.restclient = {
jsonBody: {
pattern:
/([\n\r]Content-Type: application\/json\s*[\n\r])([^\n\r]+([\n\r]|\n\r|\r\n))*[\n\r]+([^]*?)(?=([\r\n]\s*#)|$)/,
inside: {
body: {
pattern: /[\n\r]\s*[\n\r].*$/s,
inside: Prism.languages.json,
},
...standardFeatures,
},
},
keyword: {
pattern: /(^|[\n\r])(GET|POST|PUT|PATCH|DELETE|HEAD)\s+.*/,
alias: "bold",
inside: {
tag: /\shttp.*$/i,
},
},
lispAssignment: {
pattern: /(^|[\n\r]):[a-zA-Z-\d]+\s+:=\s*.*$/m,
inside: {
lisp: {
pattern: /(:=\s*)(.*$)/,
lookbehind: true,
inside: Prism.languages.lisp,
},
...standardFeatures,
},
},
...standardFeatures,
};
@phuhl
Copy link
Author

phuhl commented Apr 20, 2023

Currently missing (but easy to add):

  • XML body content
  • form body content
  • multi-line assignments
  • probably lot's of other stuff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment