DEV Community

Sh Raj
Sh Raj

Posted on • Updated on

Convert Plain Text to Rich Text with Ease!

Convert Plain Text to Rich Text with Ease!

GitHub logo SH20RAJ / RichTextConvertor

A JavaScript library to convert normal text into rich text with support for hashtags, mentions, bold, and underline.

Rich Text Converter

License: MIT npm version Visitors

A JavaScript library to convert normal text into rich text with support for hashtags, mentions, bold, and underline.

Installation

Using npm

You can install this package via npm:

npm install rich-text-converter
Enter fullscreen mode Exit fullscreen mode

CDN Integration

You can also use the library directly from a CDN:

<!-- Include RichTextConvertor.js from jsDelivr -->
<script src="https://cdn.jsdelivr.net/gh/SH20RAJ/RichTextConvertor/RichTextConvertor.min.js"></script>
Enter fullscreen mode Exit fullscreen mode

Usage

Browser

// Create a new instance of RichTextConverter
const converter = new RichTextConverter();

// Example usage
const inputText = "Check out #trending topics and mention @user in this **cool** __text__!";
const richText = converter.convert(inputText);

console.log(richText);
Enter fullscreen mode Exit fullscreen mode

Node.js

You can also use the library in Node.js:

const RichTextConverter = require('rich-text-converter');
// Create a new instance of RichTextConverter
const converter = new RichTextConverter();

// Example usage
const
…
Enter fullscreen mode Exit fullscreen mode

Have you ever wanted to spice up your plain text with hashtags, mentions, bold, and underline styles? Look no further! Introducing the Rich Text Converter JavaScript library, your go-to solution for converting normal text into rich, formatted text.

What is Rich Text Converter?

Rich Text Converter is a lightweight JavaScript library that enables you to effortlessly transform ordinary text into visually appealing and interactive content. Whether you're building a social media platform, a blog, or simply want to enhance the text on your website, this library has got you covered.

  • Hyperlink #hashtags and @usernames

Features

  • Hashtags: Automatically convert #trending into clickable links leading to related topics.
  • Mentions: Transform @user into clickable links directing to user profiles.
  • Bold: Simply wrap text within ** to make it bold.
  • Underline: Wrap text within __ to add a subtle underline to your content.

How to Use

1. Install via npm

npm install rich-text-converter
Enter fullscreen mode Exit fullscreen mode

2. Import into Your Project

// Import RichTextConverter
const RichTextConverter = require('rich-text-converter');

// Create a new instance
const converter = new RichTextConverter();

// Example usage
const inputText = "Check out #trending topics and mention @user in this **cool** __text__!";
const richText = converter.convert(inputText);

console.log(richText);
Enter fullscreen mode Exit fullscreen mode

3. CDN Integration

Alternatively, you can use the library directly from a CDN:

<!-- Include RichTextConvertor.js from jsDelivr -->
<script src="https://cdn.jsdelivr.net/gh/SH20RAJ/RichTextConvertor/RichTextConvertor.js"></script>
Enter fullscreen mode Exit fullscreen mode

4. Configuration (Optional)

Customize the conversion by providing your own configurations:

const config = {
  hashtags: {
    url: 'https://example.com/hashtag/$1',
  },
  mentions: {
    url: 'https://example.com/user/$1',
  },
  bold: {
    replace: '<strong>$1</strong>',
  },
  underline: {
    replace: '<u>$1</u>',
  },
};

const converter = new RichTextConverter(config);
Enter fullscreen mode Exit fullscreen mode

Why Choose Rich Text Converter?

  • Easy Integration: Simply include the library and start converting text.
  • Flexible Configuration: Customize the conversion patterns and URLs to fit your needs.
  • Lightweight and Efficient: Minimal overhead and fast processing.

Get Started Today!

Enhance your web application's text formatting capabilities with Rich Text Converter. Whether you're building a social platform, blog, or any web project requiring rich text, this library is here to make your life easier.

Connect with Us

  • GitHub Repository: SH20RAJ/RichTextConvertor
  • Issues and Contributions: We welcome your feedback and contributions. Feel free to open an issue or submit a pull request on our GitHub repository.

Give your text the attention it deserves. Convert plain text to rich text effortlessly with Rich Text Converter. Happy coding!

GitHub logo SH20RAJ / RichTextConvertor

A JavaScript library to convert normal text into rich text with support for hashtags, mentions, bold, and underline.

Rich Text Converter

License: MIT npm version Visitors

A JavaScript library to convert normal text into rich text with support for hashtags, mentions, bold, and underline.

Installation

Using npm

You can install this package via npm:

npm install rich-text-converter
Enter fullscreen mode Exit fullscreen mode

CDN Integration

You can also use the library directly from a CDN:

<!-- Include RichTextConvertor.js from jsDelivr -->
<script src="https://cdn.jsdelivr.net/gh/SH20RAJ/RichTextConvertor/RichTextConvertor.min.js"></script>
Enter fullscreen mode Exit fullscreen mode

Usage

Browser

// Create a new instance of RichTextConverter
const converter = new RichTextConverter();

// Example usage
const inputText = "Check out #trending topics and mention @user in this **cool** __text__!";
const richText = converter.convert(inputText);

console.log(richText);
Enter fullscreen mode Exit fullscreen mode

Node.js

You can also use the library in Node.js:

const RichTextConverter = require('rich-text-converter');
// Create a new instance of RichTextConverter
const converter = new RichTextConverter();

// Example usage
const
…
Enter fullscreen mode Exit fullscreen mode

Top comments (0)