
Security News
Package Maintainers Call for Improvements to GitHub’s New npm Security Plan
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
@md-plugins/md-plugin-codeblocks
Advanced tools
A Markdown-It plugin that enhances code block rendering by providing syntax highlighting, line numbering, and support for advanced features like tabbed code blocks. It integrates with Prism.js for syntax highlighting and allows customization for various use cases.
[[! highlight]]
, [[! add]]
, and [[! rem]]
for inline code annotations.Install the plugin via your preferred package manager:
# with pnpm:
pnpm add @md-plugins/md-plugin-codeblocks
# with Yarn:
yarn add @md-plugins/md-plugin-codeblocks
# with npm:
npm install @md-plugins/md-plugin-codeblocks
import MarkdownIt from 'markdown-it'
import { codeblocksPlugin } from '@md-plugins/md-plugin-codeblocks'
const md = new MarkdownIt()
md.use(codeblocksPlugin, {
containerComponent: 'MarkdownPrerender',
copyButtonComponent: '<MarkdownCopyButton',
preClass: 'markdown-code',
pageScripts: [
"import MarkdownPrerender from 'src/.q-press/components/MarkdownPrerender'",
"import MarkdownCopyButton from 'src/.q-press/components/MarkdownCopyButton.vue'",
],
})
console.log('Hello, world!')
The rendered output will include syntax-highlighted code wrapped in customizable components:
<markdown-prerender>
<pre v-pre class="markdown-code language-javascript">
<code>
console<span class="token punctuation">.</span>
<span class="token function">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>
<markdown-copy-button></markdown-copy-button>
</markdown-prerender>
The md-plugin-codeblocks
plugin supports the following options:
Option | Type | Default | Description |
---|---|---|---|
defaultLang | string | 'markup' | Default language for code blocks without a specified language. |
containerComponent | string | 'markdown-prerender' | Custom wrapper component for code blocks. |
copyButtonComponent | string | 'markdown-copy-button' | Custom copy button component. |
preClass | string | 'markdown-code' | CSS class for the <pre> element. |
codeClass | string | '' | CSS class for the <code> element. |
tabPanelTagName | string | 'q-tab-panel' | Tag name for the tab panels. |
tabPanelTagClass | string | 'q-pa-none' | CSS class for the tab panels. |
The plugin supports magic comments for inline annotations:
```js [numbered]
// All lines will be numbered
console.log('Line 1')
console.log('Line 2')
console.log('Line 3')
```
```js [highlight=2]
console.log('Line 1')
console.log('Line 2') // This line will be highlighted
console.log('Line 3')
```
```js
console.log('Line 1')
console.log('Line 2') [[highlight]] // This line will be highlighted
console.log('Line 3')
```
```js [add=2]
console.log('Line 1')
console.log('Line 2') // This line will be accented and prefixed with a '+'
console.log('Line 3')
```
```js [rem=2]
console.log('Line 1')
console.log('Line 2') // This line will be accented and prefixed with a '-'
console.log('Line 3')
```
```js [numbered highlight=1 rem=2 add=3]
console.log('Line 1') // This line will be highlighted
console.log('Line 2') // This line will be accented and prefixed with a '-'
console.log('Line 3') // This line will be accented and prefixed
```
Additonally, with the exception of numbered
, you can use ranges to annotate multiple lines:
[highlight=1,10-11 add=4,7-9 rem=12-14]
Easily create tabbed interfaces for multiple code examples:
```tabs
<<|js Tab 1|>>
console.log('Hello from Tab 1');
<<|ts Tab 2|>>
console.log('Hello from Tab 2');
```
Run the unit tests with Vitest
:
pnpm test
In case this README falls out of date, please refer to the documentation for the latest information.
This project is licensed under the MIT License. See the LICENSE file for details.
FAQs
A markdown-it plugin for code blocks.
The npm package @md-plugins/md-plugin-codeblocks receives a total of 28 weekly downloads. As such, @md-plugins/md-plugin-codeblocks popularity was classified as not popular.
We found that @md-plugins/md-plugin-codeblocks demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.