1.0.0 • Published 5 months ago

markdown-query v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

markdown-query

npm version npm License

markdown-query is a versatile library for querying, updating, and manipulating Markdown content in JavaScript/TypeScript applications. It provides a set of methods to perform common tasks such as retrieving elements by ID, class, or tag, updating content, and more.

Table of Contents

  1. Installation
  2. Usage
  3. API Reference
  4. Contributing
  5. License
  6. Author
  7. Contact

Installation

You can install markdown-query using npm, yarn, or pnpm. Choose your preferred package manager:

NPM

npm install markdown-query

Yarn

yarn add markdown-query

PNPM

pnpm add markdown-query

Usage

Basic Example

import { MarkdownQuery } from 'markdown-query';

const markdownQuery = new MarkdownQuery();

// Example: Get element content by ID
const markdownContent = `
  <div id="example">
    This is some content.
  </div>
`;

const elementContent = markdownQuery.getElementById(markdownContent, 'example');
console.log(elementContent); // Output: This is some content.



or directly use this like 

import { MarkdownQuery } from 'markdown-query';

const markdownContent = `
  <div id="example">
    This is some content.
  </div>
`;
const elementContent = markdownQuery.getElementById(markdownContent, 'example');
console.log(elementContent); // Output: This is some content.

Advanced Examples

Updating Content

// Update content of an element by ID
const updatedContentById = markdownQuery.updateElementById(markdownContent, 'example', 'Updated content.');
console.log(updatedContentById);

// Update alt text for an image
const imageUrl = 'https://example.com/image.jpg';
const updatedImageAlt = markdownQuery.updateMarkdownImageAlt(markdownContent, imageUrl, 'New Alt Text');
console.log(updatedImageAlt);

Deleting Content

// Delete an element by ID
const deletedContentById = markdownQuery.deleteElementById(markdownContent, 'example');
console.log(deletedContentById);

// Delete a link by URL
const linkUrl = 'https://example.com';
const deletedLink = markdownQuery.deleteMarkdownLink(markdownContent, linkUrl);
console.log(deletedLink);

API Reference

For detailed information on all available methods, parameters, and examples, please refer to the API Reference.

MethodDescription
getElementByIdRetrieves content for elements with the specified ID. Returns null if no element is found.
getElementByClassNameRetrieves an array of contents for elements with the given class name.
getElementsByTagRetrieves an array of contents for elements with the specified tag name.
getMarkdownLinksRetrieves an array of links (text and URL) from the Markdown content.
getMarkdownImagesRetrieves an array of images (alt text and URL) from the Markdown content.
getMarkdownCodeBlocksRetrieves an array of code blocks from the Markdown content.
getMarkdownListRetrieves an array of list items from the Markdown content.
getMarkdownHeadersRetrieves an array of headers from the Markdown content.
getMarkdownCodeBlockByIndexExtracts a specific code block based on the index. Returns null if the index is out of bounds.
getMarkdownImageAltRetrieves the alt text for an image. Returns null if the image is not found or alt text is not available.
updateElementByIdUpdates the content of an element by ID. Returns the updated Markdown content.
updateElementByClassNameUpdates the content of elements with the given class name. Returns the updated Markdown content.
updateElementByTagUpdates the content of elements with the given tag name. Returns the updated Markdown content.
updateMarkdownLinkUpdates a link in the Markdown content. Returns the updated Markdown content.
updateMarkdownImageAltUpdates the alt text for an image. Returns the updated Markdown content.
updateMarkdownHeadersUpdates the headers in the Markdown content. Returns the updated Markdown content.
updateMarkdownListUpdates list items in the Markdown content. Returns the updated Markdown content.
deleteElementByIdDeletes the element with the specified ID. Returns Markdown content with the element removed.
deleteElementByClassNameDeletes elements with the specified class name. Returns Markdown content with the elements removed.
deleteElementByTagDeletes elements with the specified tag name. Returns Markdown content with the elements removed.
deleteMarkdownLinkDeletes a link with the specified URL. Returns Markdown content with the link removed.
deleteMarkdownImageDeletes an image with the specified URL. Returns Markdown content with the image removed.
deleteMarkdownHeadersDeletes headers with the specified text. Returns Markdown content with the headers removed.
deleteMarkdownCodeBlockByIndexDeletes a code block at the specified index. Returns Markdown content with the code block removed.
deleteMarkdownImageAltDeletes the alt text for an image. Returns updated Markdown content.

Contributing

We welcome contributions! Before contributing, please read our contribution guidelines and adhere to our Code of Conduct.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Shiv Kumar

Shiv Kumar

Contact

For any inquiries or questions, feel free to reach out at hello@shivkumar.me.