Detalhes do pacote

remark-prism

sergioramos28.6kBSD-3-Clause1.3.6

Syntax highlighter for markdown code blocks - with support for plugins

prismjs, markdown, remark, remarkjs

readme (leia-me)

remark-prism

Syntax highlighter for markdown code blocks using Prism - with support for certain plugins. This allows syntax highlighting without running any client-side code - other than CSS.

remark-prism

installation

λ yarn add remark-prism

usage

Input:

const src = `
\`\`\`javascript
console.log('Hello World');
\`\`\`
`;

Using remark (mdast):

require('unified')()
  .use(require('remark-parse'))
  .use(require('remark-stringify'))
  .use(require('remark-prism'), {
    /* options */
  })
  .use(require('remark-html'))
  .process(file, (err, file) => console.log(String(file)));

Using rehype (hast):

require('unified')()
  .use(require('remark-parse'))
  .use(require('remark-prism'), {
    /* options */
  })
  .use(require('remark-rehype'))
  .use(require('rehype-format'))
  .use(require('rehype-stringify'))
  .process(file, (err, file) => console.log(String(file)));

Using mdx:

console.log(
  await require('@mdx-js/mdx')(src, {
    commonmark: true,
    gfm: true,
    remarkPlugins: [
      [
        require('remark-prism'),
        {
          /* options */
        },
      ],
    ],
  }),
);

Output:

<div class="remark-highlight">
  <pre class="language-javascript">
    <code>
      <span class="token console class-name">console</span>
      <span class="token punctuation">.</span>
      <span class="token method function property-access">log</span>
      <span class="token punctuation">(</span>
      <span class="token string">'Hello World'</span>
      <span class="token punctuation">)</span>
      <span class="token punctuation">;</span>
    </code>
  </pre>
</div>

Take a look at our fixtures and it's outputs to see more examples.

transformInlineCode

Add relevant class names to inline code snippets. For example when you use single backtick code examples.

use(require('remark-prism'), {
  transformInlineCode: true,
});

plugins

It supports some Prism plugins:

use(require('remark-prism'), {
  plugins: [
    'autolinker',
    'command-line',
    'data-uri-highlight',
    'diff-highlight',
    'inline-color',
    'keep-markup',
    'line-numbers',
    'show-invisibles',
    'treeview',
  ],
});

Don't forget to include the appropriate css in your stylesheets. Refer to the documentation of each plugin.

attributes

\`\`\`diff-javascript[class="line-numbers"][class="diff-highlight"]
<pre class="language-diff-javascript diff-highlight line-numbers">...</pre>

license

BSD-3-Clause

changelog (log de mudanças)

1.3.6 (2021-04-13)

Chores

  • add .npmignore (84bcf72)
  • upgrade dependencies (a89f42f)
  • deps: bump actions/cache from v2.1.4 to v2.1.5 (f1a3985)
  • deps: bump ridedott/release-me-action from v3.5.11 to v3.5.20 (2d488fb)
  • deps: bump rlespinasse/github-slug-action from 3.4.0 to 3.5.1 (d469f00)
  • deps: bump wagoid/commitlint-github-action from v3.0.6 to v3.1.0 (954264d)

1.3.5 (2021-03-30)

Chores

  • upgrade mdx to v2 (fbd1657)
  • deps: bump actions/cache from v2.1.3 to v2.1.4 (b1fd922)
  • deps: bump actions/setup-node from v2.1.4 to v2.1.5 (700fe7c)
  • deps: bump ridedott/release-me-action from v3.3.4 to v3.5.11 (f9699a0)
  • deps: bump rlespinasse/github-slug-action from 3.1.0 to 3.4.0 (339d66c)
  • deps: bump wagoid/commitlint-github-action from v2.1.6 to v3.0.6 (84befaa)
  • upgrade dependencies (319a579)

1.3.4 (2021-01-05)

Chores

  • upgrade dependencies (bacd20a)
  • deps-dev: bump actions/setup-node from v2.1.2 to v2.1.4 (f42b3ae)
  • deps-dev: bump ridedott/release-me-action from v3.2.12 to v3.3.4 (f460390)
  • deps-dev: bump wagoid/commitlint-github-action from v2.1.2 to v2.1.6 (1f6c0b0)

1.3.3 (2020-11-24)

Chores

  • deps-dev: upgrade dependencies (6349741)

Continuous Integration

Documentation

  • add more usage examples (f48e1cd)

Tests

  • add rehype and mdast tests (c4fc721)
  • add test case with all plugins (a08507a)
  • update snapshots (f0da46e)

1.3.2 (2020-11-23)

Bug Fixes

  • filter out empty language strings (94b4d9a)
  • restore indentation (295ac7a), closes #50

Chores

  • deps-dev: bump ridedott/release-me-action from v3.2.5 to v3.2.12 (871080b)
  • deps-dev: bump rollup from 2.33.1 to 2.33.2 (445eb27)
  • deps-dev: bump wagoid/commitlint-github-action from v2.1.1 to v2.1.2 (58df9db)
  • deps-dev: upgrade dependencies (7204d46)

Documentation

1.3.1 (2020-11-14)

Bug Fixes

  • add missing node props to the prism branch (de05c22)

1.3.0 (2020-11-14)

Features

  • deal exclusively with a tree, not html (6f5da71)

1.2.1 (2020-11-13)

Chores

  • deps-dev: bump actions/cache from v2.1.2 to v2.1.3 (cdb3af3)
  • deps-dev: bump c8 from 7.3.4 to 7.3.5 (960ce1d)
  • deps-dev: bump eslint from 7.11.0 to 7.12.0 (3bb283b)
  • deps-dev: bump eslint-config-prettier from 6.13.0 to 6.14.0 (a9e91ab)
  • deps-dev: bump lint-staged from 10.4.1 to 10.4.2 (93d3790)
  • deps-dev: bump puppeteer from 5.3.1 to 5.4.0 (b667cfc)
  • deps-dev: bump ridedott/release-me-action from v3.2.3 to v3.2.5 (595fc41)
  • deps-dev: bump rlespinasse/github-slug-action from 2.1.1 to 3.1.0 (fff1caf)
  • deps-dev: bump wagoid/commitlint-github-action from v2.0.2 to v2.1.1 (edc916d)

Continuous Integration

1.2.0 (2020-11-13)

Features

  • for compatibility, code also have language (#44) (3a3c448), closes #44

1.1.18 (2020-11-10)

Chores

Continuous Integration

  • no-release: fix release rules (46fc048)

Other

1.1.18 (2020-10-16)

Continuous Integration

  • no-release: fix release rules (46fc048)

1.1.17 (2020-10-16)

Chores

1.1.16 (2020-10-16)

Chores

  • deps: bump prismjs from 1.21.0 to 1.22.0 (577c6ff)
  • deps-dev: bump actions/cache from v2.1.1 to v2.1.2 (54e8357)
  • deps-dev: bump c8 from 7.3.2 to 7.3.3 (2cf722c)
  • deps-dev: bump eslint from 7.10.0 to 7.11.0 (5e89f4a)
  • deps-dev: bump eslint-config-prettier to 6.13.0 (6fa6422)
  • deps-dev: bump remark from 12.0.1 to 13.0.0 (dea0702)
  • deps-dev: bump ridedott/release-me-action to v3.2.3 (bfbbac8)
  • deps-dev: upgrade dependencies (c8, lint-staged) (974f841)

Continuous Integration

  • don't release on deps-dev scope (ee770c5)

1.1.15 (2020-10-08)

Chores

  • deps: bump actions/setup-node from v2.1.1 to v2.1.2 (45bc6d4)
  • deps: bump devmasx/coverage-check-action from v1.1.0 to v1.2.0 (e5d21f4)
  • deps: bump rlespinasse/github-slug-action from 2.1.0 to 2.1.1 (4f7a7ea)
  • deps-dev: bump ava from 3.12.1 to 3.13.0 (1189f69)
  • deps-dev: bump c8 from 7.3.1 to 7.3.2 (b18968f)
  • deps-dev: bump eslint from 7.9.0 to 7.10.0 (cc4689c)
  • deps-dev: bump eslint-config-prettier from 6.11.0 to 6.12.0 (2260954)
  • deps-dev: bump remark-html from 12.0.0 to 13.0.1 (aaeb5f3)
  • no-release: don't release on dev-deps (e271be5)

1.1.14 (2020-09-24)

Documentation

1.1.13 (2020-09-24)

Chores

  • deps-dev: bump c8 from 7.3.0 to 7.3.1 (109a675)
  • deps-dev: bump lint-staged from 10.3.0 to 10.4.0 (32a5eb0)
  • deps-dev: bump puppeteer from 5.3.0 to 5.3.1 (94c4756)

1.1.12 (2020-09-16)

Chores

  • deps-dev: bump prettier from 2.1.1 to 2.1.2 (39cd10e)

1.1.11 (2020-09-14)

Chores

  • deps-dev: bump puppeteer from 5.2.1 to 5.3.0 (ad523f1)
  • prettier and eslintrc on pkg.json (e4ba684)
  • deps-dev: bump eslint from 7.8.1 to 7.9.0 (908b280)
  • deps-dev: bump lint-staged from 10.2.13 to 10.3.0 (0f339a6)

1.1.10 (2020-09-08)

Chores

  • deps-dev: bump husky from 4.2.5 to 4.3.0 (5a5c611)

1.1.9 (2020-09-02)

Chores

  • deps-dev: bump eslint from 7.8.0 to 7.8.1 (0e0347d)

1.1.8 (2020-09-01)

Chores

  • deps-dev: bump eslint from 7.7.0 to 7.8.0 (59517a3)

1.1.7 (2020-08-26)

Chores

  • deps-dev: bump lint-staged from 10.2.12 to 10.2.13 (10f63cc)
  • deps-dev: bump prettier from 2.1.0 to 2.1.1 (636dfee)

1.1.6 (2020-08-25)

Chores

  • deps: bump actions/cache from v1 to v2.1.1 (ab65e9a)
  • deps: bump actions/setup-node from v1 to v2.1.1 (6495a14)
  • deps: bump rlespinasse/github-slug-action from 1.1.0 to 2.1.0 (ba595ed)
  • deps: bump wagoid/commitlint-github-action from v1 to v2.0.2 (5936dd1)

1.1.5 (2020-08-25)

Continuous Integration

  • update github actions through dependabot (a1334a7)

1.1.4 (2020-08-25)

Chores

  • deps-dev: bump ava from 3.11.1 to 3.12.1 (050a1f4)
  • deps-dev: bump lint-staged from 10.2.11 to 10.2.12 (4eeb1c0)
  • deps-dev: bump prettier from 2.0.5 to 2.1.0 (ec26133)

Continuous Integration

  • allow empty on dependabot changes (6e0c741)
  • remove .dependabot config (5667adc)
  • run tests on dependabot (5bc9e9a)
  • update package.json too on dependabot (bedeada)
  • upgrade yarn (1fac57c)

1.1.3 (2020-08-25)

Continuous Integration

  • add support for dependabot (aad5f02)

1.1.2 (2020-08-18)

Chores

BREAKING CHANGE

  • this essentially creates a new package and the previous one is now deprecated

1.1.1 (2020-08-18)

Chores

Continuous Integration

1.1.0 (2020-05-18)

Features

  • add support to snippet legend (2a85819)

1.0.2 (2020-05-18)

Bug Fixes

1.0.1 (2020-05-18)

Bug Fixes

  • prevent crash when lang is not defined (5170434)

1.0.0 (2020-05-09)

Features