Giter VIP home page Giter VIP logo

carbonara's Introduction

Carbonara build

API for carbon.

Getting started

Send POST https://carbonara.now.sh/api/cook to take an image of code snippet.

How it works

  • Puppeteer visit https://carbon.now.sh.
  • Mapping all params in properly URL params.
  • Taking a screenshot of the editor.

POST /api/cook

Body is JSON with next params:

parameter default type description
code (required) string Code snippet
backgroundColor "rgba(171, 184, 195, 1)" string Hex or rgba color
dropShadow true boolean Turn on/off shadow
dropShadowBlurRadius "68px" string shadow blur radius
dropShadowOffsetY "20px" string shadow offset y
exportSize "2x" string resolution of exported image, e.g. 1x, 3x
fontSize "14px" string font size
fontFamily "Hack" string font family, e.g. JetBrains Mono, Fira Code.
firstLineNumber 1 number first line number
language "auto" string programing language for properly highlighting. See name in carbon exported config. For example bash is named "application/x-sh"
lineHeight "133%" string line height
lineNumbers false boolean turn on/off line number
paddingHorizontal "56px" string horizontal padding
paddingVertical "56px" string vertical padding
theme "seti" string code theme
watermark false boolean turn on/off watermark
widthAdjustment true boolean turn on/off width adjustment
windowControls true boolean turn on/off window controls
windowTheme "none" string window theme

Defaults params are the same as https://carbon.now.sh.

Response is an image of a code snippet.

Example

Creating image and saving to code.png in terminal.

curl https://carbonara.now.sh/api/cook \
-X POST \
-H 'Content-Type: application/json' \
-d '{
      "code": "export default const sum = (a, b) => a + b",
      "backgroundColor": "#1F816D"
    }' \
> code.png

Easy way to tune image

  1. Visit https://carbon.now.sh.
  2. Set appearance.
  3. Click gear → miscexport config for downloading JSON with the current setting.
  4. Add code property in JSON.
  5. Use JSON in /api/cook request body.

Unsupported params

These options exist in exported config but there is not a possibility pass them via URL: backgroundImage, backgroundImageSelection, backgroundMode, squaredImage, hiddenCharacters, name, loading, icon, isVisible, width.

Docker container

Running the server in 3000 port with docker:

docker run -p 3000:3000 -it --cap-add=SYS_ADMIN petersolopov/carbonara

Running test

docker build -t local/carbonara .
docker run -it --rm --cap-add=SYS_ADMIN local/carbonara npm test

Development

There are two main files:

  • api/cook.js — lambda function that running in production.
  • src/index.js – nodejs server that running in docker container.

Running development server:

docker build -t local/carbonara .
docker run -v $(pwd):/home/pptruser/app/ -p 3000:3000 -it --rm --cap-add=SYS_ADMIN $(docker build -q .) npm run nodemon

Updating test images:

docker build -t local/carbonara .
docker run -v $(pwd):/home/pptruser/app/ -it --rm --cap-add=SYS_ADMIN local/carbonara npm test

LICENSE

MIT.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.