1. inject-in-tag
Inject content into Markdown files
inject-in-tag
Package: inject-in-tag
Created by: jfmengels
Last modified: Sun, 19 Jun 2022 01:18:48 GMT
Version: 1.1.1
License: MIT
Downloads: 24
Repository: https://github.com/jfmengels/inject-in-tag

Install

npm install inject-in-tag
yarn add inject-in-tag

inject-in-tag Build Status

Inject content into Markdown files

Install

$ npm install --save inject-in-tag

In Markdown, you can create comment tags of the form <!-- foo bar --> that will not appear to the user when rendered.
Using this system, we can use start and end tags to delimit sections and replace the content in between by new content.

Programmatic usage

In the following example, we want to inject the contents of resource into markDownContent, some markdown file content.
We will inject the value of each key between tags that contain the key in the tag. Here, we will inject:

  • '\nSome new and better content\n' between <!-- SOME-TAG:START --> and <!-- SOME-TAG:END -->
  • 'Other content between <!-- SOME-OTHER-TAG:START --> and <!-- SOME-OTHER-TAG:END -->
 const inject = require('inject-in-tag');

const resource = {
  'SOME-TAG': '\nSome new and better content\n',
  'SOME-OTHER-TAG': 'Other content'
}

const markDownContent = `
# Title

Lorem ipsum

## Sub-title

<!-- SOME-TAG:START -->
  Some content
<!-- SOME-TAG:END -->

<!-- SOME-OTHER-TAG:START -->Foo<!-- SOME-OTHER-TAG:END -->

Lorem ipsum
`;

const result = inject(resource, markDownContent);
result === `
# Title

Lorem ipsum

## Sub-title

<!-- SOME-TAG:START -->
  Some new and better content
<!-- SOME-TAG:END -->

<!-- SOME-OTHER-TAG:START -->Other content<!-- SOME-OTHER-TAG:END -->

Lorem ipsum
`

API

inject(resource, content)

Injects the contents of resource into content.

resource

Object with tag-name and content to inject pairs.

content

String content, that will be updated using resource

CLI

 inject-in-tag path/to/resource path/to/file/to/inject/in-1 path/to/file/to/inject/in-2 ...

path/to/resource must be a JavaScript file that exports a resource object, either directly (like module.exports = {'SOME-TAG': 'content'};) or through a Promise (like module.exports = Promise.resolve({'SOME-TAG': 'content'});). The CLI will then inject the contents in the tags of each of the following files.

License

MIT © Jeroen Engels

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code