Process images in markdown to be served by the API server

Downloads in past


1.0.34 years ago5 years agoMinified + gzip package size for @dimerapp/image in KB


<img width="500" src="https://res.cloudinary.com/adonisjs/image/upload/q_100/v1532274184/Dimer_Readme_Banner_lyy7wv.svg" alt="Dimer App">

<a href="https://dimerapp.com/what-is-dimer">
  Dimer is an open source project and CMS to help you publish your documentation online.

<sub>We believe every project/product is incomplete without documentation. <br /> We want to help you publish user facing documentation, without worrying <code>about tools or code</code> to write.</sub>

Dimer Image
Handle images detected inside markdown and process them to be served via HTTP server

!travis-imagetravis-url !appveyor-imageappveyor-url !npm-imagenpm-url
@dimerapp/markdown can detect assets (aka images) inside the Markdown documents. This package can be used to process those images and serve them via HTTP server.

How it works?

Let's start with the example markdown document and understand the flow on how images are processed.
This is an image reference ![](../images/dropdown.png)

  1. The image ../images/dropdown.png will be converted to a buffer and moved inside dist/__assets folder.
  2. During move operation, a HASH of file contents will be generated to avoid duplicate files.
  3. A thumbnail for jpg and png images is generated to render blur images and load actual image in background (has to be handled on Frontend).


npm i @dimerapp/image

# yarn
yarn add @dimerapp/image


const Markdown = require('@dimerapp/markdown')
const Context = require('@dimerapp/context')

const ctx = new Context(__dirname)

// This must be done by parsing the config file
ctx.set('lib', 'config', {
  compilerOptions: {}

const img = new Image(ctx)

const markdown = new Markdown(contents, {
  onUrl: function (url) {
    if (img.isImage(url)) {
      const response = await img.move(url, dirname(filePath))

      return img.toDimerNode(response)

Change log

The change log can be found in the CHANGELOG.md file.


Everyone is welcome to contribute. Please take a moment to review the contributing guidelines.

Authors & License

thetutlage and contributors.
MIT License, see the included MIT file.