🚨 This client is still very much a work in progress. Please open issues! 🚨
View it on github at github.com/torchlight-api/remark
The Torchlight Remark client is a JS plugin for Remark, a markdown processor powered by plugins.
To install, require the package using NPM or Yarn
1npm i remark-torchlight
1yarn add remark-torchlight
To add the plugin, you can import remark-torchlight
and use
it in your markdown chain:
1import remark from 'remark' 2import html from 'remark-html' +import torchlight from 'remark-torchlight' 4 5export default async function markdownToHtml(markdown) { 6 return await remark() 7 .use(html) + .use(torchlight) 9 .process(markdown)10 .toString()11}
To configure your Torchlight integration, you can pass through an options object with a config
key:
1export default async function markdownToHtml(markdown) { 2 return await remark() 3 .use(html) 4 .use(torchlight, { 5 // All API configuration goes under `config`. 6 config: { 7 token: 'my-token', 8 theme: 'material-theme-palenight' 9 }10 })11 .process(markdown)12 .toString()13}
If you're running in Node, you can pass a string through to a configuration file location:
1export default async function markdownToHtml(markdown) { 2 return await remark() 3 .use(html) 4 .use(torchlight, { 5 // Read from a config file. 6 config: 'torchlight.config.js' 7 }) 8 .process(markdown) 9 .toString()10}
These are the available options you can use to configure your Torchlight highlighting.
1{ 3 token: 'my-test-token', 4 5 // The Torchlight client caches highlighted code blocks. Here you 6 // can define which directory you'd like to use. You'll likely 7 // want to add this directory to your .gitignore. Set to 8 // `false` to use an in-memory cache. You may also 9 // provide a full cache implementation.10 cache: 'cache',11 12 // Which theme you want to use. You can find all of the themes at14 theme: 'material-theme-palenight',15 16 // The Host of the API.17 host: 'https://api.torchlight.dev',18 19 // Global options to control block-level settings.21 options: {22 // Turn line numbers on or off globally.23 lineNumbers: false,24 25 // Control the `style` attribute applied to line numbers.26 // lineNumbersStyle: '',27 28 // Turn on +/- diff indicators.29 diffIndicators: true,30 31 // If there are any diff indicators for a line, put them32 // in place of the line number to save horizontal space.33 diffIndicatorsInPlaceOfLineNumbers: true,34 35 // When lines are collapsed, this is the text that will36 // be shown to indicate that they can be expanded.37 // summaryCollapsedIndicator: '...',38 },39}
Set your token from torchlight.dev. (Torchlight is completely free for personal and open source projects.) It defaults to the TORCHLIGHT_TOKEN
environment variable. You can hardcode it if you please.
Torchlight caches code blocks based on their contents and configuration, so that blocks that have already been rendered won't be rendered again. Use the cache
key to control the directory in which the cache lives.
If you'd prefer to not use a file cache, you can set this to false
and Torchlight will use an in-memory cache, which is only useful when watching files.
You can also provide your own cache implementation object. Take a look at the Memory Cache to see what methods you need to implement.
You can change the theme of all your code blocks by adjusting the theme
key in your configuration. To view all of the themes provided by Torchlight, head over to torchlight.dev/themes.
These are options that you can set to control every code block on your site. Read more in the options section.