Socket
Socket
Sign inDemoInstall

@hashicorp/remark-plugins

Package Overview
Dependencies
50
Maintainers
19
Versions
54
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.2.2 to 3.0.0

2

package.json
{
"name": "@hashicorp/remark-plugins",
"description": "A potpourri of remark plugins used to process .mdx files",
"version": "2.2.2",
"version": "3.0.0",
"author": "Jeff Escalante",

@@ -6,0 +6,0 @@ "bugs": "https://github.com/hashicorp/remark-plugins/issues",

@@ -8,3 +8,3 @@ const path = require('path')

return function transformer(tree, file) {
return flatMap(tree, node => {
return flatMap(tree, (node) => {
if (node.type !== 'paragraph') return [node]

@@ -32,9 +32,25 @@

// return the file contents in place of the @include
// this takes a couple steps because we allow recursive includes
const processor = remark().use(includeMarkdownPlugin, { resolveFrom })
const ast = processor.parse(includeContents)
return processor.runSync(ast, includeContents).children
// if we are including a ".md" or ".mdx" file, we add the contents as processed markdown
// if any other file type, they are embedded into a code block
if (includePath.match(/\.md(?:x)?$/)) {
// return the file contents in place of the @include
// this takes a couple steps because we allow recursive includes
const processor = remark().use(includeMarkdownPlugin, { resolveFrom })
const ast = processor.parse(includeContents)
return processor.runSync(ast, includeContents).children
} else {
// trim trailing newline
includeContents.contents = includeContents.contents.trim()
// return contents wrapped inside a "code" node
return [
{
type: 'code',
lang: includePath.match(/\.(\w+)$/)[1],
value: includeContents,
},
]
}
})
}
}

@@ -34,2 +34,42 @@ # Include Markdown Plugin

### File Types
If you include a `.md` or `.mdx` file, its contents will be imported directly into the file, like a partial. If it has `@include` statements nested within it, they will all resolve recursively, as seen in the primary examples above
If any other file extension is included, it will be displayed as the contents of a code block, with the code block language tag set as the file extension. For example:
### Input
Your main markdown file:
```md
# My cool page
@include "test.js"
The rest of the content...
```
`test.js`, in the same directory:
```js
function sayHello(name) {
console.log(`hello, ${name}!`)
}
```
### Output
```html
<h1>My cool page</h1>
<pre class="language-js">
<code>
function sayHello(name) {
console.log(`hello, ${name}!`)
}
</code>
</pre>
<p>The rest of the content...</p>
```
### Options

@@ -50,5 +90,3 @@

```js
remark()
.use(includeMarkdown)
.use(capitalizeAllText)
remark().use(includeMarkdown).use(capitalizeAllText)
```

@@ -59,7 +97,5 @@

```js
remark()
.use(capitalizeAllText)
.use(includeMarkdown)
remark().use(capitalizeAllText).use(includeMarkdown)
```
...what will happen is that all your text will be capitalized _except_ for the text in includeed files. And on top of that, the include plugin wouldn't resolve the files properly, because it capitalized the word "include", which is the wrong syntax. So usually you want to make sure this plugin comes first in your plugin stack.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc